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
refactor: fix React hooks deps, extract modules, remove unused exports
Gabriel Steinfe7d6ec3c509
diff --git a/src/App.jsx b/src/App.jsxindex 79ea35bc5..378b01f89 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -1,8 +1,8 @@-import React, { useState, useEffect, useRef } from "react";+import React, { useState, useEffect, useLayoutEffect, useRef } from "react";import { useTranslation } from "react-i18next";import "./index.css";import { X } from "lucide-react";-import { useToast } from "./components/ui/Toast";+import { useToast } from "./components/ui/useToast";import { LoadingDots } from "./components/ui/LoadingDots";import { useHotkey } from "./hooks/useHotkey";import { formatHotkeyLabel } from "./utils/hotkeys";@@ -108,7 +108,10 @@ export default function App() {const unsubscribeFallback = window.electronAPI?.onHotkeyFallbackUsed?.((data) => {toast({title: t("app.toasts.hotkeyChanged.title"),- description: t("app.toasts.hotkeyChanged.description", { original: data.original, fallback: data.fallback }),+ description: t("app.toasts.hotkeyChanged.description", {+ original: data.original,+ fallback: data.fallback,+ }),duration: 8000,});});@@ -204,7 +207,10 @@ export default function App() {}, []);const isRecordingRef = useRef(isRecording);- isRecordingRef.current = isRecording;++ useLayoutEffect(() => {+ isRecordingRef.current = isRecording;+ }, [isRecording]);useEffect(() => {const unsubscribe = window.electronAPI?.onCancelHotkeyPressed?.(() => {diff --git a/src/AppRouter.jsx b/src/AppRouter.jsxnew file mode 100644index 000000000..e505694f8--- /dev/null+++ b/src/AppRouter.jsx@@ -0,0 +1,190 @@+import React, { Suspense, useEffect, useState } from "react";+import { useTranslation } from "react-i18next";+import App from "./App.jsx";+import AuthenticationStep from "./components/AuthenticationStep.tsx";+import MeetingNotificationOverlay from "./components/MeetingNotificationOverlay.tsx";+import UpdateNotificationOverlay from "./components/UpdateNotificationOverlay.tsx";+import WindowControls from "./components/WindowControls.tsx";+import { Card, CardContent } from "./components/ui/card.tsx";+import { useAuth } from "./hooks/useAuth";+import { useTheme } from "./hooks/useTheme";++const ControlPanel = React.lazy(() => import("./components/ControlPanel.tsx"));+const OnboardingFlow = React.lazy(() => import("./components/OnboardingFlow.tsx"));+const AgentOverlay = React.lazy(() => import("./components/AgentOverlay.tsx"));++export default function AppRouter() {+ useTheme();+ const params = window.location.search;++ if (params.includes("meeting-notification=true")) {+ return <MeetingNotificationOverlay />;+ }++ if (params.includes("update-notification=true")) {+ return <UpdateNotificationOverlay />;+ }++ return <MainApp />;+}++function MainApp() {+ const { isSignedIn, isGracePeriodOnly, isLoaded: authLoaded } = useAuth();++ const [showOnboarding, setShowOnboarding] = useState(false);+ const [needsReauth, setNeedsReauth] = useState(false);+ const [isLoading, setIsLoading] = useState(true);++ const isAgentPanel = window.location.search.includes("agent=true");+ const isControlPanel =+ !isAgentPanel &&+ (window.location.pathname.includes("control") || window.location.search.includes("panel=true"));+ const isDictationPanel = !isControlPanel && !isAgentPanel;++ useEffect(() => {+ if (isAgentPanel) {+ import("./components/AgentOverlay.tsx").catch(() => {});+ } else if (isControlPanel) {+ import("./components/ControlPanel.tsx").catch(() => {});++ if (!localStorage.getItem("onboardingCompleted")) {+ import("./components/OnboardingFlow.tsx").catch(() => {});+ }+ }+ }, [isAgentPanel, isControlPanel]);++ useEffect(() => {+ if (!authLoaded) return;++ const onboardingCompleted = localStorage.getItem("onboardingCompleted") === "true";+ const authSkipped =+ localStorage.getItem("authenticationSkipped") === "true" ||+ localStorage.getItem("skipAuth") === "true";+ const onboardingInProgress = localStorage.getItem("onboardingCurrentStep") !== null;+ const isReturningUser =+ !onboardingCompleted && isSignedIn && !isGracePeriodOnly && !onboardingInProgress;++ if (isReturningUser) {+ localStorage.setItem("onboardingCompleted", "true");+ }++ const resolved = localStorage.getItem("onboardingCompleted") === "true";++ if (isControlPanel) {+ if (!resolved) {+ setShowOnboarding(true);+ } else if (!isSignedIn && !authSkipped) {+ setNeedsReauth(true);+ }+ }++ if (isDictationPanel && !resolved) {+ const rawStep = parseInt(localStorage.getItem("onboardingCurrentStep") || "0");+ const currentStep = Math.max(0, Math.min(rawStep, 5));+ if (currentStep < 4) {+ window.electronAPI?.hideWindow?.();+ }+ }++ setIsLoading(false);+ }, [authLoaded, isControlPanel, isDictationPanel, isGracePeriodOnly, isSignedIn]);++ const handleOnboardingComplete = () => {+ setShowOnboarding(false);+ localStorage.setItem("onboardingCompleted", "true");+ };++ if (isAgentPanel) {+ return (+ <Suspense fallback={<LoadingFallback />}>+ <AgentOverlay />+ </Suspense>+ );+ }++ if (isLoading) {+ return <LoadingFallback />;+ }++ if (isControlPanel && showOnboarding) {+ return (+ <Suspense fallback={<LoadingFallback />}>+ <OnboardingFlow onComplete={handleOnboardingComplete} />+ </Suspense>+ );+ }++ if (isControlPanel && needsReauth) {+ return (+ <div+ className="h-screen flex flex-col bg-background"+ style={{ paddingTop: "env(safe-area-inset-top, 0px)" }}+ >+ <div+ className="flex items-center justify-end w-full h-10 shrink-0"+ style={{ WebkitAppRegion: "drag" }}+ >+ {window.electronAPI?.getPlatform?.() !== "darwin" && (+ <div className="pr-1" style={{ WebkitAppRegion: "no-drag" }}>+ <WindowControls />+ </div>+ )}+ </div>+ <div className="flex-1 px-6 overflow-y-auto flex items-center">+ <div className="w-full max-w-sm mx-auto">+ <Card className="bg-card/90 backdrop-blur-2xl border border-border/50 dark:border-white/5 shadow-lg rounded-xl overflow-hidden">+ <CardContent className="p-6">+ <AuthenticationStep+ onContinueWithoutAccount={() => {+ localStorage.setItem("authenticationSkipped", "true");+ localStorage.setItem("skipAuth", "true");+ setNeedsReauth(false);+ }}+ onAuthComplete={() => setNeedsReauth(false)}+ onNeedsVerification={() => {}}+ />+ </CardContent>+ </Card>+ </div>+ </div>+ </div>+ );+ }++ return isControlPanel ? (+ <Suspense fallback={<LoadingFallback />}>+ <ControlPanel />+ </Suspense>+ ) : (+ <App />+ );+}++function LoadingFallback({ message }) {+ const { t } = useTranslation();+ const fallbackMessage = message || t("common.loading");++ return (+ <div className="min-h-screen bg-background flex items-center justify-center">+ <div className="flex flex-col items-center gap-4 animate-[scale-in_300ms_ease-out]">+ <svg+ viewBox="0 0 1024 1024"+ className="w-12 h-12 drop-shadow-[0_2px_8px_rgba(37,99,235,0.18)] dark:drop-shadow-[0_2px_12px_rgba(100,149,237,0.25)]"+ aria-label="OpenWhispr"+ >+ <rect width="1024" height="1024" rx="241" fill="#2056DF" />+ <circle cx="512" cy="512" r="314" fill="#2056DF" stroke="white" strokeWidth="74" />+ <path d="M512 383V641" stroke="white" strokeWidth="74" strokeLinecap="round" />+ <path d="M627 457V568" stroke="white" strokeWidth="74" strokeLinecap="round" />+ <path d="M397 457V568" stroke="white" strokeWidth="74" strokeLinecap="round" />+ </svg>+ <div className="w-7 h-7 rounded-full border-[2.5px] border-transparent border-t-primary animate-[spinner-rotate_0.8s_cubic-bezier(0.4,0,0.2,1)_infinite] motion-reduce:animate-none motion-reduce:border-t-muted-foreground motion-reduce:opacity-50" />+ {fallbackMessage && (+ <p className="text-[13px] font-medium text-muted-foreground dark:text-foreground/60 tracking-[-0.01em]">+ {fallbackMessage}+ </p>+ )}+ </div>+ </div>+ );+}diff --git a/src/components/AuthenticationStep.tsx b/src/components/AuthenticationStep.tsxindex bc5855ae7..7cf427886 100644--- a/src/components/AuthenticationStep.tsx+++ b/src/components/AuthenticationStep.tsx@@ -284,7 +284,7 @@ export default function AuthenticationStep({setIsSubmitting(false);}},- [authMode, email, password, onAuthComplete, onNeedsVerification, t]+ [authMode, email, fullName, password, onAuthComplete, onNeedsVerification, t]);const handleBack = useCallback(() => {diff --git a/src/components/ControlPanel.tsx b/src/components/ControlPanel.tsxindex 3d5625c06..5a31cd6ac 100644--- a/src/components/ControlPanel.tsx+++ b/src/components/ControlPanel.tsx@@ -6,7 +6,7 @@ import UpgradePrompt from "./UpgradePrompt";import { ConfirmDialog, AlertDialog } from "./ui/dialog";import { useDialogs } from "../hooks/useDialogs";import { useHotkey } from "../hooks/useHotkey";-import { useToast } from "./ui/Toast";+import { useToast } from "./ui/useToast";import { useUpdater } from "../hooks/useUpdater";import { useSettings } from "../hooks/useSettings";import { useAuth } from "../hooks/useAuth";diff --git a/src/components/DeveloperSection.tsx b/src/components/DeveloperSection.tsxindex 5daedc0f4..e52fb0deb 100644--- a/src/components/DeveloperSection.tsx+++ b/src/components/DeveloperSection.tsx@@ -2,9 +2,9 @@ import { useState, useEffect } from "react";import { useTranslation } from "react-i18next";import { Button } from "./ui/button";import { FolderOpen, Copy, Check } from "lucide-react";-import { useToast } from "./ui/Toast";+import { useToast } from "./ui/useToast";import { Toggle } from "./ui/toggle";-import { useSettingsLayout } from "./ui/SidebarModal";+import { useSettingsLayout } from "./ui/useSettingsLayout";import logger from "../utils/logger";export default function DeveloperSection() {diff --git a/src/components/EmailVerificationStep.tsx b/src/components/EmailVerificationStep.tsxindex a70385d6f..858c9e558 100644--- a/src/components/EmailVerificationStep.tsx+++ b/src/components/EmailVerificationStep.tsx@@ -51,7 +51,7 @@ export default function EmailVerificationStep({ email, onVerified }: EmailVerifireturn () => {if (pollRef.current) clearInterval(pollRef.current);};- }, [email, verified, onVerified]);+ }, [email, verified, onVerified, t]);const handleResend = useCallback(async () => {if (resendCooldown > 0 || isResending || !OPENWHISPR_API_URL) return;diff --git a/src/components/OnboardingFlow.tsx b/src/components/OnboardingFlow.tsxindex f9e64cbc9..742df04a9 100644--- a/src/components/OnboardingFlow.tsx+++ b/src/components/OnboardingFlow.tsx@@ -221,7 +221,8 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {// Get platform-appropriate default hotkey from backend (accounts for// X11 modifier-only and GNOME gsettings limitations)- const defaultHotkey = await window.electronAPI?.getEffectiveDefaultHotkey?.() || getDefaultHotkey();+ const defaultHotkey =+ (await window.electronAPI?.getEffectiveDefaultHotkey?.()) || getDefaultHotkey();const platform = window.electronAPI?.getPlatform?.() ?? "darwin";// Only auto-register if no hotkey is currently set@@ -243,7 +244,7 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {};void autoRegisterDefaultHotkey();- }, [currentStep, hotkey, registerHotkey, activationStepIndex]);+ }, [currentStep, hotkey, registerHotkey, activationStepIndex, setDictationKey]);const ensureHotkeyRegistered = useCallback(async () => {if (!window.electronAPI?.updateHotkey) {@@ -303,6 +304,7 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {ensureHotkeyRegistered,isSignedIn,useLocalWhisper,+ skipAuth,updateTranscriptionSettings,]);diff --git a/src/components/ReasoningModelSelector.tsx b/src/components/ReasoningModelSelector.tsxindex 57bac5dc8..3d55318fd 100644--- a/src/components/ReasoningModelSelector.tsx+++ b/src/components/ReasoningModelSelector.tsx@@ -32,6 +32,8 @@ type CloudModelOption = {invertInDark?: boolean;};+const CLOUD_PROVIDER_IDS = ["openai", "anthropic", "gemini", "groq", "custom"];+interface ReasoningModelSelectorProps {reasoningModel: string;setReasoningModel: (model: string) => void;@@ -492,8 +494,7 @@ export default function ReasoningModelSelector({return customModelOptions;}, [isCustomBaseDirty, customModelOptions]);- const cloudProviderIds = ["openai", "anthropic", "gemini", "groq", "custom"];- const cloudProviders = cloudProviderIds.map((id) => ({+ const cloudProviders = CLOUD_PROVIDER_IDS.map((id) => ({id,name:id === "custom"@@ -589,7 +590,7 @@ export default function ReasoningModelSelector({if (localProviderIds.includes(localReasoningProvider)) {setSelectedMode("local");setSelectedLocalProvider(localReasoningProvider);- } else if (cloudProviderIds.includes(localReasoningProvider)) {+ } else if (CLOUD_PROVIDER_IDS.includes(localReasoningProvider)) {setSelectedMode("cloud");setSelectedCloudProvider(localReasoningProvider);}diff --git a/src/components/ReferralDashboard.tsx b/src/components/ReferralDashboard.tsxindex b28446599..e2902a45f 100644--- a/src/components/ReferralDashboard.tsx+++ b/src/components/ReferralDashboard.tsx@@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";import { Send, Mail, Copy, Check, Link, UserPlus, Gift, CheckCircle2, User } from "lucide-react";import { Badge } from "./ui/badge";import { Tabs, TabsList, TabsTrigger, TabsContent } from "./ui/tabs";-import { useToast } from "./ui/Toast";+import { useToast } from "./ui/useToast";import { cn } from "./lib/utils";import { SpectrogramCard } from "./referral-cards/SpectrogramCard";import logger from "../utils/logger";diff --git a/src/components/SettingsModal.tsx b/src/components/SettingsModal.tsxindex 8bf26afc3..4064af648 100644--- a/src/components/SettingsModal.tsx+++ b/src/components/SettingsModal.tsx@@ -11,7 +11,7 @@ import {Shield,MessageSquare,} from "lucide-react";-import SidebarModal, { SidebarItem } from "./ui/SidebarModal";+import SidebarModal, { type SidebarItem } from "./ui/SidebarModal";import SettingsPage, { SettingsSectionType } from "./SettingsPage";export type { SettingsSectionType };diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsxindex 30c26ee20..a4d8aeebe 100644--- a/src/components/SettingsPage.tsx+++ b/src/components/SettingsPage.tsx@@ -69,12 +69,12 @@ import AgentModeSettings from "./settings/AgentModeSettings";import LanguageSelector from "./ui/LanguageSelector";import { Skeleton } from "./ui/skeleton";import { Progress } from "./ui/progress";-import { useToast } from "./ui/Toast";+import { useToast } from "./ui/useToast";import { useTheme } from "../hooks/useTheme";import type { GpuDevice, LocalTranscriptionProvider } from "../types/electron";import logger from "../utils/logger";import { SettingsRow } from "./ui/SettingsSection";-import { useSettingsLayout } from "./ui/SidebarModal";+import { useSettingsLayout } from "./ui/useSettingsLayout";import { useUsage } from "../hooks/useUsage";import { cn } from "./lib/utils";import { startMigration, useMigration } from "../stores/noteStore.js";@@ -827,7 +827,7 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPageconst migration = useMigration();- const whisperHook = useWhisper();+ const { checkWhisperInstallation } = useWhisper();const permissionsHook = usePermissions(showAlertDialog);const systemAudio = useSystemAudioPermission();useClipboard(showAlertDialog);@@ -1077,7 +1077,7 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPageif (version && mounted) setCurrentVersion(version);if (mounted) {- whisperHook.checkWhisperInstallation();+ checkWhisperInstallation();}}, 100);@@ -1085,7 +1085,7 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPagemounted = false;clearTimeout(timer);};- }, [whisperHook.checkWhisperInstallation, getAppVersion]);+ }, [checkWhisperInstallation, getAppVersion]);useEffect(() => {const checkHotkeyMode = async () => {diff --git a/src/components/TranscriptionModelPicker.tsx b/src/components/TranscriptionModelPicker.tsxindex c7c103eb5..6dfb3496a 100644--- a/src/components/TranscriptionModelPicker.tsx+++ b/src/components/TranscriptionModelPicker.tsx@@ -298,6 +298,7 @@ export default function TranscriptionModelPicker({if (selectedLocalProvider !== internalLocalProvider) {setInternalLocalProvider(selectedLocalProvider);}+ // eslint-disable-next-line react-hooks/exhaustive-deps -- sync prop→state: only re-run when the prop changes}, [selectedLocalProvider]);const isLoadingRef = useRef(false);const isLoadingParakeetRef = useRef(false);diff --git a/src/components/UsageDisplay.tsx b/src/components/UsageDisplay.tsxindex 3186d0825..a7d7d2b64 100644--- a/src/components/UsageDisplay.tsx+++ b/src/components/UsageDisplay.tsx@@ -1,7 +1,7 @@import { useEffect, useRef } from "react";import { useTranslation } from "react-i18next";import { useUsage } from "../hooks/useUsage";-import { useToast } from "./ui/Toast";+import { useToast } from "./ui/useToast";import { Badge } from "./ui/badge";import { Progress } from "./ui/progress";import { Button } from "./ui/button";diff --git a/src/components/notes/ActionPicker.tsx b/src/components/notes/ActionPicker.tsxindex 0c5d4365c..b30037a34 100644--- a/src/components/notes/ActionPicker.tsx+++ b/src/components/notes/ActionPicker.tsx@@ -30,12 +30,13 @@ export default function ActionPicker({}: ActionPickerProps) {const { t } = useTranslation();const actions = useActions();- const [lastUsedId, setLastUsedId] = useState<number | null>(null);+ const [lastUsedId, setLastUsedId] = useState<number | null>(() => {+ const stored = localStorage.getItem("lastUsedActionId");+ return stored ? Number(stored) : null;+ });useEffect(() => {initializeActions();- const stored = localStorage.getItem("lastUsedActionId");- if (stored) setLastUsedId(Number(stored));}, []);const activeAction = actions.find((a) => a.id === lastUsedId) ?? actions[0] ?? null;diff --git a/src/components/notes/NoteEditor.tsx b/src/components/notes/NoteEditor.tsxindex db3f1c6d4..dbe480c06 100644--- a/src/components/notes/NoteEditor.tsx+++ b/src/components/notes/NoteEditor.tsx@@ -164,7 +164,7 @@ export default function NoteEditor({} catch {return [];}- }, [note.id, note.participants]);+ }, [note.participants]);const updateSegmentIndicator = useCallback(() => {const container = segmentContainerRef.current;diff --git a/src/components/notes/NoteParticipants.tsx b/src/components/notes/NoteParticipants.tsxindex ba7d08e0f..18f2c5603 100644--- a/src/components/notes/NoteParticipants.tsx+++ b/src/components/notes/NoteParticipants.tsx@@ -91,7 +91,7 @@ export default function NoteParticipants({ noteId, participants }: NoteParticipareturn next;});});- }, [localParticipants]);+ }, [localParticipants, gravatarHashes]);useEffect(() => {if (!open) return;diff --git a/src/components/notes/PersonalNotesView.tsx b/src/components/notes/PersonalNotesView.tsxindex 993ecb02f..82ec4bba2 100644--- a/src/components/notes/PersonalNotesView.tsx+++ b/src/components/notes/PersonalNotesView.tsx@@ -31,7 +31,7 @@ import {SelectSeparator,} from "../ui/select";import { Input } from "../ui/input";-import { useToast } from "../ui/Toast";+import { useToast } from "../ui/useToast";import NoteListItem from "./NoteListItem";import NoteEditor from "./NoteEditor";import ActionPicker from "./ActionPicker";@@ -285,7 +285,7 @@ export default function PersonalNotesView({setActiveNoteId(result.note.id);loadFolders();}- }, [activeFolderId, loadFolders]);+ }, [activeFolderId, loadFolders, t]);const handleOpenNewNoteDialog = useCallback(() => {const personal = findDefaultFolder(folders);@@ -330,7 +330,7 @@ export default function PersonalNotesView({loadFolders();}setShowNewNoteDialog(false);- }, [newNoteFolderId, loadFolders]);+ }, [newNoteFolderId, loadFolders, t]);const handleNotesAdded = useCallback(async () => {if (activeFolderId) {diff --git a/src/components/ui/HotkeyInput.tsx b/src/components/ui/HotkeyInput.tsxindex e2066eb5a..69d2b065c 100644--- a/src/components/ui/HotkeyInput.tsx+++ b/src/components/ui/HotkeyInput.tsx@@ -149,7 +149,7 @@ export interface HotkeyInputProps {validate?: (hotkey: string) => string | null | undefined;}-export function mapKeyboardEventToHotkey(e: KeyboardEvent): string | null {+function mapKeyboardEventToHotkey(e: KeyboardEvent): string | null {if (MODIFIER_CODES.has(e.code)) {return null;}diff --git a/src/components/ui/LanguageSelector.tsx b/src/components/ui/LanguageSelector.tsxindex 8c2e9c109..485a55269 100644--- a/src/components/ui/LanguageSelector.tsx+++ b/src/components/ui/LanguageSelector.tsx@@ -1,4 +1,4 @@-import React, { useState, useRef, useEffect } from "react";+import React, { useState, useRef, useEffect, useCallback } from "react";import { useTranslation } from "react-i18next";import { createPortal } from "react-dom";import { ChevronDown, Search, X, Check } from "lucide-react";@@ -38,7 +38,10 @@ export default function LanguageSelector({const [searchQuery, setSearchQuery] = useState("");const [highlightedIndex, setHighlightedIndex] = useState(0);const [dropdownPosition, setDropdownPosition] = useState({ top: 0, left: 0, width: 0 });- const containerRef = useRef<HTMLDivElement>(null);+ const [portalTarget, setPortalTarget] = useState<HTMLElement | null>(+ typeof document === "undefined" ? null : document.body+ );+ const containerRef = useRef<HTMLDivElement | null>(null);const dropdownRef = useRef<HTMLDivElement>(null);const triggerRef = useRef<HTMLButtonElement>(null);const searchInputRef = useRef<HTMLInputElement>(null);@@ -51,25 +54,24 @@ export default function LanguageSelector({): items;- useEffect(() => {+ const handleSearchQueryChange = useCallback((value: string) => {+ setSearchQuery(value);setHighlightedIndex(0);- }, [searchQuery]);+ }, []);// Determine the portal container: use the closest dialog if inside one (to stay// within Radix's focus trap), otherwise fall back to document.body.- const portalTarget = useRef<HTMLElement>(document.body);-- useEffect(() => {- if (containerRef.current) {- const dialog = containerRef.current.closest('[role="dialog"]');- portalTarget.current = (dialog as HTMLElement) ?? document.body;- }+ const setContainerNode = useCallback((node: HTMLDivElement | null) => {+ containerRef.current = node;+ if (!node) return;+ const dialog = node.closest('[role="dialog"]');+ setPortalTarget((dialog as HTMLElement) ?? document.body);}, []);useEffect(() => {- if (isOpen && triggerRef.current) {+ if (isOpen && triggerRef.current && portalTarget) {const triggerRect = triggerRef.current.getBoundingClientRect();- const target = portalTarget.current;+ const target = portalTarget;// When portaled into a transformed ancestor (e.g. Radix Dialog),// fixed positioning is relative to that ancestor, not the viewport.const offsetX = target === document.body ? 0 : target.getBoundingClientRect().left;@@ -83,7 +85,7 @@ export default function LanguageSelector({searchInputRef.current?.focus();});}- }, [isOpen]);+ }, [isOpen, portalTarget]);useEffect(() => {const handleClickOutside = (event: MouseEvent) => {const target = event.target as Node;@@ -127,7 +129,7 @@ export default function LanguageSelector({case "Escape":e.preventDefault();setIsOpen(false);- setSearchQuery("");+ handleSearchQueryChange("");break;}};@@ -135,18 +137,18 @@ export default function LanguageSelector({const handleSelect = (languageValue: string) => {onChange(languageValue);setIsOpen(false);- setSearchQuery("");+ handleSearchQueryChange("");};const clearSearch = () => {- setSearchQuery("");+ handleSearchQueryChange("");if (searchInputRef.current) {searchInputRef.current.focus();}};return (- <div className={`relative ${className}`} ref={containerRef}>+ <div className={`relative ${className}`} ref={setContainerNode}>{/* Trigger button - premium, tight, tactile macOS-style */}<buttonref={triggerRef}@@ -184,6 +186,7 @@ export default function LanguageSelector({{/* Dropdown - ultra-premium glassmorphic panel (rendered via portal) */}{isOpen &&+ portalTarget &&createPortal(<divref={dropdownRef}@@ -203,7 +206,7 @@ export default function LanguageSelector({ref={searchInputRef}type="text"value={searchQuery}- onChange={(e) => setSearchQuery(e.target.value)}+ onChange={(e) => handleSearchQueryChange(e.target.value)}onKeyDown={handleKeyDown}placeholder={t("languageSelector.searchPlaceholder")}className="w-full h-7 pl-7 pr-6 text-xs bg-transparent text-foreground border-0 focus:outline-none placeholder:text-muted-foreground/50"@@ -265,7 +268,7 @@ export default function LanguageSelector({)}</div></div>,- portalTarget.current+ portalTarget)}</div>);diff --git a/src/components/ui/SettingsSection.tsx b/src/components/ui/SettingsSection.tsxindex daf4c9e9a..3273c990a 100644--- a/src/components/ui/SettingsSection.tsx+++ b/src/components/ui/SettingsSection.tsx@@ -1,5 +1,5 @@import React from "react";-import { useSettingsLayout } from "./SidebarModal";+import { useSettingsLayout } from "./useSettingsLayout";interface SettingsSectionProps {title: string;diff --git a/src/components/ui/SidebarModal.tsx b/src/components/ui/SidebarModal.tsxindex 1f3db430b..1f99e3423 100644--- a/src/components/ui/SidebarModal.tsx+++ b/src/components/ui/SidebarModal.tsx@@ -2,9 +2,7 @@ import React from "react";import { useTranslation } from "react-i18next";import * as DialogPrimitive from "@radix-ui/react-dialog";import { X } from "lucide-react";--const SettingsLayoutContext = React.createContext({ isCompact: false });-export const useSettingsLayout = () => React.useContext(SettingsLayoutContext);+import { SettingsLayoutProvider } from "./useSettingsLayout";export interface SidebarItem<T extends string> {id: T;@@ -225,9 +223,9 @@ export default function SidebarModal<T extends string>({{/* Main Content */}<div className="flex-1 overflow-y-auto bg-background dark:bg-surface-1">- <SettingsLayoutContext.Provider value={{ isCompact }}>+ <SettingsLayoutProvider value={{ isCompact }}><div className={isCompact ? "p-4" : "p-6"}>{children}</div>- </SettingsLayoutContext.Provider>+ </SettingsLayoutProvider></div></div></div>diff --git a/src/components/ui/Toast.tsx b/src/components/ui/Toast.tsxindex ef6b26100..93cae0d62 100644--- a/src/components/ui/Toast.tsx+++ b/src/components/ui/Toast.tsx@@ -1,32 +1,7 @@import * as React from "react";import { X, Copy, Check } from "lucide-react";import { cn } from "../lib/utils";--export interface ToastProps {- id?: string;- title?: string;- description?: string;- action?: React.ReactNode;- variant?: "default" | "destructive" | "success";- duration?: number;- onClose?: () => void;-}--export interface ToastContextType {- toast: (props: Omit<ToastProps, "id">) => void;- dismiss: (id?: string) => void;- toastCount: number;-}--const ToastContext = React.createContext<ToastContextType | undefined>(undefined);--export const useToast = () => {- const context = React.useContext(ToastContext);- if (!context) {- throw new Error("useToast must be used within a ToastProvider");- }- return context;-};+import { ToastContext, type ToastProps } from "./useToast";interface ToastState extends ToastProps {id: string;@@ -313,18 +288,3 @@ const Toast: React.FC<</div>);};--export const toast = {- success: (message: string) => ({- title: message,- variant: "success" as const,- }),- error: (message: string) => ({- title: message,- variant: "destructive" as const,- }),- info: (message: string) => ({- title: message,- variant: "default" as const,- }),-};diff --git a/src/components/ui/badge.tsx b/src/components/ui/badge.tsxindex 4efd78f9f..a3e7117f7 100644--- a/src/components/ui/badge.tsx+++ b/src/components/ui/badge.tsx@@ -33,4 +33,4 @@ function Badge({ className, variant, ...props }: BadgeProps) {return <div className={cn(badgeVariants({ variant }), className)} {...props} />;}-export { Badge, badgeVariants };+export { Badge };diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsxindex eab3230d3..a914c138a 100644--- a/src/components/ui/button.tsx+++ b/src/components/ui/button.tsx@@ -143,4 +143,4 @@ function Button({);}-export { Button, buttonVariants };+export { Button };diff --git a/src/components/ui/useSettingsLayout.ts b/src/components/ui/useSettingsLayout.tsnew file mode 100644index 000000000..ac6bad413--- /dev/null+++ b/src/components/ui/useSettingsLayout.ts@@ -0,0 +1,7 @@+import React from "react";++const SettingsLayoutContext = React.createContext({ isCompact: false });++export const SettingsLayoutProvider = SettingsLayoutContext.Provider;++export const useSettingsLayout = () => React.useContext(SettingsLayoutContext);diff --git a/src/components/ui/useToast.ts b/src/components/ui/useToast.tsnew file mode 100644index 000000000..19223bb89--- /dev/null+++ b/src/components/ui/useToast.ts@@ -0,0 +1,27 @@+import * as React from "react";++export interface ToastProps {+ id?: string;+ title?: string;+ description?: string;+ action?: React.ReactNode;+ variant?: "default" | "destructive" | "success";+ duration?: number;+ onClose?: () => void;+}++export interface ToastContextType {+ toast: (props: Omit<ToastProps, "id">) => void;+ dismiss: (id?: string) => void;+ toastCount: number;+}++export const ToastContext = React.createContext<ToastContextType | undefined>(undefined);++export const useToast = () => {+ const context = React.useContext(ToastContext);+ if (!context) {+ throw new Error("useToast must be used within a ToastProvider");+ }+ return context;+};diff --git a/src/hooks/useEmbeddedChat.ts b/src/hooks/useEmbeddedChat.tsindex 62ccfd262..e0d2e5117 100644--- a/src/hooks/useEmbeddedChat.ts+++ b/src/hooks/useEmbeddedChat.ts@@ -1,4 +1,4 @@-import { useState, useCallback, useEffect, useRef } from "react";+import { useState, useCallback, useEffect, useMemo, useRef } from "react";import { useChatPersistence } from "../components/chat/useChatPersistence";import { useChatStreaming } from "../components/chat/useChatStreaming";import type { Message, AgentState } from "../components/chat/types";@@ -48,21 +48,24 @@ export function useEmbeddedChat({},});- const noteContextRef = useRef("");- noteContextRef.current = [- `Note ID: ${noteId}`,- folderId != null ? `Folder ID: ${folderId}` : "",- `Title: ${noteTitle}`,- `Content:\n${noteContent}`,- noteTranscript ? `\nTranscript:\n${noteTranscript}` : "",- ]- .filter(Boolean)- .join("\n");+ const noteContext = useMemo(+ () =>+ [+ `Note ID: ${noteId}`,+ folderId != null ? `Folder ID: ${folderId}` : "",+ `Title: ${noteTitle}`,+ `Content:\n${noteContent}`,+ noteTranscript ? `\nTranscript:\n${noteTranscript}` : "",+ ]+ .filter(Boolean)+ .join("\n"),+ [folderId, noteContent, noteId, noteTitle, noteTranscript]+ );const streaming = useChatStreaming({messages: persistence.messages,setMessages: persistence.setMessages,- noteContext: noteContextRef.current,+ noteContext,onStreamComplete: (_id, content, toolCalls) => {persistence.saveAssistantMessage(content, toolCalls);},diff --git a/src/hooks/useFolderManagement.ts b/src/hooks/useFolderManagement.tsindex 401050cb4..dc6303453 100644--- a/src/hooks/useFolderManagement.ts+++ b/src/hooks/useFolderManagement.ts@@ -1,6 +1,6 @@import { useState, useEffect, useRef, useCallback } from "react";import { useTranslation } from "react-i18next";-import { useToast } from "../components/ui/Toast";+import { useToast } from "../components/ui/useToast";import logger from "../utils/logger";import type { FolderItem } from "../types/electron";import { findDefaultFolder } from "../components/notes/shared";@@ -111,7 +111,7 @@ export function useFolderManagement(): UseFolderManagementReturn {return () => {isMountedRef.current = false;};- }, []);+ }, [loadFolders]);// Re-initialize notes when active folder changesuseEffect(() => {diff --git a/src/hooks/useModelDownload.ts b/src/hooks/useModelDownload.tsindex 334bc611c..c644765cc 100644--- a/src/hooks/useModelDownload.ts+++ b/src/hooks/useModelDownload.ts@@ -2,7 +2,7 @@ import { useState, useCallback, useEffect, useRef } from "react";import type { TFunction } from "i18next";import { useTranslation } from "react-i18next";import { useDialogs } from "./useDialogs";-import { useToast } from "../components/ui/Toast";+import { useToast } from "../components/ui/useToast";import type { WhisperDownloadProgressData } from "../types/electron";import "../types/electron";diff --git a/src/hooks/usePermissions.ts b/src/hooks/usePermissions.tsindex eeae85721..dda9b07c5 100644--- a/src/hooks/usePermissions.ts+++ b/src/hooks/usePermissions.ts@@ -213,7 +213,7 @@ export const usePermissions = (alert(message);}}- }, [showAlertDialog, t]);+ }, [showAlertDialog, t, setMicPermissionGranted]);const checkPasteToolsAvailability = useCallback(async (): Promise<PasteToolsResult | null> => {setIsCheckingPasteTools(true);diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.tsindex fe3968bdf..8e0c63bf3 100644--- a/src/hooks/useSettings.ts+++ b/src/hooks/useSettings.ts@@ -73,6 +73,7 @@ export interface AgentModeSettings {function useSettingsInternal() {const store = useSettingsStore();+ const { setCustomDictionary } = store;// One-time initialization: sync API keys, dictation key, activation mode,// UI language, and dictionary from the main process / SQLite.@@ -94,11 +95,11 @@ function useSettingsInternal() {if (typeof window === "undefined" || !window.electronAPI?.onDictionaryUpdated) return;const unsubscribe = window.electronAPI.onDictionaryUpdated((words: string[]) => {if (Array.isArray(words)) {- store.setCustomDictionary(words);+ setCustomDictionary(words);}});return unsubscribe;- }, [store.setCustomDictionary]);+ }, [setCustomDictionary]);// Auto-learn corrections from user edits in external appsconst [autoLearnCorrections, setAutoLearnCorrectionsRaw] = useLocalStorage(diff --git a/src/main.jsx b/src/main.jsxindex 4b6190dfa..6a2b041b3 100644--- a/src/main.jsx+++ b/src/main.jsx@@ -1,30 +1,14 @@-import React, { Suspense, useState, useEffect } from "react";+import React from "react";import ReactDOM from "react-dom/client";-import { I18nextProvider, useTranslation } from "react-i18next";-import App from "./App.jsx";-import AuthenticationStep from "./components/AuthenticationStep.tsx";-import WindowControls from "./components/WindowControls.tsx";-import { Card, CardContent } from "./components/ui/card.tsx";+import { I18nextProvider } from "react-i18next";+import AppRouter from "./AppRouter.jsx";import ErrorBoundary from "./components/ErrorBoundary.tsx";import { ToastProvider } from "./components/ui/Toast.tsx";import { SettingsProvider } from "./hooks/useSettings";-import { useTheme } from "./hooks/useTheme";-import { useAuth } from "./hooks/useAuth";import i18n from "./i18n";import "./index.css";-const controlPanelImport = () => import("./components/ControlPanel.tsx");-const onboardingFlowImport = () => import("./components/OnboardingFlow.tsx");-const agentOverlayImport = () => import("./components/AgentOverlay.tsx");--const ControlPanel = React.lazy(controlPanelImport);-const OnboardingFlow = React.lazy(onboardingFlowImport);-const AgentOverlay = React.lazy(agentOverlayImport);--import MeetingNotificationOverlay from "./components/MeetingNotificationOverlay.tsx";-import UpdateNotificationOverlay from "./components/UpdateNotificationOverlay.tsx";-let root = null;const VALID_CHANNELS = new Set(["development", "staging", "production"]);@@ -274,190 +258,6 @@ if (!isOAuthBrowserRedirect()) {mountApp();}-function AppRouter() {- useTheme();- const params = window.location.search;-- if (params.includes("meeting-notification=true")) {- return <MeetingNotificationOverlay />;- }-- if (params.includes("update-notification=true")) {- return <UpdateNotificationOverlay />;- }-- return <MainApp />;-}--function MainApp() {- const { isSignedIn, isGracePeriodOnly, isLoaded: authLoaded } = useAuth();-- const [showOnboarding, setShowOnboarding] = useState(false);- const [needsReauth, setNeedsReauth] = useState(false);-- const [isLoading, setIsLoading] = useState(true);-- const isAgentPanel = window.location.search.includes("agent=true");- const isControlPanel =- !isAgentPanel &&- (window.location.pathname.includes("control") || window.location.search.includes("panel=true"));- const isDictationPanel = !isControlPanel && !isAgentPanel;-- // Preload lazy chunks while waiting for auth so Suspense resolves instantly- useEffect(() => {- if (isAgentPanel) {- agentOverlayImport().catch(() => {});- } else if (isControlPanel) {- controlPanelImport().catch(() => {});-- if (!localStorage.getItem("onboardingCompleted")) {- onboardingFlowImport().catch(() => {});- }- }- }, [isControlPanel, isAgentPanel]);-- useEffect(() => {- if (!authLoaded) return;-- const onboardingCompleted = localStorage.getItem("onboardingCompleted") === "true";- const authSkipped =- localStorage.getItem("authenticationSkipped") === "true" ||- localStorage.getItem("skipAuth") === "true";-- // Actual session (not OAuth grace period) proves prior onboarding — restore flag if localStorage was wiped.- // Guard with onboardingInProgress so first-time users mid-onboarding don't get auto-completed.- const onboardingInProgress = localStorage.getItem("onboardingCurrentStep") !== null;- const isReturningUser =- !onboardingCompleted && isSignedIn && !isGracePeriodOnly && !onboardingInProgress;- if (isReturningUser) {- localStorage.setItem("onboardingCompleted", "true");- }-- const resolved = localStorage.getItem("onboardingCompleted") === "true";-- if (isControlPanel) {- if (!resolved) {- setShowOnboarding(true);- } else if (!isSignedIn && !authSkipped) {- setNeedsReauth(true);- }- // Otherwise: returning user with auth — go straight to ControlPanel.- // Permissions are checked at point-of-use (recording, device enumeration).- }-- if (isDictationPanel && !resolved) {- const rawStep = parseInt(localStorage.getItem("onboardingCurrentStep") || "0");- const currentStep = Math.max(0, Math.min(rawStep, 5));- if (currentStep < 4) {- window.electronAPI?.hideWindow?.();- }- }-- setIsLoading(false);- }, [isControlPanel, isDictationPanel, isSignedIn, isGracePeriodOnly, authLoaded]);-- const handleOnboardingComplete = () => {- setShowOnboarding(false);- localStorage.setItem("onboardingCompleted", "true");- };-- if (isAgentPanel) {- return (- <Suspense fallback={<LoadingFallback />}>- <AgentOverlay />- </Suspense>- );- }-- if (isLoading) {- return <LoadingFallback />;- }-- // First-time user: full onboarding wizard- if (isControlPanel && showOnboarding) {- return (- <Suspense fallback={<LoadingFallback />}>- <OnboardingFlow onComplete={handleOnboardingComplete} />- </Suspense>- );- }-- // Returning user needs to re-authenticate (signed out, setup already done)- if (isControlPanel && needsReauth) {- return (- <div- className="h-screen flex flex-col bg-background"- style={{ paddingTop: "env(safe-area-inset-top, 0px)" }}- >- <div- className="flex items-center justify-end w-full h-10 shrink-0"- style={{ WebkitAppRegion: "drag" }}- >- {window.electronAPI?.getPlatform?.() !== "darwin" && (- <div className="pr-1" style={{ WebkitAppRegion: "no-drag" }}>- <WindowControls />- </div>- )}- </div>- <div className="flex-1 px-6 overflow-y-auto flex items-center">- <div className="w-full max-w-sm mx-auto">- <Card className="bg-card/90 backdrop-blur-2xl border border-border/50 dark:border-white/5 shadow-lg rounded-xl overflow-hidden">- <CardContent className="p-6">- <AuthenticationStep- onContinueWithoutAccount={() => {- localStorage.setItem("authenticationSkipped", "true");- localStorage.setItem("skipAuth", "true");- setNeedsReauth(false);- }}- onAuthComplete={() => setNeedsReauth(false)}- onNeedsVerification={() => {}}- />- </CardContent>- </Card>- </div>- </div>- </div>- );- }-- return isControlPanel ? (- <Suspense fallback={<LoadingFallback />}>- <ControlPanel />- </Suspense>- ) : (- <App />- );-}--function LoadingFallback({ message }) {- const { t } = useTranslation();- const fallbackMessage = message || t("common.loading");-- return (- <div className="min-h-screen bg-background flex items-center justify-center">- <div className="flex flex-col items-center gap-4 animate-[scale-in_300ms_ease-out]">- <svg- viewBox="0 0 1024 1024"- className="w-12 h-12 drop-shadow-[0_2px_8px_rgba(37,99,235,0.18)] dark:drop-shadow-[0_2px_12px_rgba(100,149,237,0.25)]"- aria-label="OpenWhispr"- >- <rect width="1024" height="1024" rx="241" fill="#2056DF" />- <circle cx="512" cy="512" r="314" fill="#2056DF" stroke="white" strokeWidth="74" />- <path d="M512 383V641" stroke="white" strokeWidth="74" strokeLinecap="round" />- <path d="M627 457V568" stroke="white" strokeWidth="74" strokeLinecap="round" />- <path d="M397 457V568" stroke="white" strokeWidth="74" strokeLinecap="round" />- </svg>- <div className="w-7 h-7 rounded-full border-[2.5px] border-transparent border-t-primary animate-[spinner-rotate_0.8s_cubic-bezier(0.4,0,0.2,1)_infinite] motion-reduce:animate-none motion-reduce:border-t-muted-foreground motion-reduce:opacity-50" />- {fallbackMessage && (- <p className="text-[13px] font-medium text-muted-foreground dark:text-foreground/60 tracking-[-0.01em]">- {fallbackMessage}- </p>- )}- </div>- </div>- );-}-function mountApp() {if (!root) {root = ReactDOM.createRoot(document.getElementById("root"));