diff --git a/src/renderer/src/components/settings/VoicePane.tsx b/src/renderer/src/components/settings/VoicePane.tsx index cb1d64563..462c23db7 100644 --- a/src/renderer/src/components/settings/VoicePane.tsx +++ b/src/renderer/src/components/settings/VoicePane.tsx @@ -32,6 +32,7 @@ export function VoicePane({ settings, updateSettings }: VoicePaneProps): React.J const modelStates = useAppStore((s) => s.modelStates) const refreshModelStates = useAppStore((s) => s.refreshModelStates) const [catalog, setCatalog] = useState([]) + const [permissionPending, setPermissionPending] = useState(false) useEffect(() => { refreshModelStates() @@ -57,6 +58,37 @@ export function VoicePane({ settings, updateSettings }: VoicePaneProps): React.J }) } + const toggleVoiceDictation = async (): Promise => { + if (voiceSettings.enabled) { + updateVoiceSettings({ enabled: false }) + return + } + + setPermissionPending(true) + try { + // Why: enabling dictation is the point where users expect the macOS + // microphone prompt, not after their first attempted recording fails. + const result = await window.api.developerPermissions.request({ id: 'microphone' }) + if (result.status === 'granted' || result.status === 'unsupported') { + updateVoiceSettings({ enabled: true }) + } + + if (result.status === 'granted') { + toast.success('Microphone permission granted') + } else if (result.openedSystemSettings) { + toast.message( + 'Opened macOS Privacy & Security. Enable dictation again after granting access.' + ) + } else if (result.status !== 'unsupported') { + toast.message('Microphone permission is required before enabling voice dictation.') + } + } catch { + toast.error('Could not request microphone permission. Voice dictation was not enabled.') + } finally { + setPermissionPending(false) + } + } + const getModelState = (id: string): SpeechModelState | undefined => modelStates.find((s) => s.id === id) @@ -79,10 +111,12 @@ export function VoicePane({ settings, updateSettings }: VoicePaneProps): React.J role="switch" aria-checked={voiceSettings.enabled} aria-label="Enable Voice Dictation" - onClick={() => updateVoiceSettings({ enabled: !voiceSettings.enabled })} + aria-busy={permissionPending} + disabled={permissionPending} + onClick={() => void toggleVoiceDictation()} className={`relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border border-transparent transition-colors ${ voiceSettings.enabled ? 'bg-foreground' : 'bg-muted-foreground/30' - }`} + } ${permissionPending ? 'cursor-wait opacity-70' : ''}`} >