Use new settings API exposed directly through SyncClient
This commit is contained in:
parent
a39e0886c7
commit
d772cda164
7 changed files with 50 additions and 72 deletions
|
|
@ -18,15 +18,11 @@ export class LogsView extends ItemView {
|
|||
this.updateView();
|
||||
});
|
||||
|
||||
this.client.settings.addOnSettingsChangeHandlers(
|
||||
(newSettings, oldSettings) => {
|
||||
if (
|
||||
newSettings.minimumLogLevel !== oldSettings.minimumLogLevel
|
||||
) {
|
||||
this.updateView();
|
||||
}
|
||||
this.client.addOnSettingsChangeHandlers((newSettings, oldSettings) => {
|
||||
if (newSettings.minimumLogLevel !== oldSettings.minimumLogLevel) {
|
||||
this.updateView();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private static formatTimestamp(timestamp: Date): string {
|
||||
|
|
@ -82,7 +78,7 @@ export class LogsView extends ItemView {
|
|||
);
|
||||
|
||||
const logs = this.client.logger.getMessages(
|
||||
this.client.settings.getSettings().minimumLogLevel
|
||||
this.client.getSettings().minimumLogLevel
|
||||
);
|
||||
|
||||
if (logs.length === 0) {
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
this.syncClient = syncClient;
|
||||
this.statusDescription = statusDescription;
|
||||
|
||||
this.editedVaultName = this.syncClient.settings.getSettings().vaultName;
|
||||
this.syncClient.settings.addOnSettingsChangeHandlers(
|
||||
this.editedVaultName = this.syncClient.getSettings().vaultName;
|
||||
this.syncClient.addOnSettingsChangeHandlers(
|
||||
(newSettings, oldSettings) => {
|
||||
if (newSettings.vaultName !== oldSettings.vaultName) {
|
||||
this.editedVaultName = newSettings.vaultName;
|
||||
|
|
@ -122,9 +122,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder("https://example.com:3000")
|
||||
.setValue(this.syncClient.settings.getSettings().remoteUri)
|
||||
.setValue(this.syncClient.getSettings().remoteUri)
|
||||
.onChange(async (value) =>
|
||||
this.syncClient.settings.setSetting("remoteUri", value)
|
||||
this.syncClient.setSetting("remoteUri", value)
|
||||
)
|
||||
)
|
||||
.addButton((button) =>
|
||||
|
|
@ -146,9 +146,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
.addTextArea((text) =>
|
||||
text
|
||||
.setPlaceholder("ey...")
|
||||
.setValue(this.syncClient.settings.getSettings().token)
|
||||
.setValue(this.syncClient.getSettings().token)
|
||||
.onChange(async (value) =>
|
||||
this.syncClient.settings.setSetting("token", value)
|
||||
this.syncClient.setSetting("token", value)
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -161,22 +161,21 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder("My Obsidian Vault")
|
||||
.setValue(this.syncClient.settings.getSettings().vaultName)
|
||||
.setValue(this.syncClient.getSettings().vaultName)
|
||||
.onChange((value) => (this.editedVaultName = value))
|
||||
)
|
||||
.addButton((button) =>
|
||||
button.setButtonText("Apply").onClick(async () => {
|
||||
if (
|
||||
this.editedVaultName ===
|
||||
this.syncClient.settings.getSettings().vaultName
|
||||
this.syncClient.getSettings().vaultName
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await this.syncClient.settings.setSetting(
|
||||
await this.syncClient.setSetting(
|
||||
"vaultName",
|
||||
this.editedVaultName
|
||||
);
|
||||
await this.syncClient.reset();
|
||||
new Notice(
|
||||
"Sync state has been reset, you will need to resync"
|
||||
);
|
||||
|
|
@ -213,11 +212,11 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
.setDynamicTooltip()
|
||||
.setInstant(false)
|
||||
.setValue(
|
||||
this.syncClient.settings.getSettings()
|
||||
this.syncClient.getSettings()
|
||||
.fetchChangesUpdateIntervalMs / 1000
|
||||
)
|
||||
.onChange(async (value) =>
|
||||
this.syncClient.settings.setSetting(
|
||||
this.syncClient.setSetting(
|
||||
"fetchChangesUpdateIntervalMs",
|
||||
value * 1000
|
||||
)
|
||||
|
|
@ -234,14 +233,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
.setLimits(1, 16, 1)
|
||||
.setDynamicTooltip()
|
||||
.setInstant(false)
|
||||
.setValue(
|
||||
this.syncClient.settings.getSettings().syncConcurrency
|
||||
)
|
||||
.setValue(this.syncClient.getSettings().syncConcurrency)
|
||||
.onChange(async (value) =>
|
||||
this.syncClient.settings.setSetting(
|
||||
"syncConcurrency",
|
||||
value
|
||||
)
|
||||
this.syncClient.setSetting("syncConcurrency", value)
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -255,14 +249,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
.setLimits(0, 32, 1)
|
||||
.setDynamicTooltip()
|
||||
.setInstant(false)
|
||||
.setValue(
|
||||
this.syncClient.settings.getSettings().maxFileSizeMB
|
||||
)
|
||||
.setValue(this.syncClient.getSettings().maxFileSizeMB)
|
||||
.onChange(async (value) =>
|
||||
this.syncClient.settings.setSetting(
|
||||
"maxFileSizeMB",
|
||||
value
|
||||
)
|
||||
this.syncClient.setSetting("maxFileSizeMB", value)
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -276,14 +265,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
)
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(
|
||||
this.syncClient.settings.getSettings().isSyncEnabled
|
||||
)
|
||||
.setValue(this.syncClient.getSettings().isSyncEnabled)
|
||||
.onChange(async (value) =>
|
||||
this.syncClient.settings.setSetting(
|
||||
"isSyncEnabled",
|
||||
value
|
||||
)
|
||||
this.syncClient.setSetting("isSyncEnabled", value)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -304,11 +288,9 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
[LogLevel.WARNING]: LogLevel.WARNING,
|
||||
[LogLevel.ERROR]: LogLevel.ERROR
|
||||
})
|
||||
.setValue(
|
||||
this.syncClient.settings.getSettings().minimumLogLevel
|
||||
)
|
||||
.setValue(this.syncClient.getSettings().minimumLogLevel)
|
||||
.onChange(async (value) =>
|
||||
this.syncClient.settings.setSetting(
|
||||
this.syncClient.setSetting(
|
||||
"minimumLogLevel",
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
value as LogLevel
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export class StatusBar {
|
|||
}
|
||||
);
|
||||
|
||||
this.syncClient.settings.addOnSettingsChangeHandlers(() => {
|
||||
this.syncClient.addOnSettingsChangeHandlers(() => {
|
||||
this.updateStatus();
|
||||
});
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ export class StatusBar {
|
|||
}
|
||||
|
||||
if (!hasShownMessage) {
|
||||
if (this.syncClient.settings.getSettings().isSyncEnabled) {
|
||||
if (this.syncClient.getSettings().isSyncEnabled) {
|
||||
container.createSpan({ text: "VaultLink is idle" });
|
||||
} else {
|
||||
const button = container.createEl("button", {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export class StatusDescription {
|
|||
}
|
||||
);
|
||||
|
||||
this.syncClient.settings.addOnSettingsChangeHandlers(() => {
|
||||
this.syncClient.addOnSettingsChangeHandlers(() => {
|
||||
void this.updateConnectionState();
|
||||
});
|
||||
}
|
||||
|
|
@ -67,8 +67,8 @@ export class StatusDescription {
|
|||
|
||||
container.createSpan({ text: "VaultLink is connected to the server " });
|
||||
container.createEl("a", {
|
||||
text: this.syncClient.settings.getSettings().remoteUri,
|
||||
href: this.syncClient.settings.getSettings().remoteUri
|
||||
text: this.syncClient.getSettings().remoteUri,
|
||||
href: this.syncClient.getSettings().remoteUri
|
||||
});
|
||||
|
||||
container.createSpan({
|
||||
|
|
@ -87,7 +87,7 @@ export class StatusDescription {
|
|||
(this.lastHistoryStats?.success ?? 0) === 0 &&
|
||||
(this.lastHistoryStats?.error ?? 0) === 0
|
||||
) {
|
||||
if (this.syncClient.settings.getSettings().isSyncEnabled) {
|
||||
if (this.syncClient.getSettings().isSyncEnabled) {
|
||||
container.createSpan({
|
||||
text: "Syncing is enabled but VaultLink hasn't found anything to sync yet."
|
||||
});
|
||||
|
|
|
|||
|
|
@ -50,15 +50,6 @@ export class Settings {
|
|||
return this.settings;
|
||||
}
|
||||
|
||||
public async setSettings(value: SyncSettings): Promise<void> {
|
||||
const oldSettings = this.settings;
|
||||
this.settings = value;
|
||||
this.onSettingsChangeHandlers.forEach((handler) => {
|
||||
handler(value, oldSettings);
|
||||
});
|
||||
await this.save();
|
||||
}
|
||||
|
||||
public addOnSettingsChangeHandlers(
|
||||
handler: (settings: SyncSettings, oldSettings: SyncSettings) => void
|
||||
): void {
|
||||
|
|
@ -74,6 +65,15 @@ export class Settings {
|
|||
await this.setSettings(newSettings);
|
||||
}
|
||||
|
||||
private async setSettings(value: SyncSettings): Promise<void> {
|
||||
const oldSettings = this.settings;
|
||||
this.settings = value;
|
||||
this.onSettingsChangeHandlers.forEach((handler) => {
|
||||
handler(value, oldSettings);
|
||||
});
|
||||
await this.save();
|
||||
}
|
||||
|
||||
private async save(): Promise<void> {
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export class MockAgent extends MockClient {
|
|||
};
|
||||
|
||||
this.client.logger.addOnMessageListener((logLine: LogLine) => {
|
||||
const state = this.client.settings.getSettings().isSyncEnabled
|
||||
const state = this.client.getSettings().isSyncEnabled
|
||||
? "(online) "
|
||||
: "(offline)";
|
||||
const formatted = `[${this.name} ${state}] ${logLine.timestamp.toISOString()} ${logLine.level} ${logLine.message}`;
|
||||
|
|
@ -91,7 +91,7 @@ export class MockAgent extends MockClient {
|
|||
this.changeFetchChangesUpdateIntervalMsAction.bind(this)
|
||||
];
|
||||
|
||||
if (this.client.settings.getSettings().isSyncEnabled) {
|
||||
if (this.client.getSettings().isSyncEnabled) {
|
||||
if (this.doNotTouchWhileOffline.length === 0) {
|
||||
options.push(this.disableSyncAction.bind(this));
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ export class MockAgent extends MockClient {
|
|||
}
|
||||
|
||||
public async finish(): Promise<void> {
|
||||
await this.client.settings.setSetting("isSyncEnabled", true);
|
||||
await this.client.setSetting("isSyncEnabled", true);
|
||||
await Promise.all(this.pendingActions);
|
||||
this.client.stop();
|
||||
await this.client.syncer.waitForSyncQueue();
|
||||
|
|
@ -239,7 +239,7 @@ export class MockAgent extends MockClient {
|
|||
const file = this.getFileName();
|
||||
|
||||
if (
|
||||
(!this.client.settings.getSettings().isSyncEnabled &&
|
||||
(!this.client.getSettings().isSyncEnabled &&
|
||||
this.doNotTouchWhileOffline.includes(file)) ||
|
||||
(await this.exists(file))
|
||||
) {
|
||||
|
|
@ -258,7 +258,7 @@ export class MockAgent extends MockClient {
|
|||
this.client.logger.info(
|
||||
`Decided to change fetchChangesUpdateIntervalMs`
|
||||
);
|
||||
return this.client.settings.setSetting(
|
||||
return this.client.setSetting(
|
||||
"fetchChangesUpdateIntervalMs",
|
||||
Math.random() * 2000 + 100
|
||||
);
|
||||
|
|
@ -266,12 +266,12 @@ export class MockAgent extends MockClient {
|
|||
|
||||
private async disableSyncAction(): Promise<void> {
|
||||
this.client.logger.info(`Decided to disable sync`);
|
||||
await this.client.settings.setSetting("isSyncEnabled", false);
|
||||
await this.client.setSetting("isSyncEnabled", false);
|
||||
}
|
||||
|
||||
private async enableSyncAction(): Promise<void> {
|
||||
this.client.logger.info(`Decided to enable sync`);
|
||||
await this.client.settings.setSetting("isSyncEnabled", true);
|
||||
await this.client.setSetting("isSyncEnabled", true);
|
||||
}
|
||||
|
||||
private async renameFileAction(files: RelativePath[]): Promise<void> {
|
||||
|
|
@ -280,7 +280,7 @@ export class MockAgent extends MockClient {
|
|||
// We can't edit files offline that have been updated while offline.
|
||||
// Otherwise, the resolution logic couldn't handle it.
|
||||
if (
|
||||
!this.client.settings.getSettings().isSyncEnabled &&
|
||||
!this.client.getSettings().isSyncEnabled &&
|
||||
this.doNotTouchWhileOffline.includes(file)
|
||||
) {
|
||||
this.client.logger.info(
|
||||
|
|
@ -292,7 +292,7 @@ export class MockAgent extends MockClient {
|
|||
const newName = this.getFileName();
|
||||
|
||||
if (
|
||||
(!this.client.settings.getSettings().isSyncEnabled &&
|
||||
(!this.client.getSettings().isSyncEnabled &&
|
||||
this.doNotTouchWhileOffline.includes(newName)) ||
|
||||
(await this.exists(newName))
|
||||
) {
|
||||
|
|
@ -311,7 +311,7 @@ export class MockAgent extends MockClient {
|
|||
// We can't edit files offline that have been updated while offline.
|
||||
// Otherwise, the resolution logic couldn't handle it.
|
||||
if (
|
||||
!this.client.settings.getSettings().isSyncEnabled &&
|
||||
!this.client.getSettings().isSyncEnabled &&
|
||||
this.doNotTouchWhileOffline.includes(file)
|
||||
) {
|
||||
this.client.logger.info(
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export class MockClient implements FileSystemOperations {
|
|||
await Promise.all(
|
||||
Object.keys(this.initialSettings).map(async (key) => {
|
||||
const settingKey = key as keyof SyncSettings; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
||||
return this.client.settings.setSetting(
|
||||
return this.client.setSetting(
|
||||
settingKey,
|
||||
this.initialSettings[settingKey]! // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue