Skip to content

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

refactor: major omboarding and settings refactor

Gabriel Steind222ea0d2e1d
diff --git a/src/components/OnboardingFlow.tsx b/src/components/OnboardingFlow.tsx
index b50e3e267..98d0dcefe 100644
--- a/src/components/OnboardingFlow.tsx
+++ b/src/components/OnboardingFlow.tsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react";
-import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";
+import { Card, CardContent } from "./ui/card";
import { Button } from "./ui/button";
import { Input } from "./ui/input";
import {
@@ -10,95 +10,27 @@ import {
Mic,
Download,
Key,
- Zap,
- RefreshCw,
- Trash2,
- Cloud,
Shield,
Keyboard,
TestTube,
Sparkles,
Globe,
- Lock,
- Play,
- ArrowRight,
X,
} from "lucide-react";
import TitleBar from "./TitleBar";
import WhisperModelPicker from "./WhisperModelPicker";
+import ProcessingModeSelector from "./ui/ProcessingModeSelector";
+import ApiKeyInput from "./ui/ApiKeyInput";
+import PermissionCard from "./ui/PermissionCard";
+import StepProgress from "./ui/StepProgress";
+import { useWhisper } from "../hooks/useWhisper";
+import { usePermissions } from "../hooks/usePermissions";
+import { useClipboard } from "../hooks/useClipboard";
+import type { TranscriptionItem, ElectronAPI } from "../types/electron";
-// Type declaration for electronAPI
declare global {
interface Window {
- electronAPI: {
- pasteText: (text: string) => Promise<void>;
- hideWindow: () => Promise<void>;
- showDictationPanel?: () => Promise<void>;
- onToggleDictation: (callback: () => void) => void;
- saveTranscription: (text: string) => Promise<{ id: number; success: boolean }>;
- getTranscriptions: (limit?: number) => Promise<any[]>;
- clearTranscriptions: () => Promise<{ cleared: number; success: boolean }>;
- deleteTranscription: (id: number) => Promise<{ success: boolean }>;
- getOpenAIKey: () => Promise<string>;
- saveOpenAIKey: (key: string) => Promise<{ success: boolean }>;
- readClipboard: () => Promise<string>;
- createProductionEnvFile: (key: string) => Promise<void>;
- transcribeLocalWhisper: (audioBlob: Blob, options?: any) => Promise<any>;
- checkWhisperInstallation: () => Promise<{
- installed: boolean;
- working: boolean;
- error?: string;
- }>;
- installWhisper: () => Promise<{
- success: boolean;
- message: string;
- output: string;
- }>;
- onWhisperInstallProgress: (
- callback: (event: any, data: { type: string; message: string; output?: string }) => void
- ) => void;
- downloadWhisperModel: (modelName: string) => Promise<{
- success: boolean;
- model: string;
- downloaded: boolean;
- size_mb?: number;
- error?: string;
- }>;
- onWhisperDownloadProgress: (
- callback: (event: any, data: {
- type: string;
- model: string;
- percentage?: number;
- downloaded_bytes?: number;
- total_bytes?: number;
- error?: string;
- result?: any;
- }) => void
- ) => void;
- checkModelStatus: (modelName: string) => Promise<{
- success: boolean;
- model: string;
- downloaded: boolean;
- size_mb?: number;
- error?: string;
- }>;
- listWhisperModels: () => Promise<{
- success: boolean;
- models: Array<{ model: string; downloaded: boolean; size_mb?: number }>;
- cache_dir: string;
- }>;
- deleteWhisperModel: (modelName: string) => Promise<{
- success: boolean;
- model: string;
- deleted: boolean;
- freed_mb?: number;
- error?: string;
- }>;
- windowMinimize: () => Promise<void>;
- windowMaximize: () => Promise<void>;
- windowClose: () => Promise<void>;
- windowIsMaximized: () => Promise<boolean>;
- };
+ electronAPI: ElectronAPI;
}
}
@@ -109,25 +41,27 @@ interface OnboardingFlowProps {
export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
const [currentStep, setCurrentStep] = useState(() => {
// Load the current step from localStorage on component mount
- const savedStep = localStorage.getItem('onboardingCurrentStep');
+ const savedStep = localStorage.getItem("onboardingCurrentStep");
return savedStep ? parseInt(savedStep, 10) : 0;
});
const [useLocalWhisper, setUseLocalWhisper] = useState(false);
const [apiKey, setApiKey] = useState("");
const [whisperModel, setWhisperModel] = useState("base");
const [hotkey, setHotkey] = useState("`");
- const [whisperInstalled, setWhisperInstalled] = useState(false);
- const [installingWhisper, setInstallingWhisper] = useState(false);
- const [installProgress, setInstallProgress] = useState("");
- const [micPermissionGranted, setMicPermissionGranted] = useState(false);
- const [accessibilityPermissionGranted, setAccessibilityPermissionGranted] = useState(false);
const [practiceText, setPracticeText] = useState("");
const [isRecording, setIsRecording] = useState(false);
const [isProcessing, setIsProcessing] = useState(false);
const [recordingBlob, setRecordingBlob] = useState<Blob | null>(null);
- const [mediaRecorder, setMediaRecorder] = useState<MediaRecorder | null>(null);
+ const [mediaRecorder, setMediaRecorder] = useState<MediaRecorder | null>(
+ null
+ );
const [audioChunks, setAudioChunks] = useState<Blob[]>([]);
+ // Use our custom hooks
+ const whisperHook = useWhisper();
+ const permissionsHook = usePermissions();
+ const { pasteFromClipboard } = useClipboard();
+
const steps = [
{ title: "Welcome", icon: Sparkles },
{ title: "Choose Mode", icon: Globe },
@@ -140,16 +74,13 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
useEffect(() => {
// Set up progress listeners
- window.electronAPI.onWhisperInstallProgress((event, data) => {
- setInstallProgress(data.message);
- });
-
-// No longer needed - WhisperModelPicker handles its own progress
- }, [useLocalWhisper]);
+ whisperHook.setupProgressListener();
+ }, [whisperHook]);
// Add hotkey listener for practice step and manage dictation panel visibility
useEffect(() => {
- if (currentStep === 5) { // Practice step
+ if (currentStep === 5) {
+ // Practice step
// Show dictation panel when reaching test step
const showDictationPanel = () => {
// Create a new window for dictation panel or bring it to front
@@ -158,9 +89,9 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
window.electronAPI.showDictationPanel();
}
};
-
+
showDictationPanel();
-
+
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === hotkey && !event.repeat) {
event.preventDefault();
@@ -172,103 +103,64 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
}
};
- window.addEventListener('keydown', handleKeyDown);
- return () => window.removeEventListener('keydown', handleKeyDown);
+ window.addEventListener("keydown", handleKeyDown);
+ return () => window.removeEventListener("keydown", handleKeyDown);
}
}, [currentStep, hotkey, isRecording, isProcessing]);
- const checkWhisperInstallation = async () => {
- try {
- const result = await window.electronAPI.checkWhisperInstallation();
- setWhisperInstalled(result.installed && result.working);
- } catch (error) {
- setWhisperInstalled(false);
- }
- };
-
- const installWhisper = async () => {
- try {
- setInstallingWhisper(true);
- setInstallProgress("Starting Whisper installation...");
-
- const result = await window.electronAPI.installWhisper();
-
- if (result.success) {
- setWhisperInstalled(true);
- setInstallProgress("Installation complete!");
- } else {
- alert(`❌ Failed to install Whisper: ${result.message}`);
- }
- } catch (error) {
- alert(`❌ Failed to install Whisper: ${error}`);
- } finally {
- setInstallingWhisper(false);
- setInstallProgress("");
- }
- };
-
- const requestMicPermission = async () => {
- try {
- await navigator.mediaDevices.getUserMedia({ audio: true });
- setMicPermissionGranted(true);
- } catch (err) {
- alert("Please grant microphone permissions to use voice dictation.");
- }
- };
+ // Remove individual functions - now using hooks
- const testAccessibilityPermission = async () => {
- try {
- await window.electronAPI.pasteText("OpenWispr accessibility test");
- setAccessibilityPermissionGranted(true);
- alert("✅ Accessibility permissions working! Check if the test text appeared in another app.");
- } catch (err) {
- alert("❌ Accessibility permissions needed! Please grant them in System Settings.");
- }
- };
+ // Permission functions now handled by hooks
const startPracticeRecording = async () => {
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const recorder = new MediaRecorder(stream);
const chunks: Blob[] = [];
-
+
recorder.ondataavailable = (event) => {
chunks.push(event.data);
};
-
+
recorder.onstop = async () => {
- const blob = new Blob(chunks, { type: 'audio/wav' });
+ const blob = new Blob(chunks, { type: "audio/wav" });
setRecordingBlob(blob);
setIsProcessing(true);
-
+
// Process the audio
try {
let result;
if (useLocalWhisper) {
- result = await window.electronAPI.transcribeLocalWhisper(blob, { model: whisperModel });
+ result = await window.electronAPI.transcribeLocalWhisper(blob, {
+ model: whisperModel,
+ });
} else {
// For demo purposes, we'll use a simple OpenAI API call
const formData = new FormData();
- formData.append('file', blob, 'audio.wav');
- formData.append('model', 'whisper-1');
-
- const response = await fetch('https://api.openai.com/v1/audio/transcriptions', {
- method: 'POST',
- headers: {
- 'Authorization': `Bearer ${apiKey}`
- },
- body: formData
- });
-
+ formData.append("file", blob, "audio.wav");
+ formData.append("model", "whisper-1");
+
+ const response = await fetch(
+ "https://api.openai.com/v1/audio/transcriptions",
+ {
+ method: "POST",
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ },
+ body: formData,
+ }
+ );
+
if (response.ok) {
result = await response.json();
} else {
- throw new Error('Transcription failed');
+ throw new Error("Transcription failed");
}
}
-
+
if (result.text || result.success) {
- const text = result.text || result.transcript || "Transcription successful!";
+ const text =
+ result.text || result.transcript || "Transcription successful!";
setPracticeText(text);
// Test paste functionality
await window.electronAPI.pasteText(text);
@@ -277,10 +169,10 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
alert("Transcription failed. Please try again.");
} finally {
setIsProcessing(false);
- stream.getTracks().forEach(track => track.stop());
+ stream.getTracks().forEach((track) => track.stop());
}
};
-
+
setMediaRecorder(recorder);
setAudioChunks(chunks);
recorder.start();
@@ -302,10 +194,16 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
localStorage.setItem("useLocalWhisper", useLocalWhisper.toString());
localStorage.setItem("whisperModel", whisperModel);
localStorage.setItem("dictationKey", hotkey);
- localStorage.setItem("micPermissionGranted", micPermissionGranted.toString());
- localStorage.setItem("accessibilityPermissionGranted", accessibilityPermissionGranted.toString());
+ localStorage.setItem(
+ "micPermissionGranted",
+ permissionsHook.micPermissionGranted.toString()
+ );
+ localStorage.setItem(
+ "accessibilityPermissionGranted",
+ permissionsHook.accessibilityPermissionGranted.toString()
+ );
localStorage.setItem("onboardingCompleted", "true");
-
+
if (!useLocalWhisper && apiKey) {
await window.electronAPI.saveOpenAIKey(apiKey);
localStorage.setItem("openaiApiKey", apiKey);
@@ -316,7 +214,7 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
if (currentStep < steps.length - 1) {
const newStep = currentStep + 1;
setCurrentStep(newStep);
- localStorage.setItem('onboardingCurrentStep', newStep.toString());
+ localStorage.setItem("onboardingCurrentStep", newStep.toString());
}
};
@@ -324,14 +222,14 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
if (currentStep > 0) {
const newStep = currentStep - 1;
setCurrentStep(newStep);
- localStorage.setItem('onboardingCurrentStep', newStep.toString());
+ localStorage.setItem("onboardingCurrentStep", newStep.toString());
}
};
const finishOnboarding = async () => {
await saveSettings();
// Clear the onboarding step since we're done
- localStorage.removeItem('onboardingCurrentStep');
+ localStorage.removeItem("onboardingCurrentStep");
onComplete();
};
@@ -339,20 +237,36 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
switch (currentStep) {
case 0: // Welcome
return (
- <div className="text-center space-y-6" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <div
+ className="text-center space-y-6"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
<div className="w-16 h-16 mx-auto bg-blue-100 rounded-full flex items-center justify-center">
<Sparkles className="w-8 h-8 text-blue-600" />
</div>
<div>
- <h2 className="text-2xl font-bold text-stone-900 mb-2" style={{ fontFamily: 'Noto Sans, sans-serif' }}>Welcome to OpenWispr</h2>
- <p className="text-stone-600" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <h2
+ className="text-2xl font-bold text-stone-900 mb-2"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
+ Welcome to OpenWispr
+ </h2>
+ <p
+ className="text-stone-600"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
Let's set up your voice dictation in just a few simple steps.
</p>
</div>
<div className="bg-blue-50/50 p-4 rounded-lg border border-blue-200/60">
- <p className="text-sm text-blue-800" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
- 🎤 Turn your voice into text instantly<br />
- ⚡ Works anywhere on your computer<br />
+ <p
+ className="text-sm text-blue-800"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
+ 🎤 Turn your voice into text instantly
+ <br />
+ ⚡ Works anywhere on your computer
+ <br />
🔒 Your privacy is protected
</p>
</div>
@@ -361,73 +275,29 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
case 1: // Choose Mode
return (
- <div className="space-y-6" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <div
+ className="space-y-6"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
<div className="text-center">
- <h2 className="text-2xl font-bold text-stone-900 mb-2" style={{ fontFamily: 'Noto Sans, sans-serif' }}>Choose Your Processing Mode</h2>
- <p className="text-stone-600" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
- How would you like to convert your speech to text?
- </p>
- </div>
-
- <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
- <button
- onClick={() => setUseLocalWhisper(false)}
- className={`p-6 border-2 rounded-xl text-left transition-all cursor-pointer ${
- !useLocalWhisper
- ? "border-blue-500 bg-blue-50/50 shadow-md"
- : "border-stone-200 bg-white hover:border-stone-300 hover:shadow-sm"
- }`}
- style={{ fontFamily: 'Noto Sans, sans-serif' }}
+ <h2
+ className="text-2xl font-bold text-stone-900 mb-2"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
>
- <div className="flex items-center justify-between mb-3">
- <div className="flex items-center gap-3">
- <Cloud className="w-6 h-6 text-blue-600" />
- <h3 className="font-semibold text-stone-900">Cloud Processing</h3>
- </div>
- <span className="text-xs text-green-600 bg-green-100 px-2 py-1 rounded-full">
- Fastest
- </span>
- </div>
- <p className="text-sm text-stone-600 mb-3">
- Uses OpenAI's servers for lightning-fast transcription
- </p>
- <div className="text-xs text-stone-500">
- ✓ Fastest processing<br />
- ✓ Best accuracy<br />
- • Requires internet<br />
- • Needs API key
- </div>
- </button>
-
- <button
- onClick={() => setUseLocalWhisper(true)}
- className={`p-6 border-2 rounded-xl text-left transition-all cursor-pointer ${
- useLocalWhisper
- ? "border-blue-500 bg-blue-50/50 shadow-md"
- : "border-stone-200 bg-white hover:border-stone-300 hover:shadow-sm"
- }`}
- style={{ fontFamily: 'Noto Sans, sans-serif' }}
+ Choose Your Processing Mode
+ </h2>
+ <p
+ className="text-stone-600"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
>
- <div className="flex items-center justify-between mb-3">
- <div className="flex items-center gap-3">
- <Lock className="w-6 h-6 text-blue-600" />
- <h3 className="font-semibold text-stone-900">Local Processing</h3>
- </div>
- <span className="text-xs text-blue-600 bg-blue-100 px-2 py-1 rounded-full">
- Private
- </span>
- </div>
- <p className="text-sm text-stone-600 mb-3">
- Processes everything on your device for complete privacy
- </p>
- <div className="text-xs text-stone-500">
- ✓ Complete privacy<br />
- ✓ Works offline<br />
- ✓ No monthly costs<br />
- • Slower processing
- </div>
- </button>
+ How would you like to convert your speech to text?
+ </p>
</div>
+
+ <ProcessingModeSelector
+ useLocalWhisper={useLocalWhisper}
+ setUseLocalWhisper={setUseLocalWhisper}
+ />
</div>
);
@@ -436,38 +306,45 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
<div className="space-y-6">
<div className="text-center">
<h2 className="text-2xl font-bold text-gray-900 mb-2">
- {useLocalWhisper ? "Local Processing Setup" : "Cloud Processing Setup"}
+ {useLocalWhisper
+ ? "Local Processing Setup"
+ : "Cloud Processing Setup"}
</h2>
<p className="text-gray-600">
- {useLocalWhisper
- ? "Let's install and configure Whisper on your device"
+ {useLocalWhisper
+ ? "Let's install and configure Whisper on your device"
: "Enter your OpenAI API key to get started"}
</p>
</div>
{useLocalWhisper ? (
<div className="space-y-4">
- {!whisperInstalled ? (
+ {!whisperHook.whisperInstalled ? (
<div className="text-center space-y-4">
<div className="w-16 h-16 mx-auto bg-purple-100 rounded-full flex items-center justify-center">
<Download className="w-8 h-8 text-purple-600" />
</div>
<div>
- <h3 className="font-semibold text-gray-900 mb-2">Install Whisper</h3>
+ <h3 className="font-semibold text-gray-900 mb-2">
+ Install Whisper
+ </h3>
<p className="text-sm text-gray-600 mb-4">
- We'll automatically install Whisper for you. No technical setup required.
+ We'll automatically install Whisper for you. No
+ technical setup required.
</p>
</div>
-
- {installingWhisper ? (
+
+ {whisperHook.installingWhisper ? (
<div className="bg-purple-50 p-4 rounded-lg">
<div className="flex items-center justify-center gap-3 mb-3">
<div className="animate-spin rounded-full h-5 w-5 border-b-2 border-purple-600"></div>
- <span className="font-medium text-purple-900">Installing...</span>
+ <span className="font-medium text-purple-900">
+ Installing...
+ </span>
</div>
- {installProgress && (
+ {whisperHook.installProgress && (
<div className="text-xs text-purple-600 bg-white p-2 rounded font-mono">
- {installProgress}
+ {whisperHook.installProgress}
</div>
)}
<p className="text-xs text-purple-600 mt-2">
@@ -476,12 +353,15 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
</div>
) : (
<div className="space-y-3">
- <Button onClick={installWhisper} className="w-full">
+ <Button
+ onClick={whisperHook.installWhisper}
+ className="w-full"
+ >
Install Whisper
</Button>
- <Button
- onClick={checkWhisperInstallation}
- variant="outline"
+ <Button
+ onClick={whisperHook.checkWhisperInstallation}
+ variant="outline"
size="sm"
className="w-full"
>
@@ -496,10 +376,14 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
<div className="w-16 h-16 mx-auto bg-green-100 rounded-full flex items-center justify-center mb-4">
<Check className="w-8 h-8 text-green-600" />
</div>
- <h3 className="font-semibold text-green-900 mb-2">Whisper Installed!</h3>
- <p className="text-sm text-gray-600">Now choose your model quality:</p>
+ <h3 className="font-semibold text-green-900 mb-2">
+ Whisper Installed!
+ </h3>
+ <p className="text-sm text-gray-600">
+ Now choose your model quality:
+ </p>
</div>
-
+
<div>
<label className="block text-sm font-medium text-gray-700 mb-3">
Choose your model quality below
@@ -524,42 +408,18 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
<Key className="w-8 h-8 text-blue-600" />
</div>
</div>
-
- <div>
- <label className="block text-sm font-medium text-gray-700 mb-2">
- OpenAI API Key
- </label>
- <div className="flex gap-3">
- <Input
- type="password"
- placeholder="sk-..."
- value={apiKey}
- onChange={(e) => setApiKey(e.target.value)}
- className="flex-1"
- />
- <Button
- variant="outline"
- onClick={async () => {
- try {
- const text = await window.electronAPI.readClipboard();
- if (text && text.trim()) {
- setApiKey(text.trim());
- }
- } catch (err) {
- alert("Could not paste from clipboard.");
- }
- }}
- >
- Paste
- </Button>
- </div>
- <p className="text-xs text-gray-500 mt-2">
- Get your API key from <strong>platform.openai.com</strong>
- </p>
- </div>
+
+ <ApiKeyInput
+ apiKey={apiKey}
+ setApiKey={setApiKey}
+ label="OpenAI API Key"
+ helpText="Get your API key from platform.openai.com"
+ />
<div className="bg-blue-50 p-4 rounded-lg">
- <h4 className="font-medium text-blue-900 mb-2">How to get your API key:</h4>
+ <h4 className="font-medium text-blue-900 mb-2">
+ How to get your API key:
+ </h4>
<ol className="text-sm text-blue-800 space-y-1">
<li>1. Go to platform.openai.com</li>
<li>2. Sign in to your account</li>
@@ -577,61 +437,43 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
return (
<div className="space-y-6">
<div className="text-center">
- <h2 className="text-2xl font-bold text-gray-900 mb-2">Grant Permissions</h2>
+ <h2 className="text-2xl font-bold text-gray-900 mb-2">
+ Grant Permissions
+ </h2>
<p className="text-gray-600">
OpenWispr needs a couple of permissions to work properly
</p>
</div>
<div className="space-y-4">
- <div className="border rounded-lg p-4">
- <div className="flex items-center justify-between mb-3">
- <div className="flex items-center gap-3">
- <Mic className="w-6 h-6 text-indigo-600" />
- <div>
- <h3 className="font-semibold text-gray-900">Microphone Access</h3>
- <p className="text-sm text-gray-600">Required to record your voice</p>
- </div>
- </div>
- {micPermissionGranted ? (
- <div className="text-green-600">
- <Check className="w-5 h-5" />
- </div>
- ) : (
- <Button onClick={requestMicPermission} size="sm">
- Grant Access
- </Button>
- )}
- </div>
- </div>
-
- <div className="border rounded-lg p-4">
- <div className="flex items-center justify-between mb-3">
- <div className="flex items-center gap-3">
- <Shield className="w-6 h-6 text-indigo-600" />
- <div>
- <h3 className="font-semibold text-gray-900">Accessibility Permission</h3>
- <p className="text-sm text-gray-600">Required to paste text automatically</p>
- </div>
- </div>
- {accessibilityPermissionGranted ? (
- <div className="text-green-600">
- <Check className="w-5 h-5" />
- </div>
- ) : (
- <Button onClick={testAccessibilityPermission} size="sm">
- Test & Grant
- </Button>
- )}
- </div>
- </div>
+ <PermissionCard
+ icon={Mic}
+ title="Microphone Access"
+ description="Required to record your voice"
+ granted={permissionsHook.micPermissionGranted}
+ onRequest={permissionsHook.requestMicPermission}
+ buttonText="Grant Access"
+ />
+
+ <PermissionCard
+ icon={Shield}
+ title="Accessibility Permission"
+ description="Required to paste text automatically"
+ granted={permissionsHook.accessibilityPermissionGranted}
+ onRequest={permissionsHook.testAccessibilityPermission}
+ buttonText="Test & Grant"
+ />
</div>
<div className="bg-amber-50 p-4 rounded-lg">
- <h4 className="font-medium text-amber-900 mb-2">🔒 Privacy Note</h4>
+ <h4 className="font-medium text-amber-900 mb-2">
+ 🔒 Privacy Note
+ </h4>
<p className="text-sm text-amber-800">
- OpenWispr only uses these permissions for dictation.
- {useLocalWhisper ? " With local processing, your voice never leaves your device." : " Your voice is sent to OpenAI's servers for transcription."}
+ OpenWispr only uses these permissions for dictation.
+ {useLocalWhisper
+ ? " With local processing, your voice never leaves your device."
+ : " Your voice is sent to OpenAI's servers for transcription."}
</p>
</div>
</div>
@@ -641,7 +483,9 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
return (
<div className="space-y-6">
<div className="text-center">
- <h2 className="text-2xl font-bold text-gray-900 mb-2">Choose Your Hotkey</h2>
+ <h2 className="text-2xl font-bold text-gray-900 mb-2">
+ Choose Your Hotkey
+ </h2>
<p className="text-gray-600">
Select which key you want to press to start/stop dictation
</p>
@@ -664,16 +508,18 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
</div>
<div className="bg-gray-50 p-4 rounded-lg">
- <h4 className="font-medium text-gray-900 mb-3">Popular Choices:</h4>
+ <h4 className="font-medium text-gray-900 mb-3">
+ Popular Choices:
+ </h4>
<div className="grid grid-cols-2 gap-2">
- {['`', 'F1', 'F2', 'F3', 'F4'].map((key) => (
+ {["`", "F1", "F2", "F3", "F4"].map((key) => (
<button
key={key}
onClick={() => setHotkey(key)}
className={`p-2 text-sm font-mono rounded border transition-all ${
- hotkey === key
- ? 'border-indigo-500 bg-indigo-50 text-indigo-700'
- : 'border-gray-200 bg-white hover:border-gray-300'
+ hotkey === key
+ ? "border-indigo-500 bg-indigo-50 text-indigo-700"
+ : "border-gray-200 bg-white hover:border-gray-300"
}`}
>
{key}
@@ -687,50 +533,100 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
case 5: // Test & Practice
return (
- <div className="space-y-6" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <div
+ className="space-y-6"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
<div className="text-center">
- <h2 className="text-2xl font-bold text-stone-900 mb-2" style={{ fontFamily: 'Noto Sans, sans-serif' }}>Test & Practice</h2>
- <p className="text-stone-600" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <h2
+ className="text-2xl font-bold text-stone-900 mb-2"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
+ Test & Practice
+ </h2>
+ <p
+ className="text-stone-600"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
Let's test your setup and practice using OpenWispr
</p>
</div>
<div className="space-y-6">
<div className="bg-blue-50/50 p-6 rounded-lg border border-blue-200/60">
- <h3 className="font-semibold text-blue-900 mb-3" style={{ fontFamily: 'Noto Sans, sans-serif' }}>Practice with Your Hotkey</h3>
- <p className="text-sm text-blue-800 mb-4" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
- Press <kbd className="bg-white px-2 py-1 rounded text-xs font-mono border border-blue-200">{hotkey}</kbd> to start recording, then speak something. Press <kbd className="bg-white px-2 py-1 rounded text-xs font-mono border border-blue-200">{hotkey}</kbd> again to stop and paste the text below.
+ <h3
+ className="font-semibold text-blue-900 mb-3"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
+ Practice with Your Hotkey
+ </h3>
+ <p
+ className="text-sm text-blue-800 mb-4"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
+ Press{" "}
+ <kbd className="bg-white px-2 py-1 rounded text-xs font-mono border border-blue-200">
+ {hotkey}
+ </kbd>{" "}
+ to start recording, then speak something. Press{" "}
+ <kbd className="bg-white px-2 py-1 rounded text-xs font-mono border border-blue-200">
+ {hotkey}
+ </kbd>{" "}
+ again to stop and paste the text below.
</p>
-
+
<div className="space-y-4">
<div className="text-center">
{isRecording ? (
<div className="flex items-center justify-center gap-2 text-red-600">
<div className="animate-pulse w-3 h-3 bg-red-500 rounded-full"></div>
- <span className="font-medium" style={{ fontFamily: 'Noto Sans, sans-serif' }}>Recording... Press <kbd className="bg-white px-1 py-0.5 rounded text-xs font-mono border">{hotkey}</kbd> to stop</span>
+ <span
+ className="font-medium"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
+ Recording... Press{" "}
+ <kbd className="bg-white px-1 py-0.5 rounded text-xs font-mono border">
+ {hotkey}
+ </kbd>{" "}
+ to stop
+ </span>
</div>
) : isProcessing ? (
<div className="flex items-center justify-center gap-2 text-purple-600">
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-purple-600"></div>
- <span className="font-medium" style={{ fontFamily: 'Noto Sans, sans-serif' }}>Processing transcription...</span>
+ <span
+ className="font-medium"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
+ Processing transcription...
+ </span>
</div>
) : (
<div className="flex items-center justify-center gap-2 text-stone-600">
<Mic className="w-4 h-4" />
- <span style={{ fontFamily: 'Noto Sans, sans-serif' }}>Press <kbd className="bg-white px-1 py-0.5 rounded text-xs font-mono border">{hotkey}</kbd> to start recording</span>
+ <span style={{ fontFamily: "Noto Sans, sans-serif" }}>
+ Press{" "}
+ <kbd className="bg-white px-1 py-0.5 rounded text-xs font-mono border">
+ {hotkey}
+ </kbd>{" "}
+ to start recording
+ </span>
</div>
)}
</div>
-
+
<div>
- <label className="block text-sm font-medium text-stone-700 mb-2" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <label
+ className="block text-sm font-medium text-stone-700 mb-2"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
Transcribed Text:
</label>
<textarea
value={practiceText}
onChange={(e) => setPracticeText(e.target.value)}
className="w-full p-3 border border-stone-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white"
- style={{ fontFamily: 'Noto Sans, sans-serif' }}
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
rows={4}
placeholder="Your transcribed text will appear here after recording..."
/>
@@ -739,13 +635,36 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
</div>
<div className="bg-green-50/50 p-4 rounded-lg border border-green-200/60">
- <h4 className="font-medium text-green-900 mb-2" style={{ fontFamily: 'Noto Sans, sans-serif' }}>💡 How to use OpenWispr:</h4>
- <ol className="text-sm text-green-800 space-y-1" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <h4
+ className="font-medium text-green-900 mb-2"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
+ 💡 How to use OpenWispr:
+ </h4>
+ <ol
+ className="text-sm text-green-800 space-y-1"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
<li>1. Click in any text field (email, document, etc.)</li>
- <li>2. Press <kbd className="bg-white px-2 py-1 rounded text-xs font-mono border border-green-200">{hotkey}</kbd> to start recording</li>
+ <li>
+ 2. Press{" "}
+ <kbd className="bg-white px-2 py-1 rounded text-xs font-mono border border-green-200">
+ {hotkey}
+ </kbd>{" "}
+ to start recording
+ </li>
<li>3. Speak your text clearly</li>
- <li>4. Press <kbd className="bg-white px-2 py-1 rounded text-xs font-mono border border-green-200">{hotkey}</kbd> again to stop</li>
- <li>5. Your text will automatically appear where you were typing!</li>
+ <li>
+ 4. Press{" "}
+ <kbd className="bg-white px-2 py-1 rounded text-xs font-mono border border-green-200">
+ {hotkey}
+ </kbd>{" "}
+ again to stop
+ </li>
+ <li>
+ 5. Your text will automatically appear where you were
+ typing!
+ </li>
</ol>
</div>
</div>
@@ -759,29 +678,40 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
<Check className="w-8 h-8 text-green-600" />
</div>
<div>
- <h2 className="text-2xl font-bold text-gray-900 mb-2">You're All Set!</h2>
+ <h2 className="text-2xl font-bold text-gray-900 mb-2">
+ You're All Set!
+ </h2>
<p className="text-gray-600">
OpenWispr is now configured and ready to use.
</p>
</div>
-
+
<div className="bg-gradient-to-r from-indigo-50 to-purple-50 p-6 rounded-lg">
- <h3 className="font-semibold text-gray-900 mb-3">Your Setup Summary:</h3>
+ <h3 className="font-semibold text-gray-900 mb-3">
+ Your Setup Summary:
+ </h3>
<div className="space-y-2 text-sm">
<div className="flex justify-between">
<span>Processing:</span>
<span className="font-medium">
- {useLocalWhisper ? `Local (${whisperModel})` : 'OpenAI Cloud'}
+ {useLocalWhisper
+ ? `Local (${whisperModel})`
+ : "OpenAI Cloud"}
</span>
</div>
<div className="flex justify-between">
<span>Hotkey:</span>
- <kbd className="bg-white px-2 py-1 rounded text-xs font-mono">{hotkey}</kbd>
+ <kbd className="bg-white px-2 py-1 rounded text-xs font-mono">
+ {hotkey}
+ </kbd>
</div>
<div className="flex justify-between">
<span>Permissions:</span>
<span className="font-medium text-green-600">
- {micPermissionGranted && accessibilityPermissionGranted ? '✓ Granted' : '⚠ Review needed'}
+ {permissionsHook.micPermissionGranted &&
+ permissionsHook.accessibilityPermissionGranted
+ ? "✓ Granted"
+ : "⚠ Review needed"}
</span>
</div>
</div>
@@ -789,7 +719,8 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
<div className="bg-blue-50 p-4 rounded-lg">
<p className="text-sm text-blue-800">
- <strong>Pro tip:</strong> You can always change these settings later in the Control Panel.
+ <strong>Pro tip:</strong> You can always change these settings
+ later in the Control Panel.
</p>
</div>
</div>
@@ -802,27 +733,38 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
const canProceed = () => {
switch (currentStep) {
- case 0: return true;
- case 1: return true; // Mode selection
-case 2:
+ case 0:
+ return true;
+ case 1:
+ return true; // Mode selection
+ case 2:
if (useLocalWhisper) {
- return whisperInstalled;
+ return whisperHook.whisperInstalled;
} else {
- return apiKey.trim() !== '';
+ return apiKey.trim() !== "";
}
- case 3: return micPermissionGranted && accessibilityPermissionGranted;
- case 4: return hotkey.trim() !== '';
- case 5: return practiceText.trim() !== '';
- case 6: return true;
- default: return false;
+ case 3:
+ return (
+ permissionsHook.micPermissionGranted &&
+ permissionsHook.accessibilityPermissionGranted
+ );
+ case 4:
+ return hotkey.trim() !== "";
+ case 5:
+ return practiceText.trim() !== "";
+ case 6:
+ return true;
+ default:
+ return false;
}
};
// Load Google Font only in the browser
React.useEffect(() => {
- const link = document.createElement('link');
- link.href = 'https://fonts.googleapis.com/css2?family=Noto+Sans:wght@300;400;500;600;700&display=swap';
- link.rel = 'stylesheet';
+ const link = document.createElement("link");
+ link.href =
+ "https://fonts.googleapis.com/css2?family=Noto+Sans:wght@300;400;500;600;700&display=swap";
+ link.rel = "stylesheet";
document.head.appendChild(link);
return () => {
document.head.removeChild(link);
@@ -830,7 +772,7 @@ case 2:
}, []);
return (
- <div
+ <div
className="h-screen flex flex-col bg-gradient-to-br from-stone-50 via-white to-blue-50/30"
style={{
backgroundImage: `repeating-linear-gradient(
@@ -839,66 +781,38 @@ case 2:
#e7e5e4 24px,
#e7e5e4 25px
)`,
- fontFamily: 'Noto Sans, sans-serif',
+ fontFamily: "Noto Sans, sans-serif",
}}
>
{/* Left margin line for entire page */}
<div className="fixed left-6 md:left-12 top-0 bottom-0 w-px bg-red-300/40 z-0"></div>
-
+
<TitleBar
title="OpenWispr Setup"
showTitle={true}
className="bg-white backdrop-blur-xl border-b border-stone-200/60 relative z-10 flex-shrink-0"
>
- <div className="text-sm text-stone-500" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <div
+ className="text-sm text-stone-500"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
Step {currentStep + 1} of {steps.length}
</div>
</TitleBar>
{/* Progress Bar */}
<div className="bg-white backdrop-blur-xl border-b border-stone-200/60 px-6 md:pl-16 md:pr-6 py-2 relative z-10 flex-shrink-0">
- <div className="flex items-center justify-between mb-2">
- {steps.map((step, index) => {
- const Icon = step.icon;
- const isActive = index === currentStep;
- const isCompleted = index < currentStep;
-
- return (
- <div key={index} className="flex items-center">
- <div className={`flex items-center gap-2 ${
- isActive ? 'text-blue-600' : isCompleted ? 'text-green-600' : 'text-stone-400'
- }`} style={{ fontFamily: 'Noto Sans, sans-serif' }}>
- <div className={`w-8 h-8 rounded-full flex items-center justify-center border-2 ${
- isActive
- ? 'border-blue-600 bg-blue-50'
- : isCompleted
- ? 'border-green-600 bg-green-50'
- : 'border-stone-300 bg-white'
- }`}>
- {isCompleted ? (
- <Check className="w-4 h-4" />
- ) : (
- <Icon className="w-4 h-4" />
- )}
- </div>
- <span className="text-xs font-medium hidden md:block">{step.title}</span>
- </div>
- {index < steps.length - 1 && (
- <div className={`w-8 h-0.5 mx-2 ${
- isCompleted ? 'bg-green-600' : 'bg-stone-300'
- }`} />
- )}
- </div>
- );
- })}
- </div>
+ <StepProgress steps={steps} currentStep={currentStep} />
</div>
{/* Content - This will grow to fill available space */}
<div className="flex-1 px-6 md:pl-16 md:pr-6 py-8 relative z-10 overflow-y-auto">
<div className="max-w-4xl mx-auto">
<Card className="bg-white backdrop-blur-xl border border-stone-200/60 shadow-sm rounded-2xl overflow-hidden">
- <CardContent className="p-8" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <CardContent
+ className="p-8"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
{renderStep()}
</CardContent>
</Card>
@@ -912,15 +826,19 @@ case 2:
onClick={prevStep}
variant="outline"
disabled={currentStep === 0}
- style={{ fontFamily: 'Noto Sans, sans-serif' }}
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
>
<ChevronLeft className="w-4 h-4 mr-2" />
Previous
</Button>
-
+
<div className="flex items-center gap-2">
{currentStep === steps.length - 1 ? (
- <Button onClick={finishOnboarding} className="bg-green-600 hover:bg-green-700" style={{ fontFamily: 'Noto Sans, sans-serif' }}>
+ <Button
+ onClick={finishOnboarding}
+ className="bg-green-600 hover:bg-green-700"
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
<Check className="w-4 h-4 mr-2" />
Finish Setup
</Button>
@@ -928,7 +846,7 @@ case 2:
<Button
onClick={nextStep}
disabled={!canProceed()}
- style={{ fontFamily: 'Noto Sans, sans-serif' }}
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
>
Next
<ChevronRight className="w-4 h-4 ml-2" />
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index 33b517a09..a3b950f22 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -8,129 +8,23 @@ import {
Settings,
Keyboard,
Info,
- Trash2,
ArrowLeft,
} from "lucide-react";
import TitleBar from "./TitleBar";
import WhisperModelPicker from "./WhisperModelPicker";
+import ProcessingModeSelector from "./ui/ProcessingModeSelector";
+import ApiKeyInput from "./ui/ApiKeyInput";
+import { useWhisper } from "../hooks/useWhisper";
+import { usePermissions } from "../hooks/usePermissions";
+import { useClipboard } from "../hooks/useClipboard";
+import type { TranscriptionItem, ElectronAPI } from "../types/electron";
-// Type declaration for electronAPI
declare global {
interface Window {
- electronAPI: {
- pasteText: (text: string) => Promise<void>;
- hideWindow: () => Promise<void>;
- onToggleDictation: (callback: () => void) => void;
- saveTranscription: (
- text: string
- ) => Promise<{ id: number; success: boolean }>;
- getTranscriptions: (limit?: number) => Promise<TranscriptionItem[]>;
- clearTranscriptions: () => Promise<{ cleared: number; success: boolean }>;
- deleteTranscription: (id: number) => Promise<{ success: boolean }>;
- getOpenAIKey: () => Promise<string>;
- saveOpenAIKey: (key: string) => Promise<{ success: boolean }>;
- readClipboard: () => Promise<string>;
- createProductionEnvFile: (key: string) => Promise<void>;
- transcribeLocalWhisper: (audioBlob: Blob, options?: any) => Promise<any>;
- checkWhisperInstallation: () => Promise<{
- installed: boolean;
- working: boolean;
- error?: string;
- }>;
- installWhisper: () => Promise<{
- success: boolean;
- message: string;
- output: string;
- }>;
- onWhisperInstallProgress: (
- callback: (
- event: any,
- data: { type: string; message: string; output?: string }
- ) => void
- ) => void;
- downloadWhisperModel: (modelName: string) => Promise<{
- success: boolean;
- model: string;
- downloaded: boolean;
- size_mb?: number;
- error?: string;
- }>;
- onWhisperDownloadProgress: (
- callback: (
- event: any,
- data: {
- type: string;
- model: string;
- percentage?: number;
- downloaded_bytes?: number;
- total_bytes?: number;
- error?: string;
- result?: any;
- }
- ) => void
- ) => void;
- checkModelStatus: (modelName: string) => Promise<{
- success: boolean;
- model: string;
- downloaded: boolean;
- size_mb?: number;
- error?: string;
- }>;
- listWhisperModels: () => Promise<{
- success: boolean;
- models: Array<{ model: string; downloaded: boolean; size_mb?: number }>;
- cache_dir: string;
- }>;
- deleteWhisperModel: (modelName: string) => Promise<{
- success: boolean;
- model: string;
- deleted: boolean;
- freed_mb?: number;
- error?: string;
- }>;
- // Window control functions
- windowMinimize: () => Promise<void>;
- windowMaximize: () => Promise<void>;
- windowClose: () => Promise<void>;
- windowIsMaximized: () => Promise<boolean>;
- // Cleanup functions
- cleanupApp: () => Promise<void>;
- // Update functions
- checkForUpdates: () => Promise<{
- updateAvailable: boolean;
- version?: string;
- releaseDate?: string;
- files?: any[];
- releaseNotes?: string;
- message?: string;
- }>;
- downloadUpdate: () => Promise<{ success: boolean; message: string }>;
- installUpdate: () => Promise<{ success: boolean; message: string }>;
- getAppVersion: () => Promise<{ version: string }>;
- getUpdateStatus: () => Promise<{
- updateAvailable: boolean;
- updateDownloaded: boolean;
- isDevelopment: boolean;
- }>;
- // Update event listeners
- onUpdateAvailable: (callback: (event: any, info: any) => void) => void;
- onUpdateNotAvailable: (callback: (event: any, info: any) => void) => void;
- onUpdateDownloaded: (callback: (event: any, info: any) => void) => void;
- onUpdateDownloadProgress: (
- callback: (event: any, progressObj: any) => void
- ) => void;
- onUpdateError: (callback: (event: any, error: any) => void) => void;
- };
+ electronAPI: ElectronAPI;
}
}
-interface TranscriptionItem {
- id: number;
- text: string;
- timestamp: string;
- created_at: string;
-}
-
interface SettingsPageProps {
onBack: () => void;
}
@@ -141,10 +35,11 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
const [useLocalWhisper, setUseLocalWhisper] = useState(false);
const [whisperModel, setWhisperModel] = useState("base");
const [allowOpenAIFallback, setAllowOpenAIFallback] = useState(false);
- const [whisperInstalled, setWhisperInstalled] = useState(false);
- const [checkingWhisper, setCheckingWhisper] = useState(false);
- const [installingWhisper, setInstallingWhisper] = useState(false);
- const [installProgress, setInstallProgress] = useState<string>("");
+
+ // Use custom hooks
+ const whisperHook = useWhisper();
+ const permissionsHook = usePermissions();
+ const { pasteFromClipboardWithFallback } = useClipboard();
// Update state
const [currentVersion, setCurrentVersion] = useState<string>("");
@@ -195,13 +90,10 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
loadApiKey();
// Check Whisper installation
- checkWhisperInstallation();
+ whisperHook.checkWhisperInstallation();
// Set up progress listener for Whisper installation
- window.electronAPI.onWhisperInstallProgress((event, data) => {
- setInstallProgress(data.message);
- });
-
+ whisperHook.setupProgressListener();
// Initialize update functionality
const initializeUpdateData = async () => {
@@ -246,41 +138,7 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
});
}, []);
- const checkWhisperInstallation = async () => {
- try {
- setCheckingWhisper(true);
- const result = await window.electronAPI.checkWhisperInstallation();
- setWhisperInstalled(result.installed && result.working);
-
- } catch (error) {
- setWhisperInstalled(false);
- } finally {
- setCheckingWhisper(false);
- }
- };
-
- const installWhisper = async () => {
- try {
- setInstallingWhisper(true);
- setInstallProgress("Starting Whisper installation...");
-
- const result = await window.electronAPI.installWhisper();
-
- if (result.success) {
- alert(
- "✅ Whisper installed successfully! You can now download and use local models."
- );
- checkWhisperInstallation();
- } else {
- alert(`❌ Failed to install Whisper: ${result.message}`);
- }
- } catch (error) {
- alert(`❌ Failed to install Whisper: ${error}`);
- } finally {
- setInstallingWhisper(false);
- setInstallProgress("");
- }
- };
+ // Whisper functions now handled by hooks
const saveKey = () => {
localStorage.setItem("dictationKey", key);
@@ -331,29 +189,7 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
);
};
- const requestPermissions = async () => {
- try {
- await navigator.mediaDevices.getUserMedia({ audio: true });
- alert("Microphone access granted! Your voice may now be inscribed.");
- } catch (err) {
- alert("Please grant microphone permissions to enable voice inscription.");
- }
- };
-
- const requestAccessibilityPermissions = async () => {
- try {
- await window.electronAPI.pasteText(
- "Test inscription - please verify this appears in another application"
- );
- alert(
- "Accessibility permissions appear to be working! Check if the test inscription appeared in another app."
- );
- } catch (err) {
- alert(
- "Accessibility permissions required! The app will guide you through granting the necessary privileges for automatic text inscription."
- );
- }
- };
+ // Permission functions now handled by hooks
const resetAccessibilityPermissions = () => {
const message = `🔄 RESET ACCESSIBILITY PERMISSIONS\n\nIf you've rebuilt or reinstalled OpenWispr and automatic inscription isn't functioning, you may have obsolete permissions from the previous version.\n\n📋 STEP-BY-STEP RESTORATION:\n\n1️⃣ Open System Settings (or System Preferences)\n • macOS Ventura+: Apple Menu → System Settings\n • Older macOS: Apple Menu → System Preferences\n\n2️⃣ Navigate to Privacy & Security → Accessibility\n\n3️⃣ Look for obsolete OpenWispr entries:\n • Any entries named "OpenWispr"\n • Any entries named "Electron"\n • Any entries with unclear or generic names\n • Entries pointing to old application locations\n\n4️⃣ Remove ALL obsolete entries:\n • Select each old entry\n • Click the minus (-) button\n • Enter your password if prompted\n\n5️⃣ Add the current OpenWispr:\n • Click the plus (+) button\n • Navigate to and select the CURRENT OpenWispr app\n • Ensure the checkbox is ENABLED\n\n6️⃣ Restart OpenWispr completely\n\n💡 This is very common during development when rebuilding applications!\n\nClick OK when you're ready to open System Settings.`;
@@ -370,30 +206,7 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
}
};
- // Enhanced keyboard paste handler for API key input
- const handleApiKeyKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
- // Handle Cmd+V on Mac or Ctrl+V on Windows/Linux
- if ((e.metaKey || e.ctrlKey) && e.key === "v") {
- e.preventDefault(); // Prevent default to handle manually
-
- // Try to paste from clipboard
- setTimeout(async () => {
- try {
- // Try Electron clipboard first
- const text = await window.electronAPI.readClipboard();
- if (text && text.trim()) {
- setApiKey(text.trim());
- } else {
- // Fallback to web clipboard API
- const webText = await navigator.clipboard.readText();
- if (webText && webText.trim()) {
- setApiKey(webText.trim());
- }
- }
- } catch (err) {}
- }, 0);
- }
- };
+ // Clipboard handling now done by shared hooks
return (
<div className="min-h-screen bg-white">
@@ -442,51 +255,10 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
<label className="block text-sm font-medium text-neutral-700 mb-4">
Processing Method
</label>
- <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
- <button
- onClick={() => setUseLocalWhisper(false)}
- className={`p-4 border-2 rounded-xl text-left transition-all ${
- !useLocalWhisper
- ? "border-indigo-500 bg-indigo-50"
- : "border-neutral-200 bg-white hover:border-neutral-300"
- }`}
- >
- <div className="flex items-center justify-between mb-2">
- <h4 className="font-medium text-neutral-900">
- Cloud Processing
- </h4>
- <span className="text-xs text-green-600 bg-green-100 px-2 py-1 rounded-full">
- Fastest
- </span>
- </div>
- <p className="text-sm text-neutral-600">
- Audio sent to OpenAI servers. Faster processing,
- requires API key.
- </p>
- </button>
-
- <button
- onClick={() => setUseLocalWhisper(true)}
- className={`p-4 border-2 rounded-xl text-left transition-all ${
- useLocalWhisper
- ? "border-indigo-500 bg-indigo-50"
- : "border-neutral-200 bg-white hover:border-neutral-300"
- }`}
- >
- <div className="flex items-center justify-between mb-2">
- <h4 className="font-medium text-neutral-900">
- Local Processing
- </h4>
- <span className="text-xs text-blue-600 bg-blue-100 px-2 py-1 rounded-full">
- Private
- </span>
- </div>
- <p className="text-sm text-neutral-600">
- Audio stays on your device. Complete privacy, works
- offline.
- </p>
- </button>
- </div>
+ <ProcessingModeSelector
+ useLocalWhisper={useLocalWhisper}
+ setUseLocalWhisper={setUseLocalWhisper}
+ />
</div>
{/* Cloud Configuration */}
@@ -495,52 +267,12 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
<h4 className="font-medium text-blue-900">
OpenAI API Setup
</h4>
- <div>
- <label className="block text-sm font-medium text-blue-800 mb-2">
- API Key
- </label>
- <div className="flex gap-3">
- <Input
- type="password"
- placeholder="sk-..."
- value={apiKey}
- onChange={(e) => setApiKey(e.target.value)}
- className="flex-1"
- />
- <Button
- variant="outline"
- onClick={async () => {
- try {
- const text =
- await window.electronAPI.readClipboard();
- if (text && text.trim()) {
- setApiKey(text.trim());
- console.log(
- "Manual paste successful via Electron"
- );
- } else {
- const webText =
- await navigator.clipboard.readText();
- setApiKey(webText.trim());
- console.log(
- "Manual paste successful via Web API"
- );
- }
- } catch (err) {
- console.error("Manual paste failed:", err);
- alert(
- "Could not paste from clipboard. Please try typing or using Cmd+V/Ctrl+V."
- );
- }
- }}
- >
- Paste
- </Button>
- </div>
- <p className="text-xs text-blue-700 mt-2">
- Get your API key from platform.openai.com
- </p>
- </div>
+ <ApiKeyInput
+ apiKey={apiKey}
+ setApiKey={setApiKey}
+ className="text-blue-800"
+ helpText="Get your API key from platform.openai.com"
+ />
</div>
)}
@@ -552,11 +284,11 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
Local Whisper Setup
</h4>
<div className="flex items-center space-x-2">
- {checkingWhisper ? (
+ {whisperHook.checkingWhisper ? (
<span className="text-purple-600 text-sm">
Checking...
</span>
- ) : whisperInstalled ? (
+ ) : whisperHook.whisperInstalled ? (
<span className="text-emerald-600 text-sm font-medium">
✓ Ready
</span>
@@ -568,7 +300,7 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
</div>
</div>
- {whisperInstalled ? (
+ {whisperHook.whisperInstalled ? (
<div className="space-y-4">
<div>
<label className="block text-sm font-medium text-purple-800 mb-3">
@@ -632,21 +364,9 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
<Button
variant="outline"
size="sm"
- onClick={async () => {
- try {
- const text =
- await window.electronAPI.readClipboard();
- if (text && text.trim()) {
- setApiKey(text.trim());
- } else {
- const webText =
- await navigator.clipboard.readText();
- setApiKey(webText.trim());
- }
- } catch (err) {
- alert("Could not paste from clipboard.");
- }
- }}
+ onClick={() =>
+ pasteFromClipboardWithFallback(setApiKey)
+ }
className="border-purple-300 text-purple-700 hover:bg-purple-50"
>
Paste
@@ -677,7 +397,7 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
setup required.
</p>
- {installingWhisper ? (
+ {whisperHook.installingWhisper ? (
<div className="space-y-4">
<div className="bg-purple-50 rounded-lg p-4 border border-purple-200">
<div className="flex items-center justify-center space-x-3 mb-2">
@@ -686,9 +406,9 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
Installing...
</span>
</div>
- {installProgress && (
+ {whisperHook.installProgress && (
<div className="text-xs text-purple-600 bg-white p-2 rounded font-mono">
- {installProgress}
+ {whisperHook.installProgress}
</div>
)}
</div>
@@ -699,7 +419,7 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
) : (
<div className="space-y-4">
<Button
- onClick={installWhisper}
+ onClick={whisperHook.installWhisper}
className="bg-purple-600 hover:bg-purple-700"
>
Install Whisper
@@ -707,9 +427,7 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
<div className="flex items-center justify-center">
<Button
- onClick={() =>
- setCheckingWhisper(!checkingWhisper)
- }
+ onClick={whisperHook.checkWhisperInstallation}
variant="outline"
size="sm"
className="text-purple-600 border-purple-300 hover:bg-purple-50"
@@ -770,12 +488,15 @@ export default function SettingsPage({ onBack }: SettingsPageProps) {
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
- <Button onClick={requestPermissions} variant="outline">
+ <Button
+ onClick={permissionsHook.requestMicPermission}
+ variant="outline"
+ >
<span className="mr-2">🎤</span>
Enable Microphone
</Button>
<Button
- onClick={requestAccessibilityPermissions}
+ onClick={permissionsHook.testAccessibilityPermission}
variant="outline"
>
<span className="mr-2">🔓</span>
diff --git a/src/components/ui/ApiKeyInput.tsx b/src/components/ui/ApiKeyInput.tsx
new file mode 100644
index 000000000..1ec670a34
--- /dev/null
+++ b/src/components/ui/ApiKeyInput.tsx
@@ -0,0 +1,59 @@
+import React from "react";
+import { Button } from "./button";
+import { Input } from "./input";
+import { useClipboard } from "../../hooks/useClipboard";
+
+interface ApiKeyInputProps {
+ apiKey: string;
+ setApiKey: (key: string) => void;
+ className?: string;
+ placeholder?: string;
+ label?: string;
+ helpText?: string;
+ variant?: "default" | "purple";
+}
+
+export default function ApiKeyInput({
+ apiKey,
+ setApiKey,
+ className = "",
+ placeholder = "sk-...",
+ label = "API Key",
+ helpText = "Get your API key from platform.openai.com",
+ variant = "default",
+}: ApiKeyInputProps) {
+ const { pasteFromClipboardWithFallback } = useClipboard();
+
+ const variantClasses =
+ variant === "purple" ? "border-purple-300 focus:border-purple-500" : "";
+
+ const buttonVariantClasses =
+ variant === "purple"
+ ? "border-purple-300 text-purple-700 hover:bg-purple-50"
+ : "";
+
+ return (
+ <div className={className}>
+ <label className="block text-sm font-medium text-neutral-700 mb-2">
+ {label}
+ </label>
+ <div className="flex gap-3">
+ <Input
+ type="password"
+ placeholder={placeholder}
+ value={apiKey}
+ onChange={(e) => setApiKey(e.target.value)}
+ className={`flex-1 ${variantClasses}`}
+ />
+ <Button
+ variant="outline"
+ onClick={() => pasteFromClipboardWithFallback(setApiKey)}
+ className={buttonVariantClasses}
+ >
+ Paste
+ </Button>
+ </div>
+ <p className="text-xs text-neutral-600 mt-2">{helpText}</p>
+ </div>
+ );
+}
diff --git a/src/components/ui/PermissionCard.tsx b/src/components/ui/PermissionCard.tsx
new file mode 100644
index 000000000..5b7ce7925
--- /dev/null
+++ b/src/components/ui/PermissionCard.tsx
@@ -0,0 +1,44 @@
+import React from "react";
+import { Button } from "./button";
+import { Check, LucideIcon } from "lucide-react";
+
+interface PermissionCardProps {
+ icon: LucideIcon;
+ title: string;
+ description: string;
+ granted: boolean;
+ onRequest: () => void;
+ buttonText?: string;
+}
+
+export default function PermissionCard({
+ icon: Icon,
+ title,
+ description,
+ granted,
+ onRequest,
+ buttonText = "Grant Access",
+}: PermissionCardProps) {
+ return (
+ <div className="border rounded-lg p-4">
+ <div className="flex items-center justify-between mb-3">
+ <div className="flex items-center gap-3">
+ <Icon className="w-6 h-6 text-indigo-600" />
+ <div>
+ <h3 className="font-semibold text-gray-900">{title}</h3>
+ <p className="text-sm text-gray-600">{description}</p>
+ </div>
+ </div>
+ {granted ? (
+ <div className="text-green-600">
+ <Check className="w-5 h-5" />
+ </div>
+ ) : (
+ <Button onClick={onRequest} size="sm">
+ {buttonText}
+ </Button>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/src/components/ui/ProcessingModeSelector.tsx b/src/components/ui/ProcessingModeSelector.tsx
new file mode 100644
index 000000000..03985b4bb
--- /dev/null
+++ b/src/components/ui/ProcessingModeSelector.tsx
@@ -0,0 +1,62 @@
+import React from "react";
+import { Cloud, Lock } from "lucide-react";
+
+interface ProcessingModeSelectorProps {
+ useLocalWhisper: boolean;
+ setUseLocalWhisper: (value: boolean) => void;
+ className?: string;
+}
+
+export default function ProcessingModeSelector({
+ useLocalWhisper,
+ setUseLocalWhisper,
+ className = "",
+}: ProcessingModeSelectorProps) {
+ return (
+ <div className={`grid grid-cols-1 md:grid-cols-2 gap-3 ${className}`}>
+ <button
+ onClick={() => setUseLocalWhisper(false)}
+ className={`p-4 border-2 rounded-xl text-left transition-all cursor-pointer ${
+ !useLocalWhisper
+ ? "border-indigo-500 bg-indigo-50"
+ : "border-neutral-200 bg-white hover:border-neutral-300"
+ }`}
+ >
+ <div className="flex items-center justify-between mb-2">
+ <div className="flex items-center gap-3">
+ <Cloud className="w-6 h-6 text-blue-600" />
+ <h4 className="font-medium text-neutral-900">Cloud Processing</h4>
+ </div>
+ <span className="text-xs text-green-600 bg-green-100 px-2 py-1 rounded-full">
+ Fastest
+ </span>
+ </div>
+ <p className="text-sm text-neutral-600">
+ Audio sent to OpenAI servers. Faster processing, requires API key.
+ </p>
+ </button>
+
+ <button
+ onClick={() => setUseLocalWhisper(true)}
+ className={`p-4 border-2 rounded-xl text-left transition-all cursor-pointer ${
+ useLocalWhisper
+ ? "border-indigo-500 bg-indigo-50"
+ : "border-neutral-200 bg-white hover:border-neutral-300"
+ }`}
+ >
+ <div className="flex items-center justify-between mb-2">
+ <div className="flex items-center gap-3">
+ <Lock className="w-6 h-6 text-blue-600" />
+ <h4 className="font-medium text-neutral-900">Local Processing</h4>
+ </div>
+ <span className="text-xs text-blue-600 bg-blue-100 px-2 py-1 rounded-full">
+ Private
+ </span>
+ </div>
+ <p className="text-sm text-neutral-600">
+ Audio stays on your device. Complete privacy, works offline.
+ </p>
+ </button>
+ </div>
+ );
+}
diff --git a/src/components/ui/StepProgress.tsx b/src/components/ui/StepProgress.tsx
new file mode 100644
index 000000000..0ded56018
--- /dev/null
+++ b/src/components/ui/StepProgress.tsx
@@ -0,0 +1,70 @@
+import React from "react";
+import { Check, LucideIcon } from "lucide-react";
+
+interface Step {
+ title: string;
+ icon: LucideIcon;
+}
+
+interface StepProgressProps {
+ steps: Step[];
+ currentStep: number;
+ className?: string;
+}
+
+export default function StepProgress({
+ steps,
+ currentStep,
+ className = "",
+}: StepProgressProps) {
+ return (
+ <div className={`flex items-center justify-between mb-2 ${className}`}>
+ {steps.map((step, index) => {
+ const Icon = step.icon;
+ const isActive = index === currentStep;
+ const isCompleted = index < currentStep;
+
+ return (
+ <div key={index} className="flex items-center">
+ <div
+ className={`flex items-center gap-2 ${
+ isActive
+ ? "text-blue-600"
+ : isCompleted
+ ? "text-green-600"
+ : "text-stone-400"
+ }`}
+ style={{ fontFamily: "Noto Sans, sans-serif" }}
+ >
+ <div
+ className={`w-8 h-8 rounded-full flex items-center justify-center border-2 ${
+ isActive
+ ? "border-blue-600 bg-blue-50"
+ : isCompleted
+ ? "border-green-600 bg-green-50"
+ : "border-stone-300 bg-white"
+ }`}
+ >
+ {isCompleted ? (
+ <Check className="w-4 h-4" />
+ ) : (
+ <Icon className="w-4 h-4" />
+ )}
+ </div>
+ <span className="text-xs font-medium hidden md:block">
+ {step.title}
+ </span>
+ </div>
+ {index < steps.length - 1 && (
+ <div
+ className={`w-8 h-0.5 mx-2 ${
+ isCompleted ? "bg-green-600" : "bg-stone-300"
+ }`}
+ />
+ )}
+ </div>
+ );
+ })}
+ </div>
+ );
+}
diff --git a/src/hooks/useClipboard.ts b/src/hooks/useClipboard.ts
new file mode 100644
index 000000000..b49cddc8b
--- /dev/null
+++ b/src/hooks/useClipboard.ts
@@ -0,0 +1,63 @@
+import { useCallback } from "react";
+
+export interface UseClipboardReturn {
+ pasteFromClipboard: (setter: (value: string) => void) => Promise<void>;
+ pasteFromClipboardWithFallback: (
+ setter: (value: string) => void
+ ) => Promise<void>;
+}
+
+export const useClipboard = (): UseClipboardReturn => {
+ const pasteFromClipboard = useCallback(
+ async (setter: (value: string) => void) => {
+ try {
+ const text = await window.electronAPI.readClipboard();
+ if (text && text.trim()) {
+ setter(text.trim());
+ } else {
+ throw new Error("Empty clipboard");
+ }
+ } catch (err) {
+ console.error("Clipboard read failed:", err);
+ throw err;
+ }
+ },
+ []
+ );
+
+ const pasteFromClipboardWithFallback = useCallback(
+ async (setter: (value: string) => void) => {
+ try {
+ // Try Electron clipboard first
+ const text = await window.electronAPI.readClipboard();
+ if (text && text.trim()) {
+ setter(text.trim());
+ return;
+ }
+ } catch (err) {
+ console.warn("Electron clipboard failed, trying web API:", err);
+ }
+
+ try {
+ // Fallback to web clipboard API
+ const webText = await navigator.clipboard.readText();
+ if (webText && webText.trim()) {
+ setter(webText.trim());
+ return;
+ }
+ } catch (err) {
+ console.error("Web clipboard also failed:", err);
+ }
+
+ alert(
+ "Could not paste from clipboard. Please try typing or using Cmd+V/Ctrl+V."
+ );
+ },
+ []
+ );
+
+ return {
+ pasteFromClipboard,
+ pasteFromClipboardWithFallback,
+ };
+};
diff --git a/src/hooks/usePermissions.ts b/src/hooks/usePermissions.ts
new file mode 100644
index 000000000..6e9db5b49
--- /dev/null
+++ b/src/hooks/usePermissions.ts
@@ -0,0 +1,53 @@
+import { useState, useCallback } from "react";
+
+export interface UsePermissionsReturn {
+ // State
+ micPermissionGranted: boolean;
+ accessibilityPermissionGranted: boolean;
+
+ // Functions
+ requestMicPermission: () => Promise<void>;
+ testAccessibilityPermission: () => Promise<void>;
+ setMicPermissionGranted: (granted: boolean) => void;
+ setAccessibilityPermissionGranted: (granted: boolean) => void;
+}
+
+export const usePermissions = (): UsePermissionsReturn => {
+ const [micPermissionGranted, setMicPermissionGranted] = useState(false);
+ const [accessibilityPermissionGranted, setAccessibilityPermissionGranted] =
+ useState(false);
+
+ const requestMicPermission = useCallback(async () => {
+ try {
+ await navigator.mediaDevices.getUserMedia({ audio: true });
+ setMicPermissionGranted(true);
+ } catch (err) {
+ console.error("Microphone permission denied:", err);
+ alert("Please grant microphone permissions to use voice dictation.");
+ }
+ }, []);
+
+ const testAccessibilityPermission = useCallback(async () => {
+ try {
+ await window.electronAPI.pasteText("OpenWispr accessibility test");
+ setAccessibilityPermissionGranted(true);
+ alert(
+ "✅ Accessibility permissions working! Check if the test text appeared in another app."
+ );
+ } catch (err) {
+ console.error("Accessibility permission test failed:", err);
+ alert(
+ "❌ Accessibility permissions needed! Please grant them in System Settings."
+ );
+ }
+ }, []);
+
+ return {
+ micPermissionGranted,
+ accessibilityPermissionGranted,
+ requestMicPermission,
+ testAccessibilityPermission,
+ setMicPermissionGranted,
+ setAccessibilityPermissionGranted,
+ };
+};
diff --git a/src/hooks/useWhisper.ts b/src/hooks/useWhisper.ts
new file mode 100644
index 000000000..391c80c8e
--- /dev/null
+++ b/src/hooks/useWhisper.ts
@@ -0,0 +1,77 @@
+import { useState, useCallback } from "react";
+import { WhisperCheckResult, WhisperInstallResult } from "../types/electron";
+
+export interface UseWhisperReturn {
+ // State
+ whisperInstalled: boolean;
+ checkingWhisper: boolean;
+ installingWhisper: boolean;
+ installProgress: string;
+
+ // Functions
+ checkWhisperInstallation: () => Promise<void>;
+ installWhisper: () => Promise<void>;
+
+ // Setup progress listener
+ setupProgressListener: () => void;
+}
+
+export const useWhisper = (): UseWhisperReturn => {
+ const [whisperInstalled, setWhisperInstalled] = useState(false);
+ const [checkingWhisper, setCheckingWhisper] = useState(false);
+ const [installingWhisper, setInstallingWhisper] = useState(false);
+ const [installProgress, setInstallProgress] = useState("");
+
+ const checkWhisperInstallation = useCallback(async () => {
+ try {
+ setCheckingWhisper(true);
+ const result: WhisperCheckResult =
+ await window.electronAPI.checkWhisperInstallation();
+ setWhisperInstalled(result.installed && result.working);
+ } catch (error) {
+ console.error("Error checking Whisper installation:", error);
+ setWhisperInstalled(false);
+ } finally {
+ setCheckingWhisper(false);
+ }
+ }, []);
+
+ const installWhisper = useCallback(async () => {
+ try {
+ setInstallingWhisper(true);
+ setInstallProgress("Starting Whisper installation...");
+
+ const result: WhisperInstallResult =
+ await window.electronAPI.installWhisper();
+
+ if (result.success) {
+ setWhisperInstalled(true);
+ setInstallProgress("Installation complete!");
+ } else {
+ alert(`❌ Failed to install Whisper: ${result.message}`);
+ }
+ } catch (error) {
+ console.error("Error installing Whisper:", error);
+ alert(`❌ Failed to install Whisper: ${error}`);
+ } finally {
+ setInstallingWhisper(false);
+ setTimeout(() => setInstallProgress(""), 2000); // Clear progress after 2 seconds
+ }
+ }, []);
+
+ const setupProgressListener = useCallback(() => {
+ window.electronAPI.onWhisperInstallProgress((_, data) => {
+ setInstallProgress(data.message);
+ });
+ }, []);
+
+ return {
+ whisperInstalled,
+ checkingWhisper,
+ installingWhisper,
+ installProgress,
+ checkWhisperInstallation,
+ installWhisper,
+ setupProgressListener,
+ };
+};
diff --git a/src/types/electron.ts b/src/types/electron.ts
new file mode 100644
index 000000000..84427e419
--- /dev/null
+++ b/src/types/electron.ts
@@ -0,0 +1,164 @@
+export interface TranscriptionItem {
+ id: number;
+ text: string;
+ timestamp: string;
+ created_at: string;
+}
+
+export interface WhisperInstallResult {
+ success: boolean;
+ message: string;
+ output: string;
+}
+
+export interface WhisperCheckResult {
+ installed: boolean;
+ working: boolean;
+ error?: string;
+}
+
+export interface WhisperModelResult {
+ success: boolean;
+ model: string;
+ downloaded: boolean;
+ size_mb?: number;
+ error?: string;
+}
+
+export interface WhisperModelDeleteResult {
+ success: boolean;
+ model: string;
+ deleted: boolean;
+ freed_mb?: number;
+ error?: string;
+}
+
+export interface WhisperModelsListResult {
+ success: boolean;
+ models: Array<{ model: string; downloaded: boolean; size_mb?: number }>;
+ cache_dir: string;
+}
+
+export interface UpdateCheckResult {
+ updateAvailable: boolean;
+ version?: string;
+ releaseDate?: string;
+ files?: any[];
+ releaseNotes?: string;
+ message?: string;
+}
+
+export interface UpdateStatusResult {
+ updateAvailable: boolean;
+ updateDownloaded: boolean;
+ isDevelopment: boolean;
+}
+
+export interface UpdateResult {
+ success: boolean;
+ message: string;
+}
+
+export interface AppVersionResult {
+ version: string;
+}
+
+export interface WhisperDownloadProgressData {
+ type: string;
+ model: string;
+ percentage?: number;
+ downloaded_bytes?: number;
+ total_bytes?: number;
+ error?: string;
+ result?: any;
+}
+
+export interface WhisperInstallProgressData {
+ type: string;
+ message: string;
+ output?: string;
+}
+
+// Additional interface missing from preload.js
+export interface SaveSettings {
+ useLocalWhisper: boolean;
+ apiKey: string;
+ whisperModel: string;
+ hotkey: string;
+}
+
+declare global {
+ interface Window {
+ electronAPI: {
+ // Basic window operations
+ pasteText: (text: string) => Promise<void>;
+ hideWindow: () => Promise<void>;
+ showDictationPanel?: () => Promise<void>;
+ onToggleDictation: (callback: () => void) => void;
+
+ // Database operations
+ saveTranscription: (
+ text: string
+ ) => Promise<{ id: number; success: boolean }>;
+ getTranscriptions: (limit?: number) => Promise<TranscriptionItem[]>;
+ clearTranscriptions: () => Promise<{ cleared: number; success: boolean }>;
+ deleteTranscription: (id: number) => Promise<{ success: boolean }>;
+
+ // API key management
+ getOpenAIKey: () => Promise<string>;
+ saveOpenAIKey: (key: string) => Promise<{ success: boolean }>;
+ createProductionEnvFile: (key: string) => Promise<void>;
+
+ // Clipboard operations
+ readClipboard: () => Promise<string>;
+
+ // Whisper operations
+ transcribeLocalWhisper: (
+ audioBlob: Blob | ArrayBuffer,
+ options?: any
+ ) => Promise<any>;
+ checkWhisperInstallation: () => Promise<WhisperCheckResult>;
+ installWhisper: () => Promise<WhisperInstallResult>;
+ onWhisperInstallProgress: (
+ callback: (event: any, data: WhisperInstallProgressData) => void
+ ) => void;
+ downloadWhisperModel: (modelName: string) => Promise<WhisperModelResult>;
+ onWhisperDownloadProgress: (
+ callback: (event: any, data: WhisperDownloadProgressData) => void
+ ) => void;
+ checkModelStatus: (modelName: string) => Promise<WhisperModelResult>;
+ listWhisperModels: () => Promise<WhisperModelsListResult>;
+ deleteWhisperModel: (
+ modelName: string
+ ) => Promise<WhisperModelDeleteResult>;
+
+ // Window control operations
+ windowMinimize: () => Promise<void>;
+ windowMaximize: () => Promise<void>;
+ windowClose: () => Promise<void>;
+ windowIsMaximized: () => Promise<boolean>;
+
+ // App management
+ cleanupApp: () => Promise<void>;
+
+ // Update operations
+ checkForUpdates: () => Promise<UpdateCheckResult>;
+ downloadUpdate: () => Promise<UpdateResult>;
+ installUpdate: () => Promise<UpdateResult>;
+ getAppVersion: () => Promise<AppVersionResult>;
+ getUpdateStatus: () => Promise<UpdateStatusResult>;
+
+ // Update event listeners
+ onUpdateAvailable: (callback: (event: any, info: any) => void) => void;
+ onUpdateNotAvailable: (callback: (event: any, info: any) => void) => void;
+ onUpdateDownloaded: (callback: (event: any, info: any) => void) => void;
+ onUpdateDownloadProgress: (
+ callback: (event: any, progressObj: any) => void
+ ) => void;
+ onUpdateError: (callback: (event: any, error: any) => void) => void;
+
+ // Settings management (used by OnboardingFlow but not in preload.js)
+ saveSettings?: (settings: SaveSettings) => Promise<void>;
+ };
+ }
+}