Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
feat(sync): re-sync on window focus and a 5-minute interval (#1070)
Chad Piha7025bc273fbe
diff --git a/src/components/ControlPanel.tsx b/src/components/ControlPanel.tsxindex a4f606281..301f8de56 100644--- a/src/components/ControlPanel.tsx+++ b/src/components/ControlPanel.tsx@@ -375,7 +375,28 @@ export default function ControlPanel({ initialSettingsSection }: ControlPanelPro}, [toast, t]);useEffect(() => {- syncService.syncAll().catch(console.error);+ // Keep syncing during a long session, not just once at launch.+ syncService.requestSyncAll("mount");++ const onFocus = () => syncService.requestSyncAll("focus");+ const onVisibility = () => {+ if (document.visibilityState === "visible") {+ syncService.requestSyncAll("focus");+ }+ };+ const onOnline = () => syncService.requestSyncAll("online");+ window.addEventListener("focus", onFocus);+ document.addEventListener("visibilitychange", onVisibility);+ window.addEventListener("online", onOnline);++ const interval = setInterval(() => syncService.requestSyncAll("interval"), 5 * 60 * 1000);++ return () => {+ window.removeEventListener("focus", onFocus);+ document.removeEventListener("visibilitychange", onVisibility);+ window.removeEventListener("online", onOnline);+ clearInterval(interval);+ };}, []);useEffect(() => {@@ -422,7 +443,7 @@ export default function ControlPanel({ initialSettingsSection }: ControlPanelProconst result = await window.electronAPI.deleteTranscription(id);if (result.success) {removeFromStore(id);- syncService.syncAll().catch(console.error);+ syncService.requestSyncAll("manual");} else {showAlertDialog({title: t("controlPanel.history.couldNotDeleteTitle"),@@ -451,7 +472,7 @@ export default function ControlPanel({ initialSettingsSection }: ControlPanelProconst result = await window.electronAPI.clearTranscriptions();if (result.success) {clearStore();- syncService.syncAll().catch(console.error);+ syncService.requestSyncAll("manual");toast({title: t("controlPanel.history.clearAllSuccess"),variant: "success",diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsxindex 8be019c35..00c0697b6 100644--- a/src/components/SettingsPage.tsx+++ b/src/components/SettingsPage.tsx@@ -3380,7 +3380,7 @@ EOF`,setCloudBackupEnabled(v);if (v) {startMigration().catch(console.error);- syncService.syncAll().catch(console.error);+ syncService.requestSyncAll("manual");}}}/>diff --git a/src/hooks/useFolderManagement.ts b/src/hooks/useFolderManagement.tsindex 4f44af548..a16ed109a 100644--- a/src/hooks/useFolderManagement.ts+++ b/src/hooks/useFolderManagement.ts@@ -208,7 +208,7 @@ export function useFolderManagement(): UseFolderManagementReturn {const personalFolder = findDefaultFolder(items);if (personalFolder) setActiveFolderId(personalFolder.id);}- syncService.syncAll().catch(console.error);+ syncService.requestSyncAll("manual");} else if (result.error) {toast({title: t("notes.folders.couldNotDelete"),diff --git a/src/services/SyncService.ts b/src/services/SyncService.tsindex 76f7be520..1ea0aa364 100644--- a/src/services/SyncService.ts+++ b/src/services/SyncService.ts@@ -21,6 +21,8 @@ const BATCH_SIZE = 50;const TRANSCRIPTION_BATCH_SIZE = 100;const DICTIONARY_BATCH_SIZE = 200;const SNIPPET_BATCH_SIZE = 200;+// Skip a redundant syncAll() if focus + interval fire close together.+const AUTO_SYNC_THROTTLE_MS = 20000;// SQLite `datetime('now')` yields "YYYY-MM-DD HH:MM:SS" (no T, no millis, no Z);// the cloud sends ISO 8601 "YYYY-MM-DDTHH:MM:SS.sssZ". Normalize both to@@ -35,9 +37,11 @@ function normalizeTimestamp(value: string | null | undefined): string {class SyncService {private syncing = false;+ private syncAllPending = false;private dictionaryDirty = false;private snippetsDirty = false;private pushTimers = new Map<string, ReturnType<typeof setTimeout>>();+ private lastSyncAllAt = 0;canSync(): boolean {return (@@ -48,7 +52,13 @@ class SyncService {}async syncAll(): Promise<void> {- if (this.syncing || !this.canSync()) return;+ if (!this.canSync()) return;+ // A pass already running may have synced past the data this request covers,+ // so flag a re-run instead of dropping it.+ if (this.syncing) {+ this.syncAllPending = true;+ return;+ }this.syncing = true;try {await this.syncFolders();@@ -66,11 +76,27 @@ class SyncService {await this.syncSnippets();} while (this.snippetsDirty);localStorage.setItem("lastSyncedAt", new Date().toISOString());+ this.lastSyncAllAt = Date.now();} catch (err) {console.error("Sync failed:", err);} finally {this.syncing = false;}+ if (this.syncAllPending) {+ this.syncAllPending = false;+ await this.syncAll();+ }+ }++ requestSyncAll(reason: "mount" | "focus" | "interval" | "online" | "manual"): void {+ if (!this.canSync()) return;+ if (+ reason !== "manual" &&+ (this.syncing || Date.now() - this.lastSyncAllAt < AUTO_SYNC_THROTTLE_MS)+ ) {+ return;+ }+ void this.syncAll();}async syncDictionaryNow(): Promise<void> {