diff --git a/mobile/src/dictation/dictation-reply-schema.ts b/mobile/src/dictation/dictation-reply-schema.ts index 9298651bd11..70c3bd707fa 100644 --- a/mobile/src/dictation/dictation-reply-schema.ts +++ b/mobile/src/dictation/dictation-reply-schema.ts @@ -32,6 +32,8 @@ export const dictationSetupSchema = z.looseObject({ enabled: salvagedOptional('enabled', z.boolean()), selectedModelId: salvagedOptional('selectedModelId', z.string()), dictationMode: salvagedOptional('dictationMode', z.string()), + // Absent from older hosts, which have no Auto mode; the phone then offers only Toggle and Hold. + dictationHoldToRecord: salvagedOptional('dictationHoldToRecord', z.boolean()), // Absent from older hosts, which remove no fillers either; the phone then keeps them on, the host default. removeFillerWords: salvagedOptional('removeFillerWords', z.boolean()), models: salvagingArray(speechModelSchema) diff --git a/mobile/src/dictation/mobile-dictation-setup.ts b/mobile/src/dictation/mobile-dictation-setup.ts index de85a942f67..9e7f034dbd8 100644 --- a/mobile/src/dictation/mobile-dictation-setup.ts +++ b/mobile/src/dictation/mobile-dictation-setup.ts @@ -181,7 +181,12 @@ export async function deleteDictationModel( export async function setDictationConfig( client: RpcOperationSender, - params: { enabled?: boolean; modelId?: string; dictationMode?: 'toggle' | 'hold' } + params: { + enabled?: boolean + modelId?: string + dictationMode?: 'toggle' | 'hold' + dictationHoldToRecord?: boolean + } ): Promise { const reply = await dictationConfigWrite.request(client, params) return interpretOrThrowRefusalMessage( diff --git a/mobile/src/i18n/locales/de.json b/mobile/src/i18n/locales/de.json index 029b9684286..b0fe3ddcfa7 100644 --- a/mobile/src/i18n/locales/de.json +++ b/mobile/src/i18n/locales/de.json @@ -2847,6 +2847,8 @@ "dictationHeading": "DIKTAT", "dictationMode": "Diktatmodus", "dictationModeDescription": "Umschalten: einmal zum Starten und erneut zum Stoppen drücken. Gedrückt halten: währenddessen diktieren.", + "dictationModeWithAutoDescription": "Automatisch: Tippen zum Starten und Stoppen; am Computer nimmt das Gedrückthalten des Kürzels auf, bis Sie loslassen. Gedrückt halten: währenddessen diktieren. Umschalten: einmal zum Starten und erneut zum Stoppen drücken.", + "autoMode": "Automatisch", "downloadFailed": "Download fehlgeschlagen", "enableDictation": "Diktat aktivieren", "holdMode": "Gedrückt halten", diff --git a/mobile/src/i18n/locales/en.json b/mobile/src/i18n/locales/en.json index 2cb6a10d186..38df12913c0 100644 --- a/mobile/src/i18n/locales/en.json +++ b/mobile/src/i18n/locales/en.json @@ -142,6 +142,8 @@ "dictationDescription": "Dictate text into any focused pane on your desktop.", "dictationMode": "Dictation Mode", "dictationModeDescription": "Toggle: press once to start, again to stop. Hold: dictate while held.", + "dictationModeWithAutoDescription": "Auto: tap to start and stop; on your computer, holding the shortcut records until you let go. Hold: dictate while held. Toggle: press once to start, again to stop.", + "autoMode": "Auto", "speechModelHeading": "SPEECH MODEL", "speechModel": "Speech Model", "loading": "Loading voice settings…" diff --git a/mobile/src/i18n/locales/es.json b/mobile/src/i18n/locales/es.json index 42015fee2bd..4de6b8ceda7 100644 --- a/mobile/src/i18n/locales/es.json +++ b/mobile/src/i18n/locales/es.json @@ -2921,6 +2921,8 @@ "dictationHeading": "DICTADO", "dictationMode": "Modo de dictado", "dictationModeDescription": "Alternar: pulsa una vez para iniciar y otra para detener. Mantener pulsado: dicta sin soltar.", + "dictationModeWithAutoDescription": "Automático: toca para iniciar y detener; en tu ordenador, mantener el atajo graba hasta que lo sueltes. Mantener pulsado: dicta sin soltar. Alternar: pulsa una vez para iniciar y otra para detener.", + "autoMode": "Automático", "downloadFailed": "Falló la descarga", "enableDictation": "Habilitar dictado de voz", "holdMode": "Mantener", diff --git a/mobile/src/i18n/locales/fr.json b/mobile/src/i18n/locales/fr.json index 4b44bb66a01..49aa7419acc 100644 --- a/mobile/src/i18n/locales/fr.json +++ b/mobile/src/i18n/locales/fr.json @@ -2921,6 +2921,8 @@ "dictationHeading": "DICTÉE", "dictationMode": "Mode de dictée", "dictationModeDescription": "Bascule : appuyez une fois pour démarrer, puis à nouveau pour arrêter. Maintien : dictez tant que vous maintenez l'appui.", + "dictationModeWithAutoDescription": "Auto : appuyez pour démarrer et arrêter ; sur votre ordinateur, maintenir le raccourci enregistre jusqu’à ce que vous relâchiez. Maintien : dictez tant que vous maintenez l’appui. Bascule : appuyez une fois pour démarrer, puis à nouveau pour arrêter.", + "autoMode": "Auto", "downloadFailed": "Échec du téléchargement", "enableDictation": "Activer la dictée vocale", "holdMode": "Maintien", diff --git a/mobile/src/i18n/locales/ja.json b/mobile/src/i18n/locales/ja.json index 5784e413a06..5d8c5b90039 100644 --- a/mobile/src/i18n/locales/ja.json +++ b/mobile/src/i18n/locales/ja.json @@ -2843,6 +2843,8 @@ "dictationHeading": "ディクテーション", "dictationMode": "ディクテーションモード", "dictationModeDescription": "トグル:1 回押すと開始し、もう一度押すと停止します。ホールド:押している間だけ音声入力します。", + "dictationModeWithAutoDescription": "自動:タップで開始と停止。コンピュータではショートカットを押し続けると離すまで録音します。ホールド:押している間だけ音声入力します。トグル:1 回押すと開始し、もう一度押すと停止します。", + "autoMode": "自動", "downloadFailed": "ダウンロードに失敗しました", "enableDictation": "音声ディクテーションを有効にする", "holdMode": "ホールド", diff --git a/mobile/src/i18n/locales/ko.json b/mobile/src/i18n/locales/ko.json index f35c7f04781..2869ac7c0ac 100644 --- a/mobile/src/i18n/locales/ko.json +++ b/mobile/src/i18n/locales/ko.json @@ -2843,6 +2843,8 @@ "dictationHeading": "받아쓰기", "dictationMode": "받아쓰기 모드", "dictationModeDescription": "토글: 한 번 누르면 받아쓰기를 시작하고, 다시 누르면 중지합니다. 길게 누르기: 누르고 있는 동안 받아쓰기합니다.", + "dictationModeWithAutoDescription": "자동: 탭하여 시작하고 중지합니다. 컴퓨터에서는 단축키를 길게 누르면 손을 뗄 때까지 녹음합니다. 길게 누르기: 누르고 있는 동안 받아쓰기합니다. 토글: 한 번 누르면 시작하고, 다시 누르면 중지합니다.", + "autoMode": "자동", "downloadFailed": "다운로드 실패", "enableDictation": "음성 받아쓰기 활성화", "holdMode": "길게 누르기", diff --git a/mobile/src/i18n/locales/pt.json b/mobile/src/i18n/locales/pt.json index 11e9b550f46..1b47e7d5be5 100644 --- a/mobile/src/i18n/locales/pt.json +++ b/mobile/src/i18n/locales/pt.json @@ -2921,6 +2921,8 @@ "dictationHeading": "DITADO", "dictationMode": "Modo de Ditado", "dictationModeDescription": "Alternar: pressione uma vez para iniciar e novamente para parar. Manter pressionado: pressione e segure para ditar.", + "dictationModeWithAutoDescription": "Automático: toque para iniciar e parar; no computador, manter o atalho pressionado grava até você soltar. Manter pressionado: pressione e segure para ditar. Alternar: pressione uma vez para iniciar e novamente para parar.", + "autoMode": "Automático", "downloadFailed": "Falha no download", "enableDictation": "Ativar Ditado por Voz", "holdMode": "Manter Pressionado", diff --git a/mobile/src/i18n/locales/ru.json b/mobile/src/i18n/locales/ru.json index d3ed0877a93..9065841500d 100644 --- a/mobile/src/i18n/locales/ru.json +++ b/mobile/src/i18n/locales/ru.json @@ -2995,6 +2995,8 @@ "dictationHeading": "ДИКТОВКА", "dictationMode": "Режим диктовки", "dictationModeDescription": "Переключение: нажмите один раз, чтобы начать, ещё раз — чтобы остановить. Удержание: диктуйте, пока удерживаете кнопку.", + "dictationModeWithAutoDescription": "Авто: нажмите, чтобы начать и остановить; на компьютере удержание сочетания клавиш записывает до отпускания. Удержание: диктуйте, пока удерживаете кнопку. Переключение: нажмите один раз, чтобы начать, ещё раз — чтобы остановить.", + "autoMode": "Авто", "downloadFailed": "Не удалось скачать", "enableDictation": "Включить голосовую диктовку", "holdMode": "Удержание", diff --git a/mobile/src/i18n/locales/tr.json b/mobile/src/i18n/locales/tr.json index d278bddb6a4..eae39fed246 100644 --- a/mobile/src/i18n/locales/tr.json +++ b/mobile/src/i18n/locales/tr.json @@ -2847,6 +2847,8 @@ "dictationHeading": "DİKTE", "dictationMode": "Dikte Modu", "dictationModeDescription": "Aç/kapat: başlatmak için bir kez, durdurmak için tekrar basın. Basılı tut: basılı tuttuğunuz sürece dikte edin.", + "dictationModeWithAutoDescription": "Otomatik: başlatmak ve durdurmak için dokunun; bilgisayarınızda kısayolu basılı tutmak bırakana kadar kaydeder. Basılı tut: basılı tuttuğunuz sürece dikte edin. Aç/kapat: başlatmak için bir kez, durdurmak için tekrar basın.", + "autoMode": "Otomatik", "downloadFailed": "İndirme tamamlanamadı", "enableDictation": "Sesli Dikteyi Etkinleştir", "holdMode": "Basılı Tut", diff --git a/mobile/src/i18n/locales/zh-Hant.json b/mobile/src/i18n/locales/zh-Hant.json index 102324d702f..7b45a45a060 100644 --- a/mobile/src/i18n/locales/zh-Hant.json +++ b/mobile/src/i18n/locales/zh-Hant.json @@ -2843,6 +2843,8 @@ "dictationHeading": "聽寫", "dictationMode": "聽寫模式", "dictationModeDescription": "切換:按一次開始,再按一次停止。按住:按住期間進行聽寫。", + "dictationModeWithAutoDescription": "自動:輕按開始和停止;在電腦上按住快捷鍵會一直錄音,直到放開。按住:按住期間進行聽寫。切換:按一次開始,再按一次停止。", + "autoMode": "自動", "downloadFailed": "下載失敗", "enableDictation": "啟用語音聽寫", "holdMode": "按住", diff --git a/mobile/src/i18n/locales/zh.json b/mobile/src/i18n/locales/zh.json index f3a4f171e5f..3361b7e993a 100644 --- a/mobile/src/i18n/locales/zh.json +++ b/mobile/src/i18n/locales/zh.json @@ -2843,6 +2843,8 @@ "dictationHeading": "听写", "dictationMode": "听写模式", "dictationModeDescription": "切换:按一次开始,再按一次停止。按住:按住期间进行听写。", + "dictationModeWithAutoDescription": "自动:轻按开始和停止;在电脑上按住快捷键会一直录音,直到松开。按住:按住期间进行听写。切换:按一次开始,再按一次停止。", + "autoMode": "自动", "downloadFailed": "下载失败", "enableDictation": "启用语音听写", "holdMode": "按住", diff --git a/mobile/src/settings/settings-screen-state.test.tsx b/mobile/src/settings/settings-screen-state.test.tsx index 6bd21b6b58c..b0a3136fc2f 100644 --- a/mobile/src/settings/settings-screen-state.test.tsx +++ b/mobile/src/settings/settings-screen-state.test.tsx @@ -55,6 +55,36 @@ afterEach(() => { act(() => renderer?.unmount()) }) describe('shared settings screen state', () => { + it('shows a desktop on Auto as Auto and switches it to plain Toggle', async () => { + const operations = { + load: vi.fn().mockResolvedValue({ + enabled: true, + dictationMode: 'toggle', + dictationHoldToRecord: true, + selectedModelId: '', + models: [] + }), + configure: vi.fn().mockImplementation(() => new Promise(() => {})), + download: vi.fn(), + delete: vi.fn() + } as VoiceSettingsOperations + await act(async () => { + renderer = create( + createElement(VoiceSettingsScreen, { operations, focused: true, onBack: vi.fn() }) + ) + }) + const modeProps = () => renderer.root.findByProps({ testIDPrefix: 'voice-mode-' }).props + expect(modeProps().selected).toBe('auto') + + await act(async () => { + modeProps().onSelect('toggle') + }) + expect(operations.configure).toHaveBeenCalledWith({ + dictationMode: 'toggle', + dictationHoldToRecord: false + }) + expect(modeProps().selected).toBe('toggle') + }) it('flips the Voice switch before the desktop replies and surfaces a rejected save', async () => { const loaded = { enabled: true, diff --git a/mobile/src/settings/voice-settings-operations.ts b/mobile/src/settings/voice-settings-operations.ts index fc5fced208d..bedcd866d1e 100644 --- a/mobile/src/settings/voice-settings-operations.ts +++ b/mobile/src/settings/voice-settings-operations.ts @@ -6,6 +6,7 @@ export interface VoiceSettingsOperations { enabled?: boolean modelId?: string dictationMode?: 'toggle' | 'hold' + dictationHoldToRecord?: boolean }): Promise download(modelId: string): Promise delete(modelId: string): Promise diff --git a/mobile/src/settings/voice-settings-screen.tsx b/mobile/src/settings/voice-settings-screen.tsx index 1766b7512d5..3cdf1f43f80 100644 --- a/mobile/src/settings/voice-settings-screen.tsx +++ b/mobile/src/settings/voice-settings-screen.tsx @@ -17,16 +17,21 @@ import { type MobileSpeechSetup } from '../dictation/mobile-dictation-setup' import { MobileSwitch } from '../components/MobileSwitch' +import { + dictationShortcutMode, + dictationShortcutModeSettings +} from '../../../src/shared/dictation-shortcut-mode' import { SettingsNote, SettingsScreen, SettingsSection } from './settings-screen-frame' import { VoiceTranscribeOnSection, voiceTranscribeOnShown } from './voice-transcribe-on-section' const POLL_INTERVAL_MS = 1500 -function dictationModes(t: Translate) { - return [ - { value: 'toggle', label: t('settings.voiceSettingsScreen.toggleMode', 'Toggle') }, - { value: 'hold', label: t('settings.voiceSettingsScreen.holdMode', 'Hold') } - ] as const +// Hosts that report hold-to-record have Auto; older ones only Toggle and Hold. +function dictationModes(t: Translate, offersAuto: boolean) { + const toggle = { value: 'toggle', label: t('settings.voiceSettingsScreen.toggleMode', 'Toggle') } + const hold = { value: 'hold', label: t('settings.voiceSettingsScreen.holdMode', 'Hold') } + const auto = { value: 'auto', label: t('settings.voiceSettingsScreen.autoMode', 'Auto') } + return offersAuto ? ([auto, hold, toggle] as const) : ([toggle, hold] as const) } type ModelBusyAction = { modelId: string; type: 'download' | 'select' | 'delete' } @@ -154,13 +159,16 @@ export default function VoiceSettingsScreen({ return } setError(null) - const { enabled, dictationMode } = params + const { enabled, dictationMode, dictationHoldToRecord } = params setSetup((prev) => prev ? { ...prev, ...(enabled === undefined ? {} : { enabled }), - ...(dictationMode === undefined ? {} : { dictationMode }) + ...(dictationMode === undefined ? {} : { dictationMode }), + ...(dictationHoldToRecord === undefined || prev.dictationHoldToRecord === undefined + ? {} + : { dictationHoldToRecord }) } : prev ) @@ -243,6 +251,7 @@ export default function VoiceSettingsScreen({ ) const enabled = setup?.enabled ?? false + const offersAuto = setup?.dictationHoldToRecord !== undefined const selectedModel = setup?.models.find((m) => m.id === setup.selectedModelId) const selectedModelLabel = selectedModel?.label ?? t('settings.voiceSettingsScreen.noneSelected', 'None selected') @@ -299,10 +308,17 @@ export default function VoiceSettingsScreen({ first={!voiceTranscribeOnShown()} title={t('settings.voiceSettingsScreen.dictationHeading', 'DICTATION')} // The segmented control leaves the mode row no room for two lines of explanation. - footer={t( - 'settings.voiceSettingsScreen.dictationModeDescription', - 'Toggle: press once to start, again to stop. Hold: dictate while held.' - )} + footer={ + offersAuto + ? t( + 'settings.voiceSettingsScreen.dictationModeWithAutoDescription', + 'Auto: tap to start and stop; on your computer, holding the shortcut records until you let go. Hold: dictate while held. Toggle: press once to start, again to stop.' + ) + : t( + 'settings.voiceSettingsScreen.dictationModeDescription', + 'Toggle: press once to start, again to stop. Hold: dictate while held.' + ) + } > void configure({ dictationMode })} + segments={dictationModes(t, offersAuto)} + selected={offersAuto ? dictationShortcutMode(setup) : setup.dictationMode} + onSelect={(mode) => void configure(dictationShortcutModeSettings(mode))} testIDPrefix="voice-mode-" disabled={!enabled} /> diff --git a/src/main/persistence/loading-store/normalize-loaded-global-settings.test.ts b/src/main/persistence/loading-store/normalize-loaded-global-settings.test.ts index 0969c127964..7409c554ed3 100644 --- a/src/main/persistence/loading-store/normalize-loaded-global-settings.test.ts +++ b/src/main/persistence/loading-store/normalize-loaded-global-settings.test.ts @@ -36,18 +36,24 @@ it('keeps existing Antigravity profiles personal and preserves explicit or malfo expect(() => resolveAntigravityChatAuthConfig(malformed)).toThrow('account settings') }) -it('moves the old Toggle dictation default to Auto once and keeps Hold and later choices', () => { - const voice = (dictationMode: string) => ({ ...getDefaultVoiceSettings(), dictationMode }) - const legacy = { voiceDictationModeDefaultedToAuto: undefined } +it('stores Auto as Toggle plus hold-to-record so older builds keep a working shortcut', () => { + const { dictationHoldToRecord: _absentBeforeAuto, ...legacyVoice } = getDefaultVoiceSettings() + const load = (voice: Record, marked: boolean) => { + const settings = normalizeLegacyProfile({ + voiceDictationModeDefaultedToAuto: marked ? true : undefined, + voice: { ...legacyVoice, ...voice } + }) + return [settings.voice?.dictationMode, settings.voice?.dictationHoldToRecord] + } - const migrated = normalizeLegacyProfile({ ...legacy, voice: voice('toggle') }) - expect(migrated.voice?.dictationMode).toBe('auto') - expect(migrated.voiceDictationModeDefaultedToAuto).toBe(true) - expect(normalizeLegacyProfile({ ...legacy, voice: voice('hold') }).voice?.dictationMode).toBe( - 'hold' - ) - expect( - normalizeLegacyProfile({ voiceDictationModeDefaultedToAuto: true, voice: voice('toggle') }) - .voice?.dictationMode - ).toBe('toggle') + // The old Toggle default becomes Auto; Hold was always a choice. + expect(load({ dictationMode: 'toggle' }, false)).toEqual(['toggle', true]) + expect(load({ dictationMode: 'hold' }, false)[0]).toBe('hold') + // Builds that stored Auto as 'auto', or a Toggle picked there, keep what the user had. + expect(load({ dictationMode: 'auto' }, true)).toEqual(['toggle', true]) + expect(load({ dictationMode: 'toggle' }, true)).toEqual(['toggle', false]) + expect(load({ dictationMode: 'toggle', dictationHoldToRecord: false }, false)).toEqual([ + 'toggle', + false + ]) }) diff --git a/src/main/persistence/loading-store/normalize-loaded-global-settings.ts b/src/main/persistence/loading-store/normalize-loaded-global-settings.ts index b5915fa7007..9f59c279f29 100644 --- a/src/main/persistence/loading-store/normalize-loaded-global-settings.ts +++ b/src/main/persistence/loading-store/normalize-loaded-global-settings.ts @@ -24,6 +24,7 @@ import { readLegacySidekickFlag } from '../applying-settings/onboarding-normaliz import { normalizeMachineName } from '../../../shared/machine-name' import { replaceRetiredSpeechModelId } from '../../speech/model-catalog' import type { PersistedState } from '../../../shared/persisted-state-types' +import type { VoiceSettings } from '../../../shared/speech-types' import type { PreparedLoadedTerminalSettings } from './prepare-loaded-terminal-settings' import type { PreparedLoadedProfileSettings } from './prepare-loaded-profile-settings' @@ -72,15 +73,10 @@ export function normalizeLoadedGlobalSettings( normalizedSourceControlGroupOrder } = profile const pluginOwnedSettings = normalizePluginOwnedSettings(parsed.settings ?? {}) - const voice = { ...getDefaultVoiceSettings(), ...parsed.settings?.voice } - // Stored 'toggle' was everyone's old default, and Auto still toggles on a tap; Hold was always a choice. - const keepsDictationMode = - voice.dictationMode === 'hold' || - voice.dictationMode === 'auto' || - (parsed.settings?.voiceDictationModeDefaultedToAuto === true && - voice.dictationMode === 'toggle') - if (!keepsDictationMode) { - voice.dictationMode = 'auto' + const voice = { + ...getDefaultVoiceSettings(), + ...parsed.settings?.voice, + ...migrateDictationShortcutMode(parsed.settings) } const matchTerminalSidebarInputs = { pluginAppThemeLight: pluginOwnedSettings.pluginAppThemeLight, @@ -197,3 +193,20 @@ export function normalizeLoadedGlobalSettings( voiceDictationModeDefaultedToAuto: true } } + +/** Auto is stored as Toggle plus hold-to-record so builds that only know Toggle and Hold keep working. */ +function migrateDictationShortcutMode( + settings: PersistedState['settings'] | undefined +): Pick { + const stored: { dictationMode?: unknown; dictationHoldToRecord?: unknown } = settings?.voice ?? {} + // Builds from 3d2b0b12812 stored Auto as 'auto'. A 'toggle' saved before the marker was everyone's old default. + const dictationHoldToRecord = + stored.dictationMode === 'auto' || + (typeof stored.dictationHoldToRecord === 'boolean' + ? stored.dictationHoldToRecord + : settings?.voiceDictationModeDefaultedToAuto !== true) + return { + dictationMode: stored.dictationMode === 'hold' ? 'hold' : 'toggle', + dictationHoldToRecord + } +} diff --git a/src/main/runtime/rpc/methods/speech/speech.ts b/src/main/runtime/rpc/methods/speech/speech.ts index 066dc6d5d1f..352dc1357d7 100644 --- a/src/main/runtime/rpc/methods/speech/speech.ts +++ b/src/main/runtime/rpc/methods/speech/speech.ts @@ -35,7 +35,10 @@ export const SPEECH_METHODS = [ runtime.configureMobileDictation({ ...(params.enabled !== undefined ? { enabled: params.enabled } : {}), ...(params.modelId !== undefined ? { modelId: params.modelId } : {}), - ...(params.dictationMode !== undefined ? { dictationMode: params.dictationMode } : {}) + ...(params.dictationMode !== undefined ? { dictationMode: params.dictationMode } : {}), + ...(params.dictationHoldToRecord !== undefined + ? { dictationHoldToRecord: params.dictationHoldToRecord } + : {}) }) }), defineMethod({ diff --git a/src/main/runtime/speech/runtime-mobile-speech-catalog.ts b/src/main/runtime/speech/runtime-mobile-speech-catalog.ts index 71aac4a9c53..ea7841e3525 100644 --- a/src/main/runtime/speech/runtime-mobile-speech-catalog.ts +++ b/src/main/runtime/speech/runtime-mobile-speech-catalog.ts @@ -60,6 +60,7 @@ export class RuntimeMobileSpeechCatalog { enabled: voice.enabled === true, selectedModelId: voice.sttModel ?? '', dictationMode: voice.dictationMode === 'hold' ? 'hold' : 'toggle', + dictationHoldToRecord: voice.dictationHoldToRecord !== false, removeFillerWords: voice.removeFillerWords !== false, models } @@ -101,6 +102,7 @@ export class RuntimeMobileSpeechCatalog { enabled?: boolean modelId?: string dictationMode?: 'toggle' | 'hold' + dictationHoldToRecord?: boolean }): Promise { const store = this.requireWritableStore() const current = store.getSettings().voice ?? getDefaultVoiceSettings() @@ -114,7 +116,10 @@ export class RuntimeMobileSpeechCatalog { ...current, ...(params.enabled !== undefined ? { enabled: params.enabled } : {}), ...(params.modelId !== undefined ? { sttModel: params.modelId } : {}), - ...(params.dictationMode !== undefined ? { dictationMode: params.dictationMode } : {}) + ...(params.dictationMode !== undefined ? { dictationMode: params.dictationMode } : {}), + ...(params.dictationHoldToRecord !== undefined + ? { dictationHoldToRecord: params.dictationHoldToRecord } + : {}) } store.updateSettings?.({ voice: nextVoice }, { notifyListeners: true }) return this.list() diff --git a/src/main/window/createMainWindow-terminal-focus-shortcuts.test.ts b/src/main/window/createMainWindow-terminal-focus-shortcuts.test.ts index a0ac74981ba..d96399190e9 100644 --- a/src/main/window/createMainWindow-terminal-focus-shortcuts.test.ts +++ b/src/main/window/createMainWindow-terminal-focus-shortcuts.test.ts @@ -1,5 +1,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import type { DictationMode } from '../../shared/speech-types' +import type { VoiceSettings } from '../../shared/speech-types' +import { dictationShortcutModeSettings } from '../../shared/dictation-shortcut-mode' vi.mock('electron', async () => (await import('./createMainWindow-test-harness')).electronModuleMock() @@ -60,10 +61,13 @@ describe('createMainWindow', () => { return browserWindowInstance }) - const voice: { enabled: boolean; sttModel: string; dictationMode: DictationMode } = { + const voice: Pick< + VoiceSettings, + 'enabled' | 'sttModel' | 'dictationMode' | 'dictationHoldToRecord' + > = { enabled: false, sttModel: '', - dictationMode: 'toggle' + ...dictationShortcutModeSettings('toggle') } createMainWindow({ getUI: () => ({}) as never, @@ -104,7 +108,7 @@ describe('createMainWindow', () => { webContents.send.mockClear() voice.sttModel = 'test-model' - voice.dictationMode = 'hold' + Object.assign(voice, dictationShortcutModeSettings('hold')) expect(pageForwardsDictation?.()).toBe(false) const holdPreventDefault = vi.fn() windowHandlers['before-input-event']( @@ -114,14 +118,14 @@ describe('createMainWindow', () => { expect(holdPreventDefault).not.toHaveBeenCalled() expect(webContents.send).not.toHaveBeenCalledWith('ui:dictationKeyDown') - voice.dictationMode = 'auto' + Object.assign(voice, dictationShortcutModeSettings('auto')) expect(pageForwardsDictation?.()).toBe(true) const autoPreventDefault = vi.fn() windowHandlers['before-input-event']({ preventDefault: autoPreventDefault }, dictationInput) expect(autoPreventDefault).not.toHaveBeenCalled() expect(webContents.send).not.toHaveBeenCalledWith('ui:dictationKeyDown') - voice.dictationMode = 'toggle' + Object.assign(voice, dictationShortcutModeSettings('toggle')) const composingPreventDefault = vi.fn() windowHandlers['before-input-event']( { preventDefault: composingPreventDefault }, @@ -181,10 +185,13 @@ describe('createMainWindow', () => { return browserWindowInstance }) - const voice: { enabled: boolean; sttModel: string; dictationMode: DictationMode } = { + const voice: Pick< + VoiceSettings, + 'enabled' | 'sttModel' | 'dictationMode' | 'dictationHoldToRecord' + > = { enabled: false, sttModel: '', - dictationMode: 'toggle' + ...dictationShortcutModeSettings('toggle') } createMainWindow( { @@ -232,12 +239,12 @@ describe('createMainWindow', () => { voice.enabled = true voice.sttModel = 'test-model' - voice.dictationMode = 'hold' + Object.assign(voice, dictationShortcutModeSettings('hold')) const holdPreventDefault = triggerDoubleTapShift() expect(holdPreventDefault).not.toHaveBeenCalled() expect(webContents.send).not.toHaveBeenCalledWith('ui:dictationKeyDown') - voice.dictationMode = 'auto' + Object.assign(voice, dictationShortcutModeSettings('auto')) const autoPreventDefault = triggerDoubleTapShift() expect(autoPreventDefault).toHaveBeenCalledTimes(1) expect(webContents.send).toHaveBeenCalledWith('ui:dictationKeyDown') diff --git a/src/main/window/main-window-shortcut-routing.ts b/src/main/window/main-window-shortcut-routing.ts index edb541fffab..ce6f15827eb 100644 --- a/src/main/window/main-window-shortcut-routing.ts +++ b/src/main/window/main-window-shortcut-routing.ts @@ -21,6 +21,7 @@ import type { CreateMainWindowOptions } from './main-window-contracts' import type { MainWindowFocusLifecycle } from './main-window-focus-lifecycle' import { sendResolvedWindowShortcutAction } from './main-window-shortcut-actions' import { isMacAppPasteInput } from './mac-app-paste-input' +import { dictationShortcutMode } from '../../shared/dictation-shortcut-mode' import { nativeChatPromptClaimsShortcut, textInputOwnsComposition, @@ -87,7 +88,7 @@ export function installMainWindowShortcutRouting(args: { if (!voiceSettings?.enabled || textInputOwnsComposition(options.input)) { return false } - const dictationMode = voiceSettings.dictationMode ?? 'auto' + const dictationMode = dictationShortcutMode(voiceSettings) // A double tap has no release to hold, so Auto toggles on it. const toggles = dictationMode === 'toggle' || diff --git a/src/renderer/src/components/dictation/use-dictation-controls.ts b/src/renderer/src/components/dictation/use-dictation-controls.ts index 9a3a09f27da..eb8103010c5 100644 --- a/src/renderer/src/components/dictation/use-dictation-controls.ts +++ b/src/renderer/src/components/dictation/use-dictation-controls.ts @@ -20,7 +20,7 @@ export function useDictationControls( const escCancels = useEffectEvent(() => handlers.escCancels()) // A failed recording stays retryable even after voice is turned off in Settings. const enabled = voice?.enabled === true || phase !== 'idle' - const mainShortcut = voice?.enabled === true && (voice.dictationMode ?? 'auto') !== 'hold' + const mainShortcut = voice?.enabled === true && voice.dictationMode !== 'hold' // Main intercepts Toggle presses and Auto double taps so the chord never reaches xterm. useEffect(() => { diff --git a/src/renderer/src/components/dictation/use-hold-dictation-gesture.test.tsx b/src/renderer/src/components/dictation/use-hold-dictation-gesture.test.tsx index b0ba49397e8..961152c20b4 100644 --- a/src/renderer/src/components/dictation/use-hold-dictation-gesture.test.tsx +++ b/src/renderer/src/components/dictation/use-hold-dictation-gesture.test.tsx @@ -7,6 +7,7 @@ import type { DictationState } from '../../../../shared/speech-types' import type { GlobalSettings } from '../../../../shared/global-settings-types' import { getDefaultSettings, getDefaultVoiceSettings } from '../../../../shared/constants' import { useHoldDictationGesture } from './use-hold-dictation-gesture' +import { dictationShortcutModeSettings } from '../../../../shared/dictation-shortcut-mode' const originalUserAgent = navigator.userAgent @@ -29,7 +30,12 @@ function holdSettings(): GlobalSettings { return { ...getDefaultSettings('/home/test'), terminalShortcutPolicy, - voice: { ...getDefaultVoiceSettings(), enabled: true, sttModel: 'test-model', dictationMode } + voice: { + ...getDefaultVoiceSettings(), + enabled: true, + sttModel: 'test-model', + ...dictationShortcutModeSettings(dictationMode) + } } } diff --git a/src/renderer/src/components/dictation/use-hold-dictation-gesture.ts b/src/renderer/src/components/dictation/use-hold-dictation-gesture.ts index efdec56f33c..42d29175ea1 100644 --- a/src/renderer/src/components/dictation/use-hold-dictation-gesture.ts +++ b/src/renderer/src/components/dictation/use-hold-dictation-gesture.ts @@ -7,6 +7,7 @@ import { } from '../../../../shared/keybindings' import { textInputOwnsComposition } from '../../../../shared/text-input-shortcut-policy' import type { GlobalSettings } from '../../../../shared/global-settings-types' +import { dictationShortcutMode } from '../../../../shared/dictation-shortcut-mode' import { addAppKeyListener, removeAppKeyListener } from '@/lib/app-keyboard-router' import { showTerminalShortcutCaptureNotification } from '@/lib/terminal-shortcut-capture-notification' import { getKeybindingContext } from '../terminal-workspace-model' @@ -125,7 +126,7 @@ export function useHoldDictationGesture({ stopDictation }: HoldDictationGestureOptions): void { const activeHoldRef = useRef(null) - const mode = settings?.voice?.dictationMode ?? 'auto' + const mode = dictationShortcutMode(settings?.voice) const enabled = settings?.voice?.enabled === true // Settings and keybinding refreshes re-create these inputs; re-running the effect would end a held dictation. const start = useEffectEvent(() => void startDictation()) diff --git a/src/renderer/src/components/settings/voice/VoiceDictationSettingsSection.tsx b/src/renderer/src/components/settings/voice/VoiceDictationSettingsSection.tsx index aa7f7fa85a2..9edcdec2532 100644 --- a/src/renderer/src/components/settings/voice/VoiceDictationSettingsSection.tsx +++ b/src/renderer/src/components/settings/voice/VoiceDictationSettingsSection.tsx @@ -1,4 +1,8 @@ import type { VoiceSettings } from '../../../../../shared/speech-types' +import { + dictationShortcutMode, + dictationShortcutModeSettings +} from '../../../../../shared/dictation-shortcut-mode' import { Label } from '../../ui/label' import { Separator } from '../../ui/separator' import { Switch } from '../../ui/switch' @@ -21,6 +25,7 @@ export function VoiceDictationSettingsSection({ }: VoiceDictationSettingsSectionProps): React.JSX.Element { const t = useTranslate() const shortcutLabel = useShortcutLabel('voice.dictation') + const selectedMode = dictationShortcutMode(voiceSettings) const modeLabels = { auto: t('auto.components.settings.VoicePane.dictationModeAuto', 'Auto'), hold: t('auto.components.settings.VoicePane.174da92062', 'Hold'), @@ -69,10 +74,10 @@ export function VoiceDictationSettingsSection({ {(['auto', 'hold', 'toggle'] as const).map((mode) => (