diff --git a/frontend/obsidian-plugin/src/views/settings/settings-tab.ts b/frontend/obsidian-plugin/src/views/settings/settings-tab.ts index 84da83d8..3f7ed7ca 100644 --- a/frontend/obsidian-plugin/src/views/settings/settings-tab.ts +++ b/frontend/obsidian-plugin/src/views/settings/settings-tab.ts @@ -266,8 +266,9 @@ export class SyncSettingsTab extends PluginSettingTab { new Notice("Checking connection to the server..."); new Notice( - (await this.syncClient.checkConnection()) - .serverMessage + ( + await this.syncClient.checkConnection() + ).serverMessage ); await this.statusDescription.updateConnectionState(); } else { @@ -503,6 +504,47 @@ export class SyncSettingsTab extends PluginSettingTab { ); }) ); + + new Setting(containerEl) + .setName("Sync interval (ms)") + .setDesc( + "How often to reconcile when no changes are detected. Leave blank to rely on change notifications." + ) + .addText((input) => + input + .setPlaceholder("Disabled") + .setValue( + this.syncClient + .getSettings() + .syncIntervalMs?.toString() ?? "" + ) + .onChange(async (value) => { + if (value === "") { + return this.syncClient.setSetting( + "syncIntervalMs", + undefined + ); + } + + const parsedValue = Number(value); + if ( + !Number.isSafeInteger(parsedValue) || + parsedValue <= 0 + ) { + input.setValue( + this.syncClient + .getSettings() + .syncIntervalMs?.toString() ?? "" + ); + return; + } + + return this.syncClient.setSetting( + "syncIntervalMs", + parsedValue + ); + }) + ); } private setStatusDescriptionSubscription( diff --git a/frontend/sync-client/src/persistence/settings.ts b/frontend/sync-client/src/persistence/settings.ts index 2558139a..f1f17f26 100644 --- a/frontend/sync-client/src/persistence/settings.ts +++ b/frontend/sync-client/src/persistence/settings.ts @@ -15,6 +15,7 @@ export interface SyncSettings { enableTelemetry: boolean; requestTimeoutMs: number; networkRetryIntervalMs: number; + syncIntervalMs?: number; minimumSaveIntervalMs: number; } @@ -31,6 +32,7 @@ export const DEFAULT_SETTINGS: SyncSettings = { enableTelemetry: false, requestTimeoutMs: 30_000, networkRetryIntervalMs: 1000, + syncIntervalMs: undefined, minimumSaveIntervalMs: 1000 }; diff --git a/frontend/sync-client/src/services/websocket-manager.ts b/frontend/sync-client/src/services/websocket-manager.ts index 8d62fb2b..8b3b69dd 100644 --- a/frontend/sync-client/src/services/websocket-manager.ts +++ b/frontend/sync-client/src/services/websocket-manager.ts @@ -5,7 +5,7 @@ import type { WebSocketClientMessage } from "./types/WebSocketClientMessage"; import type { CursorPositionFromClient } from "./types/CursorPositionFromClient"; import type { ClientCursors } from "./types/ClientCursors"; import { createPromise } from "../utils/create-promise"; -import type { EventBatch } from "./protocol"; +import type { EventBatch } from "./types/EventBatch"; import { WEBSOCKET_DISCONNECT_TIMEOUT_IN_S } from "../consts"; import { removeFromArray } from "../utils/remove-from-array"; import { EventListeners } from "../utils/data-structures/event-listeners"; diff --git a/frontend/sync-client/src/types/file-manifest-entries.ts b/frontend/sync-client/src/types/file-manifest-entries.ts new file mode 100644 index 00000000..1e23dd06 --- /dev/null +++ b/frontend/sync-client/src/types/file-manifest-entries.ts @@ -0,0 +1,3 @@ +import type { FileManifest } from "../services/types/FileManifest"; + +export type FileManifestEntries = FileManifest["entries"];