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
fix: link default folders to existing cloud folders instead of registering duplicates (#1086)
Chad Pihacc867c282235
diff --git a/preload.js b/preload.jsindex 59f77a4c5..6486d85f0 100644--- a/preload.js+++ b/preload.js@@ -825,6 +825,8 @@ contextBridge.exposeInMainWorld("electronAPI", {upsertFolderFromCloud: (cloudFolder) =>ipcRenderer.invoke("db-upsert-folder-from-cloud", cloudFolder),markFolderSynced: (id, cloudId) => ipcRenderer.invoke("db-mark-folder-synced", id, cloudId),+ adoptFolderIdentity: (id, clientFolderId, cloudId, updatedAt) =>+ ipcRenderer.invoke("db-adopt-folder-identity", id, clientFolderId, cloudId, updatedAt),getFolderIdMap: () => ipcRenderer.invoke("db-get-folder-id-map"),getPendingFolderDeletes: () => ipcRenderer.invoke("db-get-pending-folder-deletes"),hardDeleteFolder: (id) => ipcRenderer.invoke("db-hard-delete-folder", id),diff --git a/src/helpers/database.js b/src/helpers/database.jsindex bf4b2b7be..c5413c492 100644--- a/src/helpers/database.js+++ b/src/helpers/database.js@@ -2862,6 +2862,21 @@ class DatabaseManager {}}+ adoptFolderIdentity(id, clientFolderId, cloudId, updatedAt) {+ try {+ if (!this.db) throw new Error("Database not initialized");+ this.db+ .prepare(+ "UPDATE folders SET client_folder_id = ?, cloud_id = ?, sync_status = 'synced', updated_at = COALESCE(?, updated_at) WHERE id = ?"+ )+ .run(clientFolderId, cloudId, updatedAt ?? null, id);+ return { success: true };+ } catch (error) {+ debugLogger.error("Error adopting folder identity", { error: error.message }, "database");+ throw error;+ }+ }+getFolderIdMap() {try {if (!this.db) throw new Error("Database not initialized");diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex a174fe184..d52be59b7 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -1394,6 +1394,9 @@ class IPCHandlers {ipcMain.handle("db-mark-folder-synced", (_, id, cloudId) =>this.databaseManager.markFolderSynced(id, cloudId));+ ipcMain.handle("db-adopt-folder-identity", (_, id, clientFolderId, cloudId, updatedAt) =>+ this.databaseManager.adoptFolderIdentity(id, clientFolderId, cloudId, updatedAt)+ );ipcMain.handle("db-get-folder-id-map", () => this.databaseManager.getFolderIdMap());ipcMain.handle("db-get-pending-folder-deletes", () =>this.databaseManager.getPendingFolderDeletes()diff --git a/src/services/SyncService.ts b/src/services/SyncService.tsindex fe3bf21b5..62867cb57 100644--- a/src/services/SyncService.ts+++ b/src/services/SyncService.ts@@ -326,11 +326,44 @@ class SyncService {}private async syncFolders(): Promise<void> {+ await this.adoptDefaultFolders();await this.pushPendingFolders();await this.pushFolderDeletes();await this.pullFolders();}+ // Each platform seeds "Personal"/"Meetings" with its own random+ // client_folder_id, so the second device to sync would register them as+ // new folders and collide with the cloud's per-user unique folder name.+ // Before the first push, adopt the cloud identity of any same-named+ // default folder so both platforms converge on a single folder.+ private async adoptDefaultFolders(): Promise<void> {+ const pending = (await window.electronAPI.getPendingFolders?.()) ?? [];+ const unlinkedDefaults = pending.filter((f) => f.is_default && !f.cloud_id);+ if (unlinkedDefaults.length === 0) return;++ try {+ const { folders: cloudFolders } = await FoldersService.list();+ const cloudByName = new Map(+ cloudFolders+ .filter((f) => f.is_default && !f.deleted_at)+ .map((f) => [f.name.toLowerCase(), f])+ );+ for (const local of unlinkedDefaults) {+ const match = cloudByName.get(local.name.toLowerCase());+ if (!match) continue;+ await window.electronAPI.adoptFolderIdentity?.(+ local.id,+ match.client_folder_id ?? local.client_folder_id,+ match.id,+ match.updated_at+ );+ }+ } catch (err) {+ console.error("Default folder adoption failed:", err);+ }+ }+private async pushFolderDeletes(): Promise<void> {const deletes = (await window.electronAPI.getPendingFolderDeletes?.()) ?? [];for (const f of deletes) {@@ -370,9 +403,30 @@ class SyncService {sort_order: f.sort_order,})));- for (const cloudFolder of created) {- const local = fresh.find((f) => f.client_folder_id === cloudFolder.client_folder_id);- if (local) await window.electronAPI.markFolderSynced?.(local.id, cloudFolder.id);+ // created preserves input order; the cloud may return an existing+ // folder with a different client_folder_id when a same-named+ // default already exists there — adopt its identity in that case.+ if (created.length !== fresh.length) {+ console.error(+ `Folder batch create returned ${created.length} folders for ${fresh.length} inputs; skipping identity adoption`+ );+ return;+ }+ for (const [i, cloudFolder] of created.entries()) {+ const local = fresh[i];+ if (+ cloudFolder.client_folder_id &&+ cloudFolder.client_folder_id !== local.client_folder_id+ ) {+ await window.electronAPI.adoptFolderIdentity?.(+ local.id,+ cloudFolder.client_folder_id,+ cloudFolder.id,+ cloudFolder.updated_at+ );+ } else {+ await window.electronAPI.markFolderSynced?.(local.id, cloudFolder.id);+ }}} catch (err) {console.error("Folder batch create failed:", err);@@ -396,6 +450,25 @@ class SyncService {continue;}+ // A default folder created on another platform arrives with an+ // unknown client_folder_id; inserting it would violate the local+ // unique folder name. Match it by name and adopt its identity.+ if (!local && cloudFolder.is_default) {+ const allFolders = (await window.electronAPI.getFolderIdMap?.()) ?? [];+ const nameMatch = allFolders.find(+ (f) => f.is_default && f.name.toLowerCase() === cloudFolder.name.toLowerCase()+ );+ if (nameMatch) {+ await window.electronAPI.adoptFolderIdentity?.(+ nameMatch.id,+ cloudFolder.client_folder_id ?? nameMatch.client_folder_id,+ cloudFolder.id,+ cloudFolder.updated_at+ );+ continue;+ }+ }+if (local?.deleted_at) continue;if (!local || cloudFolder.updated_at > local.updated_at) {await window.electronAPI.upsertFolderFromCloud?.(diff --git a/src/types/electron.ts b/src/types/electron.tsindex f5b1b6bd1..3eb0f821a 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -1899,6 +1899,12 @@ declare global {getFolderByClientId?: (clientFolderId: string) => Promise<FolderItem | null>;upsertFolderFromCloud?: (cloudFolder: Record<string, unknown>) => Promise<FolderItem>;markFolderSynced?: (id: number, cloudId: string) => Promise<void>;+ adoptFolderIdentity?: (+ id: number,+ clientFolderId: string,+ cloudId: string,+ updatedAt?: string+ ) => Promise<void>;getFolderIdMap?: () => Promise<FolderItem[]>;getPendingFolderDeletes?: () => Promise<FolderItem[]>;hardDeleteFolder?: (id: number) => Promise<{ success: boolean; id: number }>;