Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(notes): sync editor content when note is updated externally

Gabriel Stein661d161dd92a
diff --git a/src/components/ApiKeysSection.tsx b/src/components/ApiKeysSection.tsx
index 7bacde15c..90c26f3c9 100644
--- a/src/components/ApiKeysSection.tsx
+++ b/src/components/ApiKeysSection.tsx
@@ -5,7 +5,7 @@ import { Button } from "./ui/button";
import { Input } from "./ui/input";
import { Badge } from "./ui/badge";
import { Skeleton } from "./ui/skeleton";
-import { useToast } from "./ui/Toast";
+import { useToast } from "./ui/useToast";
import {
Dialog,
DialogContent,
diff --git a/src/components/NoteEditor.tsx b/src/components/NoteEditor.tsx
index 52ec9d494..15ed13ea7 100644
--- a/src/components/NoteEditor.tsx
+++ b/src/components/NoteEditor.tsx
@@ -63,7 +63,7 @@ export default function NoteEditor({ note, cloudEnabled, onDelete, onUpdate }: N
await window.electronAPI.updateNote(note.id, updates);
const updated = { ...note, ...updates };
onUpdate(updated);
- syncService.debouncedPush('note', note.id);
+ syncService.debouncedPush("note", note.id);
setSaveState("saved");
fadeTimerRef.current = setTimeout(() => setSaveState("idle"), 2000);
} catch {
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index 6f8b4de59..e7735f6ec 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -3447,25 +3447,35 @@ EOF`,
{t("settingsPage.privacy.cloudNotesMigrationDone")}
</p>
)}
- {cloudBackupEnabled && isSignedIn && (() => {
- const lastSyncedAt = localStorage.getItem("lastSyncedAt");
- if (!lastSyncedAt) return null;
- const date = new Date(lastSyncedAt);
- const now = new Date();
- const diffMs = now.getTime() - date.getTime();
- const diffMin = Math.floor(diffMs / 60000);
- const diffHr = Math.floor(diffMs / 3600000);
- let relative: string;
- if (diffMin < 1) relative = t("settingsPage.privacy.justNow");
- else if (diffMin < 60) relative = t("settingsPage.privacy.minutesAgo", { count: diffMin });
- else if (diffHr < 24) relative = t("settingsPage.privacy.hoursAgo", { count: diffHr });
- else relative = date.toLocaleDateString(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" });
- return (
- <p className="mt-1 text-xs text-muted-foreground">
- {t("settingsPage.privacy.lastSynced", { time: relative })}
- </p>
- );
- })()}
+ {cloudBackupEnabled &&
+ isSignedIn &&
+ (() => {
+ const lastSyncedAt = localStorage.getItem("lastSyncedAt");
+ if (!lastSyncedAt) return null;
+ const date = new Date(lastSyncedAt);
+ const now = new Date();
+ const diffMs = now.getTime() - date.getTime();
+ const diffMin = Math.floor(diffMs / 60000);
+ const diffHr = Math.floor(diffMs / 3600000);
+ let relative: string;
+ if (diffMin < 1) relative = t("settingsPage.privacy.justNow");
+ else if (diffMin < 60)
+ relative = t("settingsPage.privacy.minutesAgo", { count: diffMin });
+ else if (diffHr < 24)
+ relative = t("settingsPage.privacy.hoursAgo", { count: diffHr });
+ else
+ relative = date.toLocaleDateString(undefined, {
+ month: "short",
+ day: "numeric",
+ hour: "2-digit",
+ minute: "2-digit",
+ });
+ return (
+ <p className="mt-1 text-xs text-muted-foreground">
+ {t("settingsPage.privacy.lastSynced", { time: relative })}
+ </p>
+ );
+ })()}
</div>
)}
diff --git a/src/components/notes/PersonalNotesView.tsx b/src/components/notes/PersonalNotesView.tsx
index cdf3917c0..806bd01b2 100644
--- a/src/components/notes/PersonalNotesView.tsx
+++ b/src/components/notes/PersonalNotesView.tsx
@@ -200,6 +200,13 @@ export default function PersonalNotesView({
setLocalTitle(activeNote.title);
setLocalContent(activeNote.content);
setLocalEnhancedContent(activeNote.enhanced_content ?? null);
+ } else if (activeNote && activeNote.id === activeNoteRef.current && !saveTimeoutRef.current) {
+ // External update (e.g. AI chat tool) — resync only when no user save is pending
+ if (activeNote.title !== localTitleRef.current) setLocalTitle(activeNote.title);
+ if (activeNote.content !== localContentRef.current) setLocalContent(activeNote.content);
+ if ((activeNote.enhanced_content ?? null) !== localEnhancedContent) {
+ setLocalEnhancedContent(activeNote.enhanced_content ?? null);
+ }
}
if (!activeNote) {
if (saveTimeoutRef.current) {
@@ -217,7 +224,7 @@ export default function PersonalNotesView({
}
};
syncNote();
- }, [activeNote]);
+ }, [activeNote, localEnhancedContent]);
const debouncedSave = useCallback((noteId: number, title: string, content: string) => {
if (saveTimeoutRef.current) clearTimeout(saveTimeoutRef.current);
diff --git a/src/helpers/database.js b/src/helpers/database.js
index 478ecb7ab..878bc402c 100644
--- a/src/helpers/database.js
+++ b/src/helpers/database.js
@@ -464,7 +464,9 @@ class DatabaseManager {
if (!err.message.includes("duplicate column")) throw err;
}
try {
- this.db.exec("ALTER TABLE agent_conversations ADD COLUMN sync_status TEXT DEFAULT 'pending'");
+ this.db.exec(
+ "ALTER TABLE agent_conversations ADD COLUMN sync_status TEXT DEFAULT 'pending'"
+ );
} catch (err) {
if (!err.message.includes("duplicate column")) throw err;
}
@@ -506,10 +508,18 @@ class DatabaseManager {
}
}
- this.db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_notes_client_note_id ON notes(client_note_id)");
- this.db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_folders_client_folder_id ON folders(client_folder_id)");
- this.db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_conversations_client_id ON agent_conversations(client_conversation_id)");
- this.db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_transcriptions_client_id ON transcriptions(client_transcription_id)");
+ this.db.exec(
+ "CREATE UNIQUE INDEX IF NOT EXISTS idx_notes_client_note_id ON notes(client_note_id)"
+ );
+ this.db.exec(
+ "CREATE UNIQUE INDEX IF NOT EXISTS idx_folders_client_folder_id ON folders(client_folder_id)"
+ );
+ this.db.exec(
+ "CREATE UNIQUE INDEX IF NOT EXISTS idx_conversations_client_id ON agent_conversations(client_conversation_id)"
+ );
+ this.db.exec(
+ "CREATE UNIQUE INDEX IF NOT EXISTS idx_transcriptions_client_id ON transcriptions(client_transcription_id)"
+ );
return true;
} catch (error) {
@@ -531,7 +541,14 @@ class DatabaseManager {
const stmt = this.db.prepare(
"INSERT INTO transcriptions (text, raw_text, status, error_message, error_code, client_transcription_id) VALUES (?, ?, ?, ?, ?, ?)"
);
- const result = stmt.run(text, rawText, status, errorMessage, errorCode, clientTranscriptionId);
+ const result = stmt.run(
+ text,
+ rawText,
+ status,
+ errorMessage,
+ errorCode,
+ clientTranscriptionId
+ );
const fetchStmt = this.db.prepare("SELECT * FROM transcriptions WHERE id = ?");
const transcription = fetchStmt.get(result.lastInsertRowid);
@@ -718,7 +735,15 @@ class DatabaseManager {
const stmt = this.db.prepare(
"INSERT INTO notes (title, content, note_type, source_file, audio_duration_seconds, folder_id, client_note_id) VALUES (?, ?, ?, ?, ?, ?, ?)"
);
- const result = stmt.run(title, content, noteType, sourceFile, audioDuration, folderId, clientNoteId);
+ const result = stmt.run(
+ title,
+ content,
+ noteType,
+ sourceFile,
+ audioDuration,
+ folderId,
+ clientNoteId
+ );
const fetchStmt = this.db.prepare("SELECT * FROM notes WHERE id = ?");
const note = fetchStmt.get(result.lastInsertRowid);
@@ -886,7 +911,9 @@ class DatabaseManager {
try {
if (!this.db) throw new Error("Database not initialized");
return this.db
- .prepare("SELECT folder_id, COUNT(*) as count FROM notes WHERE deleted_at IS NULL GROUP BY folder_id")
+ .prepare(
+ "SELECT folder_id, COUNT(*) as count FROM notes WHERE deleted_at IS NULL GROUP BY folder_id"
+ )
.all();
} catch (error) {
debugLogger.error("Error getting folder note counts", { error: error.message }, "notes");
@@ -997,7 +1024,9 @@ class DatabaseManager {
if (!this.db) throw new Error("Database not initialized");
const clientConversationId = randomUUID();
const result = this.db
- .prepare("INSERT INTO agent_conversations (title, note_id, client_conversation_id) VALUES (?, ?, ?)")
+ .prepare(
+ "INSERT INTO agent_conversations (title, note_id, client_conversation_id) VALUES (?, ?, ?)"
+ )
.run(title, noteId, clientConversationId);
return this.db
.prepare("SELECT * FROM agent_conversations WHERE id = ?")
@@ -1037,7 +1066,9 @@ class DatabaseManager {
try {
if (!this.db) throw new Error("Database not initialized");
return this.db
- .prepare("SELECT * FROM agent_conversations WHERE deleted_at IS NULL ORDER BY updated_at DESC LIMIT ?")
+ .prepare(
+ "SELECT * FROM agent_conversations WHERE deleted_at IS NULL ORDER BY updated_at DESC LIMIT ?"
+ )
.all(limit);
} catch (error) {
debugLogger.error("Error getting agent conversations", { error: error.message }, "database");
@@ -1857,7 +1888,6 @@ class DatabaseManager {
}
}
-
getPendingNotes() {
try {
if (!this.db) throw new Error("Database not initialized");
@@ -1874,7 +1904,9 @@ class DatabaseManager {
try {
if (!this.db) throw new Error("Database not initialized");
return this.db
- .prepare("SELECT * FROM notes WHERE deleted_at IS NOT NULL AND cloud_id IS NOT NULL AND sync_status = 'pending'")
+ .prepare(
+ "SELECT * FROM notes WHERE deleted_at IS NOT NULL AND cloud_id IS NOT NULL AND sync_status = 'pending'"
+ )
.all();
} catch (error) {
debugLogger.error("Error getting pending note deletes", { error: error.message }, "database");
@@ -1885,7 +1917,9 @@ class DatabaseManager {
getNoteByClientId(clientNoteId) {
try {
if (!this.db) throw new Error("Database not initialized");
- return this.db.prepare("SELECT * FROM notes WHERE client_note_id = ?").get(clientNoteId) || null;
+ return (
+ this.db.prepare("SELECT * FROM notes WHERE client_note_id = ?").get(clientNoteId) || null
+ );
} catch (error) {
debugLogger.error("Error getting note by client id", { error: error.message }, "database");
throw error;
@@ -1928,7 +1962,9 @@ class DatabaseManager {
cloudNote.created_at,
cloudNote.updated_at
);
- return this.db.prepare("SELECT * FROM notes WHERE client_note_id = ?").get(cloudNote.client_note_id);
+ return this.db
+ .prepare("SELECT * FROM notes WHERE client_note_id = ?")
+ .get(cloudNote.client_note_id);
} catch (error) {
debugLogger.error("Error upserting note from cloud", { error: error.message }, "database");
throw error;
@@ -1938,7 +1974,9 @@ class DatabaseManager {
markNoteSynced(id, cloudId) {
try {
if (!this.db) throw new Error("Database not initialized");
- this.db.prepare("UPDATE notes SET sync_status = 'synced', cloud_id = ? WHERE id = ?").run(cloudId, id);
+ this.db
+ .prepare("UPDATE notes SET sync_status = 'synced', cloud_id = ? WHERE id = ?")
+ .run(cloudId, id);
return { success: true };
} catch (error) {
debugLogger.error("Error marking note synced", { error: error.message }, "database");
@@ -1968,7 +2006,6 @@ class DatabaseManager {
}
}
-
getPendingFolders() {
try {
if (!this.db) throw new Error("Database not initialized");
@@ -1982,7 +2019,10 @@ class DatabaseManager {
getFolderByClientId(clientFolderId) {
try {
if (!this.db) throw new Error("Database not initialized");
- return this.db.prepare("SELECT * FROM folders WHERE client_folder_id = ?").get(clientFolderId) || null;
+ return (
+ this.db.prepare("SELECT * FROM folders WHERE client_folder_id = ?").get(clientFolderId) ||
+ null
+ );
} catch (error) {
debugLogger.error("Error getting folder by client id", { error: error.message }, "database");
throw error;
@@ -2009,7 +2049,9 @@ class DatabaseManager {
cloudFolder.sort_order || 0,
cloudFolder.created_at
);
- return this.db.prepare("SELECT * FROM folders WHERE client_folder_id = ?").get(cloudFolder.client_folder_id);
+ return this.db
+ .prepare("SELECT * FROM folders WHERE client_folder_id = ?")
+ .get(cloudFolder.client_folder_id);
} catch (error) {
debugLogger.error("Error upserting folder from cloud", { error: error.message }, "database");
throw error;
@@ -2019,7 +2061,9 @@ class DatabaseManager {
markFolderSynced(id, cloudId) {
try {
if (!this.db) throw new Error("Database not initialized");
- this.db.prepare("UPDATE folders SET sync_status = 'synced', cloud_id = ? WHERE id = ?").run(cloudId, id);
+ this.db
+ .prepare("UPDATE folders SET sync_status = 'synced', cloud_id = ? WHERE id = ?")
+ .run(cloudId, id);
return { success: true };
} catch (error) {
debugLogger.error("Error marking folder synced", { error: error.message }, "database");
@@ -2037,15 +2081,20 @@ class DatabaseManager {
}
}
-
getPendingConversations() {
try {
if (!this.db) throw new Error("Database not initialized");
return this.db
- .prepare("SELECT * FROM agent_conversations WHERE sync_status = 'pending' AND deleted_at IS NULL")
+ .prepare(
+ "SELECT * FROM agent_conversations WHERE sync_status = 'pending' AND deleted_at IS NULL"
+ )
.all();
} catch (error) {
- debugLogger.error("Error getting pending conversations", { error: error.message }, "database");
+ debugLogger.error(
+ "Error getting pending conversations",
+ { error: error.message },
+ "database"
+ );
throw error;
}
}
@@ -2054,10 +2103,16 @@ class DatabaseManager {
try {
if (!this.db) throw new Error("Database not initialized");
return this.db
- .prepare("SELECT * FROM agent_conversations WHERE deleted_at IS NOT NULL AND cloud_id IS NOT NULL AND sync_status = 'pending'")
+ .prepare(
+ "SELECT * FROM agent_conversations WHERE deleted_at IS NOT NULL AND cloud_id IS NOT NULL AND sync_status = 'pending'"
+ )
.all();
} catch (error) {
- debugLogger.error("Error getting pending conversation deletes", { error: error.message }, "database");
+ debugLogger.error(
+ "Error getting pending conversation deletes",
+ { error: error.message },
+ "database"
+ );
throw error;
}
}
@@ -2065,9 +2120,17 @@ class DatabaseManager {
getConversationByClientId(clientId) {
try {
if (!this.db) throw new Error("Database not initialized");
- return this.db.prepare("SELECT * FROM agent_conversations WHERE client_conversation_id = ?").get(clientId) || null;
+ return (
+ this.db
+ .prepare("SELECT * FROM agent_conversations WHERE client_conversation_id = ?")
+ .get(clientId) || null
+ );
} catch (error) {
- debugLogger.error("Error getting conversation by client id", { error: error.message }, "database");
+ debugLogger.error(
+ "Error getting conversation by client id",
+ { error: error.message },
+ "database"
+ );
throw error;
}
}
@@ -2110,7 +2173,11 @@ class DatabaseManager {
});
return transaction();
} catch (error) {
- debugLogger.error("Error upserting conversation from cloud", { error: error.message }, "database");
+ debugLogger.error(
+ "Error upserting conversation from cloud",
+ { error: error.message },
+ "database"
+ );
throw error;
}
}
@@ -2118,7 +2185,9 @@ class DatabaseManager {
markConversationSynced(id, cloudId) {
try {
if (!this.db) throw new Error("Database not initialized");
- this.db.prepare("UPDATE agent_conversations SET sync_status = 'synced', cloud_id = ? WHERE id = ?").run(cloudId, id);
+ this.db
+ .prepare("UPDATE agent_conversations SET sync_status = 'synced', cloud_id = ? WHERE id = ?")
+ .run(cloudId, id);
return { success: true };
} catch (error) {
debugLogger.error("Error marking conversation synced", { error: error.message }, "database");
@@ -2138,13 +2207,16 @@ class DatabaseManager {
}
}
-
getPendingTranscriptions() {
try {
if (!this.db) throw new Error("Database not initialized");
return this.db.prepare("SELECT * FROM transcriptions WHERE sync_status = 'pending'").all();
} catch (error) {
- debugLogger.error("Error getting pending transcriptions", { error: error.message }, "database");
+ debugLogger.error(
+ "Error getting pending transcriptions",
+ { error: error.message },
+ "database"
+ );
throw error;
}
}
@@ -2152,9 +2224,17 @@ class DatabaseManager {
getTranscriptionByClientId(clientId) {
try {
if (!this.db) throw new Error("Database not initialized");
- return this.db.prepare("SELECT * FROM transcriptions WHERE client_transcription_id = ?").get(clientId) || null;
+ return (
+ this.db
+ .prepare("SELECT * FROM transcriptions WHERE client_transcription_id = ?")
+ .get(clientId) || null
+ );
} catch (error) {
- debugLogger.error("Error getting transcription by client id", { error: error.message }, "database");
+ debugLogger.error(
+ "Error getting transcription by client id",
+ { error: error.message },
+ "database"
+ );
throw error;
}
}
@@ -2180,9 +2260,15 @@ class DatabaseManager {
cloudTranscription.status || "completed",
cloudTranscription.created_at
);
- return this.db.prepare("SELECT * FROM transcriptions WHERE client_transcription_id = ?").get(cloudTranscription.client_transcription_id);
+ return this.db
+ .prepare("SELECT * FROM transcriptions WHERE client_transcription_id = ?")
+ .get(cloudTranscription.client_transcription_id);
} catch (error) {
- debugLogger.error("Error upserting transcription from cloud", { error: error.message }, "database");
+ debugLogger.error(
+ "Error upserting transcription from cloud",
+ { error: error.message },
+ "database"
+ );
throw error;
}
}
@@ -2190,7 +2276,9 @@ class DatabaseManager {
markTranscriptionSynced(id, cloudId) {
try {
if (!this.db) throw new Error("Database not initialized");
- this.db.prepare("UPDATE transcriptions SET sync_status = 'synced', cloud_id = ? WHERE id = ?").run(cloudId, id);
+ this.db
+ .prepare("UPDATE transcriptions SET sync_status = 'synced', cloud_id = ? WHERE id = ?")
+ .run(cloudId, id);
return { success: true };
} catch (error) {
debugLogger.error("Error marking transcription synced", { error: error.message }, "database");
diff --git a/src/helpers/downloadUtils.js b/src/helpers/downloadUtils.js
index 971c57b54..262d2eb56 100644
--- a/src/helpers/downloadUtils.js
+++ b/src/helpers/downloadUtils.js
@@ -39,8 +39,7 @@ const TLS_ERROR_CODES = new Set([
function isTlsError(error) {
return (
TLS_ERROR_CODES.has(error.code) ||
- (error.message &&
- error.message.includes("unable to get local issuer certificate"))
+ (error.message && error.message.includes("unable to get local issuer certificate"))
);
}
@@ -238,10 +237,10 @@ function downloadAttempt(url, tempPath, options) {
reject(Object.assign(new Error("Download cancelled"), { isAbort: true }));
} else if (isTlsError(err)) {
reject(
- Object.assign(
- new Error(`Certificate error: ${err.message}`),
- { code: "TLS_ERROR", isTlsError: true },
- ),
+ Object.assign(new Error(`Certificate error: ${err.message}`), {
+ code: "TLS_ERROR",
+ isTlsError: true,
+ })
);
} else {
reject(err);
diff --git a/src/services/SyncService.ts b/src/services/SyncService.ts
index 4fc670d89..e0c1df588 100644
--- a/src/services/SyncService.ts
+++ b/src/services/SyncService.ts
@@ -222,7 +222,9 @@ class SyncService {
cloudFolder.client_folder_id ?? ""
);
if (!local || cloudFolder.updated_at > local.created_at) {
- await window.electronAPI.upsertFolderFromCloud?.(cloudFolder);
+ await window.electronAPI.upsertFolderFromCloud?.(
+ cloudFolder as unknown as Record<string, unknown>
+ );
}
}
} catch (err) {
@@ -319,7 +321,10 @@ class SyncService {
: defaultFolderId;
if (!local || cloudNote.updated_at > local.updated_at) {
- await window.electronAPI.upsertNoteFromCloud?.(cloudNote, localFolderId);
+ await window.electronAPI.upsertNoteFromCloud?.(
+ cloudNote as unknown as Record<string, unknown>,
+ localFolderId
+ );
}
}
}
@@ -411,8 +416,8 @@ class SyncService {
);
if (!local || cloudConv.updated_at > local.updated_at) {
await window.electronAPI.upsertConversationFromCloud?.(
- cloudConv,
- cloudConv.messages ?? []
+ cloudConv as unknown as Record<string, unknown>,
+ (cloudConv.messages ?? []) as unknown as Array<Record<string, unknown>>
);
}
}
@@ -478,7 +483,9 @@ class SyncService {
cloudT.client_transcription_id ?? ""
);
if (!local) {
- await window.electronAPI.upsertTranscriptionFromCloud?.(cloudT);
+ await window.electronAPI.upsertTranscriptionFromCloud?.(
+ cloudT as unknown as Record<string, unknown>
+ );
}
}
}
diff --git a/src/services/tools/createNoteTool.ts b/src/services/tools/createNoteTool.ts
index 54776ac6f..6d6da972c 100644
--- a/src/services/tools/createNoteTool.ts
+++ b/src/services/tools/createNoteTool.ts
@@ -58,7 +58,7 @@ export const createNoteTool: ToolDefinition = {
return { success: false, data: null, displayText: "Failed to create note" };
}
- syncService.debouncedPush('note', result.note.id);
+ syncService.debouncedPush("note", result.note.id);
const suffix = folderCreated ? ` in new folder "${folderName}"` : "";
return {
diff --git a/src/services/tools/updateNoteTool.ts b/src/services/tools/updateNoteTool.ts
index 8cf99f61d..0ceb78835 100644
--- a/src/services/tools/updateNoteTool.ts
+++ b/src/services/tools/updateNoteTool.ts
@@ -71,7 +71,7 @@ export const updateNoteTool: ToolDefinition = {
return { success: false, data: null, displayText: "Failed to update note" };
}
- syncService.debouncedPush('note', id);
+ syncService.debouncedPush("note", id);
const suffix = folderCreated ? ` (moved to new folder "${folderName}")` : "";
return {
diff --git a/src/tsconfig.json b/src/tsconfig.json
index 22537951c..84f8984eb 100644
--- a/src/tsconfig.json
+++ b/src/tsconfig.json
@@ -17,8 +17,7 @@
"paths": {
"@/*": ["./*"]
},
- "baseUrl": ".",
- "ignoreDeprecations": "6.0"
+ "baseUrl": "."
},
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"],
"exclude": ["node_modules", "dist"]
diff --git a/src/types/electron.ts b/src/types/electron.ts
index 478bdef06..10d61baa3 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -1144,6 +1144,7 @@ declare global {
title: string;
archived_at?: string;
cloud_id?: string;
+ client_conversation_id?: string;
created_at: string;
updated_at: string;
}>