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: Auto-refresh transcription history via shared store and IPC events
Gabriel Stein322be9286b64
diff --git a/preload.js b/preload.jsindex 6f6944764..485c36dde 100644--- a/preload.js+++ b/preload.js@@ -14,6 +14,22 @@ contextBridge.exposeInMainWorld("electronAPI", {clearTranscriptions: () => ipcRenderer.invoke("db-clear-transcriptions"),deleteTranscription: (id) =>ipcRenderer.invoke("db-delete-transcription", id),+ onTranscriptionAdded: (callback) => {+ const listener = (_event, transcription) => callback?.(transcription);+ ipcRenderer.on("transcription-added", listener);+ return () => ipcRenderer.removeListener("transcription-added", listener);+ },+ onTranscriptionDeleted: (callback) => {+ const listener = (_event, data) => callback?.(data);+ ipcRenderer.on("transcription-deleted", listener);+ return () => ipcRenderer.removeListener("transcription-deleted", listener);+ },+ onTranscriptionsCleared: (callback) => {+ const listener = (_event, data) => callback?.(data);+ ipcRenderer.on("transcriptions-cleared", listener);+ return () =>+ ipcRenderer.removeListener("transcriptions-cleared", listener);+ },// Environment variablesgetOpenAIKey: () => ipcRenderer.invoke("get-openai-key"),diff --git a/src/components/ControlPanel.tsx b/src/components/ControlPanel.tsxindex dfd292140..9d11a1963 100644--- a/src/components/ControlPanel.tsx+++ b/src/components/ControlPanel.tsx@@ -1,7 +1,7 @@import { useState, useEffect } from "react";import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";import { Button } from "./ui/button";-import { Trash2, RefreshCw, Settings, FileText, Mic, X } from "lucide-react";+import { Trash2, Settings, FileText, Mic, X } from "lucide-react";import SettingsModal from "./SettingsModal";import TitleBar from "./TitleBar";import SupportDropdown from "./ui/SupportDropdown";@@ -10,10 +10,15 @@ import { ConfirmDialog, AlertDialog } from "./ui/dialog";import { useDialogs } from "../hooks/useDialogs";import { useHotkey } from "../hooks/useHotkey";import { useToast } from "./ui/Toast";-import type { TranscriptionItem as TranscriptionItemType } from "../types/electron";+import {+ useTranscriptions,+ initializeTranscriptions,+ removeTranscription as removeFromStore,+ clearTranscriptions as clearStoreTranscriptions,+} from "../stores/transcriptionStore";export default function ControlPanel() {- const [history, setHistory] = useState<TranscriptionItemType[]>([]);+ const history = useTranscriptions();const [isLoading, setIsLoading] = useState(true);const [showSettings, setShowSettings] = useState(false);const { hotkey } = useHotkey();@@ -39,7 +44,6 @@ export default function ControlPanel() {};useEffect(() => {- // Load transcription history from databaseloadTranscriptions();// Initialize update status@@ -82,9 +86,12 @@ export default function ControlPanel() {const loadTranscriptions = async () => {try {setIsLoading(true);- const transcriptions = await window.electronAPI.getTranscriptions(50);- setHistory(transcriptions);+ await initializeTranscriptions();} catch (error) {+ showAlertDialog({+ title: "Unable to load history",+ description: "Please try again in a moment.",+ });} finally {setIsLoading(false);}@@ -116,7 +123,7 @@ export default function ControlPanel() {onConfirm: async () => {try {const result = await window.electronAPI.clearTranscriptions();- setHistory([]);+ clearStoreTranscriptions();showAlertDialog({title: "History Cleared",description: `Successfully cleared ${result.cleared} transcriptions from your chronicles.`,@@ -141,8 +148,7 @@ export default function ControlPanel() {try {const result = await window.electronAPI.deleteTranscription(id);if (result.success) {- // Remove from local state- setHistory((prev) => prev.filter((item) => item.id !== id));+ removeFromStore(id);} else {showAlertDialog({title: "Delete Failed",@@ -161,10 +167,6 @@ export default function ControlPanel() {});};- const refreshHistory = async () => {- await loadTranscriptions();- };-return (<div className="min-h-screen bg-white"><ConfirmDialog@@ -233,9 +235,6 @@ export default function ControlPanel() {Recent Transcriptions</CardTitle><div className="flex gap-2">- <Button onClick={refreshHistory} variant="ghost" size="icon">- <RefreshCw size={16} />- </Button>{history.length > 0 && (<ButtononClick={clearHistory}diff --git a/src/helpers/database.js b/src/helpers/database.jsindex f7b427b0d..9c1c7265c 100644--- a/src/helpers/database.js+++ b/src/helpers/database.js@@ -47,8 +47,12 @@ class DatabaseManager {);const result = stmt.run(text);+ const fetchStmt = this.db.prepare(+ "SELECT * FROM transcriptions WHERE id = ?"+ );+ const transcription = fetchStmt.get(result.lastInsertRowid);- return { id: result.lastInsertRowid, success: true };+ return { id: result.lastInsertRowid, success: true, transcription };} catch (error) {console.error("Error saving transcription:", error.message);throw error;@@ -95,7 +99,7 @@ class DatabaseManager {console.log(`🗑️ Deleted transcription ${id}, affected rows: ${result.changes}`);- return { success: result.changes > 0 };+ return { success: result.changes > 0, id };} catch (error) {console.error("❌ Error deleting transcription:", error);throw error;diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex be2c0fbb7..3a22ea01e 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -1,4 +1,4 @@-const { ipcMain, app, shell } = require("electron");+const { ipcMain, app, shell, BrowserWindow } = require("electron");const AppUtils = require("../utils");const debugLogger = require("./debugLogger");@@ -90,7 +90,11 @@ class IPCHandlers {// Database handlersipcMain.handle("db-save-transcription", async (event, text) => {- return this.databaseManager.saveTranscription(text);+ const result = this.databaseManager.saveTranscription(text);+ if (result?.success && result?.transcription) {+ this.broadcastToWindows("transcription-added", result.transcription);+ }+ return result;});ipcMain.handle("db-get-transcriptions", async (event, limit = 50) => {@@ -98,11 +102,21 @@ class IPCHandlers {});ipcMain.handle("db-clear-transcriptions", async (event) => {- return this.databaseManager.clearTranscriptions();+ const result = this.databaseManager.clearTranscriptions();+ if (result?.success) {+ this.broadcastToWindows("transcriptions-cleared", {+ cleared: result.cleared,+ });+ }+ return result;});ipcMain.handle("db-delete-transcription", async (event, id) => {- return this.databaseManager.deleteTranscription(id);+ const result = this.databaseManager.deleteTranscription(id);+ if (result?.success) {+ this.broadcastToWindows("transcription-deleted", { id });+ }+ return result;});// Clipboard handlers@@ -506,6 +520,15 @@ class IPCHandlers {return { success: true };});}++ broadcastToWindows(channel, payload) {+ const windows = BrowserWindow.getAllWindows();+ windows.forEach((win) => {+ if (!win.isDestroyed()) {+ win.webContents.send(channel, payload);+ }+ });+ }}module.exports = IPCHandlers;diff --git a/src/stores/transcriptionStore.ts b/src/stores/transcriptionStore.tsnew file mode 100644index 000000000..5e6ee61b3--- /dev/null+++ b/src/stores/transcriptionStore.ts@@ -0,0 +1,100 @@+import { useSyncExternalStore } from "react";+import type { TranscriptionItem } from "../types/electron";++type Listener = () => void;++const listeners = new Set<Listener>();+let transcriptions: TranscriptionItem[] = [];+let hasBoundIpcListeners = false;+const DEFAULT_LIMIT = 50;+let currentLimit = DEFAULT_LIMIT;++const emit = () => {+ listeners.forEach((listener) => listener());+};++const subscribe = (listener: Listener) => {+ listeners.add(listener);+ return () => listeners.delete(listener);+};++const getSnapshot = () => transcriptions;++function ensureIpcListeners() {+ if (hasBoundIpcListeners || typeof window === "undefined") {+ return;+ }++ const disposers: Array<() => void> = [];++ if (window.electronAPI?.onTranscriptionAdded) {+ const dispose = window.electronAPI.onTranscriptionAdded((item) => {+ if (item) {+ addTranscription(item);+ }+ });+ if (typeof dispose === "function") {+ disposers.push(dispose);+ }+ }++ if (window.electronAPI?.onTranscriptionDeleted) {+ const dispose = window.electronAPI.onTranscriptionDeleted(({ id }) => {+ removeTranscription(id);+ });+ if (typeof dispose === "function") {+ disposers.push(dispose);+ }+ }++ if (window.electronAPI?.onTranscriptionsCleared) {+ const dispose = window.electronAPI.onTranscriptionsCleared(() => {+ clearTranscriptions();+ });+ if (typeof dispose === "function") {+ disposers.push(dispose);+ }+ }++ hasBoundIpcListeners = true;++ window.addEventListener("beforeunload", () => {+ disposers.forEach((dispose) => dispose());+ });+}++export async function initializeTranscriptions(limit = DEFAULT_LIMIT) {+ currentLimit = limit;+ ensureIpcListeners();+ const items = await window.electronAPI.getTranscriptions(limit);+ transcriptions = items;+ emit();+ return items;+}++export function addTranscription(item: TranscriptionItem) {+ if (!item) return;+ const withoutDuplicate = transcriptions.filter(+ (existing) => existing.id !== item.id+ );+ transcriptions = [item, ...withoutDuplicate].slice(0, currentLimit);+ emit();+}++export function removeTranscription(id: number) {+ if (!id) return;+ const next = transcriptions.filter((item) => item.id !== id);+ if (next.length === transcriptions.length) return;+ transcriptions = next;+ emit();+}++export function clearTranscriptions() {+ if (transcriptions.length === 0) return;+ transcriptions = [];+ emit();+}++export function useTranscriptions() {+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);+}diff --git a/src/types/electron.ts b/src/types/electron.tsindex a9866f339..7b215bccf 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -127,6 +127,15 @@ declare global {getTranscriptions: (limit?: number) => Promise<TranscriptionItem[]>;clearTranscriptions: () => Promise<{ cleared: number; success: boolean }>;deleteTranscription: (id: number) => Promise<{ success: boolean }>;+ onTranscriptionAdded?: (+ callback: (item: TranscriptionItem) => void+ ) => (() => void) | void;+ onTranscriptionDeleted?: (+ callback: (payload: { id: number }) => void+ ) => (() => void) | void;+ onTranscriptionsCleared?: (+ callback: (payload: { cleared: number }) => void+ ) => (() => void) | void;// API key managementgetOpenAIKey: () => Promise<string>;