fix(dictation): store Auto as Toggle plus hold-to-record so older builds keep a working shortcut

This commit is contained in:
Kelvin Amoaba
2026-11-09 08:57:06 +00:00
parent c323f876b8
commit d31f03499f
32 changed files with 213 additions and 59 deletions
@@ -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)
@@ -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<MobileSpeechSetup> {
const reply = await dictationConfigWrite.request(client, params)
return interpretOrThrowRefusalMessage(
+2
View File
@@ -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",
+2
View File
@@ -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…"
+2
View File
@@ -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",
+2
View File
@@ -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",
+2
View File
@@ -2843,6 +2843,8 @@
"dictationHeading": "ディクテーション",
"dictationMode": "ディクテーションモード",
"dictationModeDescription": "トグル:1 回押すと開始し、もう一度押すと停止します。ホールド:押している間だけ音声入力します。",
"dictationModeWithAutoDescription": "自動:タップで開始と停止。コンピュータではショートカットを押し続けると離すまで録音します。ホールド:押している間だけ音声入力します。トグル:1 回押すと開始し、もう一度押すと停止します。",
"autoMode": "自動",
"downloadFailed": "ダウンロードに失敗しました",
"enableDictation": "音声ディクテーションを有効にする",
"holdMode": "ホールド",
+2
View File
@@ -2843,6 +2843,8 @@
"dictationHeading": "받아쓰기",
"dictationMode": "받아쓰기 모드",
"dictationModeDescription": "토글: 한 번 누르면 받아쓰기를 시작하고, 다시 누르면 중지합니다. 길게 누르기: 누르고 있는 동안 받아쓰기합니다.",
"dictationModeWithAutoDescription": "자동: 탭하여 시작하고 중지합니다. 컴퓨터에서는 단축키를 길게 누르면 손을 뗄 때까지 녹음합니다. 길게 누르기: 누르고 있는 동안 받아쓰기합니다. 토글: 한 번 누르면 시작하고, 다시 누르면 중지합니다.",
"autoMode": "자동",
"downloadFailed": "다운로드 실패",
"enableDictation": "음성 받아쓰기 활성화",
"holdMode": "길게 누르기",
+2
View File
@@ -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",
+2
View File
@@ -2995,6 +2995,8 @@
"dictationHeading": "ДИКТОВКА",
"dictationMode": "Режим диктовки",
"dictationModeDescription": "Переключение: нажмите один раз, чтобы начать, ещё раз — чтобы остановить. Удержание: диктуйте, пока удерживаете кнопку.",
"dictationModeWithAutoDescription": "Авто: нажмите, чтобы начать и остановить; на компьютере удержание сочетания клавиш записывает до отпускания. Удержание: диктуйте, пока удерживаете кнопку. Переключение: нажмите один раз, чтобы начать, ещё раз — чтобы остановить.",
"autoMode": "Авто",
"downloadFailed": "Не удалось скачать",
"enableDictation": "Включить голосовую диктовку",
"holdMode": "Удержание",
+2
View File
@@ -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",
+2
View File
@@ -2843,6 +2843,8 @@
"dictationHeading": "聽寫",
"dictationMode": "聽寫模式",
"dictationModeDescription": "切換:按一次開始,再按一次停止。按住:按住期間進行聽寫。",
"dictationModeWithAutoDescription": "自動:輕按開始和停止;在電腦上按住快捷鍵會一直錄音,直到放開。按住:按住期間進行聽寫。切換:按一次開始,再按一次停止。",
"autoMode": "自動",
"downloadFailed": "下載失敗",
"enableDictation": "啟用語音聽寫",
"holdMode": "按住",
+2
View File
@@ -2843,6 +2843,8 @@
"dictationHeading": "听写",
"dictationMode": "听写模式",
"dictationModeDescription": "切换:按一次开始,再按一次停止。按住:按住期间进行听写。",
"dictationModeWithAutoDescription": "自动:轻按开始和停止;在电脑上按住快捷键会一直录音,直到松开。按住:按住期间进行听写。切换:按一次开始,再按一次停止。",
"autoMode": "自动",
"downloadFailed": "下载失败",
"enableDictation": "启用语音听写",
"holdMode": "按住",
@@ -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,
@@ -6,6 +6,7 @@ export interface VoiceSettingsOperations {
enabled?: boolean
modelId?: string
dictationMode?: 'toggle' | 'hold'
dictationHoldToRecord?: boolean
}): Promise<MobileSpeechSetup>
download(modelId: string): Promise<void>
delete(modelId: string): Promise<MobileSpeechSetup>
+30 -14
View File
@@ -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.'
)
}
>
<ListRow
key="enabled"
@@ -329,9 +345,9 @@ export default function VoiceSettingsScreen({
disabled={!enabled}
accessory={
<MobileSegmentedControl
segments={dictationModes(t)}
selected={setup.dictationMode}
onSelect={(dictationMode) => void configure({ dictationMode })}
segments={dictationModes(t, offersAuto)}
selected={offersAuto ? dictationShortcutMode(setup) : setup.dictationMode}
onSelect={(mode) => void configure(dictationShortcutModeSettings(mode))}
testIDPrefix="voice-mode-"
disabled={!enabled}
/>
@@ -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<string, unknown>, 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
])
})
@@ -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<VoiceSettings, 'dictationMode' | 'dictationHoldToRecord'> {
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
}
}
@@ -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({
@@ -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<RuntimeSpeechSetupState> {
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()
@@ -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')
@@ -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' ||
@@ -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(() => {
@@ -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)
}
}
}
@@ -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<ActiveHold | null>(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())
@@ -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) => (
<button
key={mode}
onClick={() => onUpdateVoiceSettings({ dictationMode: mode })}
onClick={() => onUpdateVoiceSettings(dictationShortcutModeSettings(mode))}
disabled={!voiceSettings.enabled}
className={`rounded-sm px-3 py-1 text-sm transition-colors ${
voiceSettings.dictationMode === mode
selectedMode === mode
? 'bg-accent font-medium text-accent-foreground'
: 'text-muted-foreground hover:text-foreground'
} ${!voiceSettings.enabled ? 'opacity-50 cursor-not-allowed' : ''}`}
@@ -86,6 +86,7 @@ export function installBrowserLinkMaterializationProbe() {
modelsDir: '',
dictationLanguage: 'auto',
dictationMode: 'hold',
dictationHoldToRecord: false,
removeFillerWords: true,
terminalConfirmBeforeInsert: true,
userModels: [],
+2 -1
View File
@@ -101,7 +101,8 @@ export function getDefaultVoiceSettings(): VoiceSettings {
sttModel: '',
modelsDir: '',
dictationLanguage: DICTATION_LANGUAGE_AUTO,
dictationMode: 'auto' as const,
dictationMode: 'toggle' as const,
dictationHoldToRecord: true,
removeFillerWords: true,
terminalConfirmBeforeInsert: false,
userModels: [],
+24
View File
@@ -0,0 +1,24 @@
import type { VoiceSettings } from './speech-types'
/** The shortcut's behaviour; Auto is Toggle plus hold-to-record, so builds that only know Toggle still toggle. */
export type DictationShortcutMode = 'auto' | 'hold' | 'toggle'
// Loose so a phone's salvaged host reply reads the same way as stored settings.
type StoredDictationMode = { dictationMode?: string; dictationHoldToRecord?: boolean }
export function dictationShortcutMode(
voice: StoredDictationMode | null | undefined
): DictationShortcutMode {
if (voice?.dictationMode === 'hold') {
return 'hold'
}
return voice?.dictationHoldToRecord === false ? 'toggle' : 'auto'
}
export function dictationShortcutModeSettings(
mode: DictationShortcutMode
): Pick<VoiceSettings, 'dictationMode' | 'dictationHoldToRecord'> {
return mode === 'hold'
? { dictationMode: 'hold', dictationHoldToRecord: false }
: { dictationMode: 'toggle', dictationHoldToRecord: mode === 'auto' }
}
+2 -1
View File
@@ -60,7 +60,8 @@ export const SpeechModelAction = z.object({
export const DictationSetup = z.object({
enabled: z.boolean().optional(),
modelId: OptionalString,
dictationMode: z.enum(['toggle', 'hold']).optional()
dictationMode: z.enum(['toggle', 'hold']).optional(),
dictationHoldToRecord: z.boolean().optional()
})
/** Why the cap: an OpenAI key is ~200 characters; anything far longer is a paste mistake. */
+2
View File
@@ -171,6 +171,8 @@ export type RuntimeSpeechSetupState = {
enabled: boolean
selectedModelId: string
dictationMode: 'toggle' | 'hold'
/** Toggle plus hold-to-record is Auto. Absent from older hosts, which have no Auto. */
dictationHoldToRecord: boolean
/** Phones that recognize speech themselves clean their own text by this switch. */
removeFillerWords: boolean
models: RuntimeSpeechModelSummary[]
+4 -2
View File
@@ -73,8 +73,8 @@ export type UserModelConfig = {
sampleRate?: number
}
// Auto: holding the shortcut records until release, a tap toggles.
export type DictationMode = 'auto' | 'hold' | 'toggle'
// Stays two values so older builds keep working; Auto is Toggle plus dictationHoldToRecord.
export type DictationMode = 'toggle' | 'hold'
export type VoiceSettings = {
enabled: boolean
@@ -83,6 +83,8 @@ export type VoiceSettings = {
/** 'auto' or an ISO-639-1 code. Not `language`: its stored 'en' default never came from the user. */
dictationLanguage: string
dictationMode: DictationMode
/** With Toggle, holding the shortcut records until release (Auto); see dictation-shortcut-mode.ts. */
dictationHoldToRecord: boolean
/** Drops "um", "uh" and their equivalents in the dictation language before text is inserted. */
removeFillerWords: boolean
terminalConfirmBeforeInsert: boolean