Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(mobile): hide the keyboard's example instructions during the voice assistant onboarding (#2692)
Chad Pihaa1c1d6bcde47
diff --git a/openwhispr-mobile/modules/app-group-storage/src/index.ts b/openwhispr-mobile/modules/app-group-storage/src/index.tsindex 697076546..9644a4bb4 100644--- a/openwhispr-mobile/modules/app-group-storage/src/index.ts+++ b/openwhispr-mobile/modules/app-group-storage/src/index.ts@@ -300,6 +300,9 @@ export const APP_GROUP_KEYS = {KEYBOARD_AGENT_APPLICABLE: 'keyboard_agent_applicable',KEYBOARD_AGENT_NAME: 'keyboard_agent_name',KEYBOARD_AGENT_SHARE_CONTEXT: 'keyboard_agent_share_context',+ // App → keyboard: hide the example instructions until this time (ms), while onboarding's+ // voice assistant step says what to dictate.+ KEYBOARD_AGENT_HINTS_HIDDEN_UNTIL_MS: 'keyboard_agent_hints_hidden_until_ms',// Agent mode — one-shot / per-job keys (cleared on app launch)KEYBOARD_AGENT_REQUEST: 'keyboard_agent_request',KEYBOARD_AGENT_JOB: 'keyboard_agent_job',diff --git a/openwhispr-mobile/plugins/keyboard-extension/ios/KeyboardViewController.swift b/openwhispr-mobile/plugins/keyboard-extension/ios/KeyboardViewController.swiftindex 2f94780a3..6b6347479 100644--- a/openwhispr-mobile/plugins/keyboard-extension/ios/KeyboardViewController.swift+++ b/openwhispr-mobile/plugins/keyboard-extension/ios/KeyboardViewController.swift@@ -696,6 +696,11 @@ final class KeyboardViewController: UIInputViewController, UIGestureRecognizerDe"Make it shorter",]private var agentRecordingHint: String?++ // An example to say, unless the app's own walkthrough is telling the user what to say.+ private func agentHint(from hints: [String]) -> String? {+ KeyboardHandoffProvider.shared.agentHintsHidden() ? nil : hints.randomElement()+ }private var isAgentGenerating = falseprivate var waitForAgentResultTimer: Timer?private var agentReviewNoteResetTimer: Timer?@@ -1553,7 +1558,7 @@ final class KeyboardViewController: UIInputViewController, UIGestureRecognizerDe// Deep-link/recovery starts never pass through the tap handlers, so pick// (and stash) a hint lazily here.if agentRecordingHint == nil {- agentRecordingHint = Self.agentComposeHints.randomElement()+ agentRecordingHint = agentHint(from: Self.agentComposeHints)}recordingCaptionLabel.text = agentRecordingHint.map { "\u{201C}\($0)\u{201D}" } ?? "Listening"recordingHeaderLabel.text = agentRecordingHeaderText@@ -3096,7 +3101,7 @@ final class KeyboardViewController: UIInputViewController, UIGestureRecognizerDe// so the user knows the instruction will rewrite that text. Degrade silently// when selectedText is nil (most third-party apps don't expose it).let selectionCaption: String? = (selectedText?.isEmpty == false) ? "Rewriting Selection" : nil- agentRecordingHint = Self.agentComposeHints.randomElement()+ agentRecordingHint = agentHint(from: Self.agentComposeHints)if recordsInPlace {isAgentRecordingActive = true@@ -3938,7 +3943,7 @@ final class KeyboardViewController: UIInputViewController, UIGestureRecognizerDeisAgentActionInFlight = trueisAgentRecordingActive = truehideAgentReviewCard(clearState: false)- agentRecordingHint = Self.agentFollowUpHints.randomElement()+ agentRecordingHint = agentHint(from: Self.agentFollowUpHints)startAgentRecordingInPlace(caption: "Describe your changes")}@@ -4072,6 +4077,7 @@ private struct KeyboardHandoffProvider {private let agentResultKey = "keyboard_agent_result"private let agentActionKey = "keyboard_agent_action"private let agentActionAtMsKey = "keyboard_agent_action_at_ms"+ private let agentHintsHiddenUntilMsKey = "keyboard_agent_hints_hidden_until_ms"static let toneValues = ["default", "formal", "casual", "very_casual", "excited"]private static var darwinStartNotificationName: String {"\(resolvedContainingAppBundleID).startRecording"@@ -4209,6 +4215,15 @@ private struct KeyboardHandoffProvider {return trimmed.isEmpty ? "your agent" : trimmed}+ /// The app hides the example instructions until this deadline while its own walkthrough says+ /// what to dictate (onboarding's voice assistant step). A deadline, so a step the app never left+ /// (killed mid-onboarding) stops hiding them on its own.+ func agentHintsHidden() -> Bool {+ guard let raw = UserDefaults(suiteName: appGroupId)?.string(forKey: agentHintsHiddenUntilMsKey),+ let untilMs = Double(raw) else { return false }+ return Date().timeIntervalSince1970 * 1000 < untilMs+ }+/// True when the app has written its heartbeat within the last 5s (same rule/// used for recording-active). While the agent is generating, a stale/missing/// heartbeat means the app process died mid-job and no result is coming.diff --git a/openwhispr-mobile/src/lib/__tests__/keyboardAgentSync.test.ts b/openwhispr-mobile/src/lib/__tests__/keyboardAgentSync.test.tsindex a99c7cdfb..482079345 100644--- a/openwhispr-mobile/src/lib/__tests__/keyboardAgentSync.test.ts+++ b/openwhispr-mobile/src/lib/__tests__/keyboardAgentSync.test.ts@@ -7,6 +7,7 @@ import {writeKeyboardAgentResult,consumeKeyboardAgentAction,isKeyboardAgentCancelled,+ hideKeyboardAgentHints,} from '@/lib/keyboardAgentSync';import type { KeyboardAgentJob, KeyboardAgentResult } from '@/lib/keyboardAgentSync';import { useConfigStore } from '@/store/useConfigStore';@@ -36,12 +37,23 @@ jest.mock('../../../modules/app-group-storage/src', () => ({KEYBOARD_AGENT_RESULT: 'keyboard_agent_result',KEYBOARD_AGENT_ACTION: 'keyboard_agent_action',KEYBOARD_AGENT_ACTION_AT_MS: 'keyboard_agent_action_at_ms',+ KEYBOARD_AGENT_HINTS_HIDDEN_UNTIL_MS: 'keyboard_agent_hints_hidden_until_ms',KEYBOARD_CANCEL_REQUESTED: 'keyboard_cancel_requested',},}));+let mockAppStateListener: ((state: string) => void) | undefined;jest.mock('react-native', () => ({- AppState: { addEventListener: () => ({ remove: () => {} }) },+ AppState: {+ addEventListener: (_type: string, listener: (state: string) => void) => {+ mockAppStateListener = listener;+ return {+ remove: () => {+ if (mockAppStateListener === listener) mockAppStateListener = undefined;+ },+ };+ },+ },}));jest.mock('@/services/storage/StorageService', () => ({@@ -564,3 +576,38 @@ describe('isKeyboardAgentCancelled', () => {expect(store.keyboard_cancel_requested).toBe('0');});});++// ─── Example instructions ─────────────────────────────────────────────────────++// Onboarding's voice assistant step says what to dictate, so the keyboard hides its own examples.+describe('hideKeyboardAgentHints', () => {+ afterEach(() => {+ jest.restoreAllMocks();+ });++ it('hides them for 15 minutes, so a step the app never left stops on its own', () => {+ jest.spyOn(Date, 'now').mockReturnValue(1_000_000);+ hideKeyboardAgentHints();+ expect(store.keyboard_agent_hints_hidden_until_ms).toBe(String(1_000_000 + 15 * 60_000));+ });++ it('renews the deadline when the app comes back to the foreground', () => {+ const now = jest.spyOn(Date, 'now').mockReturnValue(1_000_000);+ const show = hideKeyboardAgentHints();+ now.mockReturnValue(2_000_000);+ mockAppStateListener?.('background');+ expect(store.keyboard_agent_hints_hidden_until_ms).toBe(String(1_000_000 + 15 * 60_000));+ mockAppStateListener?.('active');+ expect(store.keyboard_agent_hints_hidden_until_ms).toBe(String(2_000_000 + 15 * 60_000));+ show();+ });++ it('shows them again when the step is left, and stops renewing', () => {+ const show = hideKeyboardAgentHints();+ expect(store.keyboard_agent_hints_hidden_until_ms).toBeDefined();+ show();+ expect(store.keyboard_agent_hints_hidden_until_ms).toBeUndefined();+ mockAppStateListener?.('active');+ expect(store.keyboard_agent_hints_hidden_until_ms).toBeUndefined();+ });+});diff --git a/openwhispr-mobile/src/lib/keyboardAgentSync.ts b/openwhispr-mobile/src/lib/keyboardAgentSync.tsindex 3ae7852af..c0763f88a 100644--- a/openwhispr-mobile/src/lib/keyboardAgentSync.ts+++ b/openwhispr-mobile/src/lib/keyboardAgentSync.ts@@ -19,6 +19,10 @@ const MAX_PAYLOAD_CHARS = 8_000; // ~8 KB total safety budgetconst FRESH_REQUEST_TTL_MS = 15_000;+// A deadline rather than a flag, so a step the app never left (killed mid-onboarding) stops+// hiding the keyboard's example instructions on its own.+const AGENT_HINTS_HIDDEN_TTL_MS = 15 * 60_000;+export interface KeyboardAgentRequest {kind: 'compose' | 'follow_up';sessionId?: string;@@ -213,6 +217,30 @@ export function clearKeyboardAgentJob(): void {AppGroupStorage.removeItem(APP_GROUP_KEYS.KEYBOARD_AGENT_JOB);}+// Onboarding's voice assistant step tells the user what to say, so the keyboard's example+// instruction would contradict it. Hides the examples; the returned function shows them again.+// The deadline is renewed whenever the app comes back to the foreground, so a user who leaves+// the step open past it doesn't get examples back.+export function hideKeyboardAgentHints(): () => void {+ const renewDeadline = (): void => {+ AppGroupStorage.setItem(+ APP_GROUP_KEYS.KEYBOARD_AGENT_HINTS_HIDDEN_UNTIL_MS,+ String(Date.now() + AGENT_HINTS_HIDDEN_TTL_MS),+ );+ };+ renewDeadline();+ const appStateSub = AppState.addEventListener('change', (state) => {+ if (state === 'active') {+ renewDeadline();+ }+ });++ return (): void => {+ appStateSub.remove();+ AppGroupStorage.removeItem(APP_GROUP_KEYS.KEYBOARD_AGENT_HINTS_HIDDEN_UNTIL_MS);+ };+}+// The draft the keyboard's card opens on, picked as its readAgentResult picks it: the active// version, the first without one, clamped to the list. It is written before agent_ready, so a// listener for that status reads the new one.diff --git a/openwhispr-mobile/src/screens/onboarding/steps/VoiceAgentStep.tsx b/openwhispr-mobile/src/screens/onboarding/steps/VoiceAgentStep.tsxindex a84d98e10..8bb99c2dc 100644--- a/openwhispr-mobile/src/screens/onboarding/steps/VoiceAgentStep.tsx+++ b/openwhispr-mobile/src/screens/onboarding/steps/VoiceAgentStep.tsx@@ -13,7 +13,7 @@ import { useOnboardingPracticeMode } from '@/hooks/useOnboardingPracticeMode';import { useOnboardingStep } from '@/hooks/useOnboardingStep';import { BRAND } from '@/config/colors';import { AppFont } from '@/lib/fonts';-import { readKeyboardAgentDraft } from '@/lib/keyboardAgentSync';+import { hideKeyboardAgentHints, readKeyboardAgentDraft } from '@/lib/keyboardAgentSync';import { safeHaptics } from '@/lib/utils';import { useAuthStore } from '@/store/useAuthStore';import { hasRealAccountHistory } from '@/sync/syncIdentity';@@ -94,6 +94,9 @@ export function VoiceAgentStep(): ReactElement {safeHaptics(phase === 'done' ? 'success' : 'light');}, [phase, draftText, pulse]);+ // The card says what to dictate, so the keyboard's own example instruction would contradict it.+ useEffect(() => hideKeyboardAgentHints(), []);+useEffect(() => {const subscription = addKeyboardStatusChangedListener((event) => {if (event.status === 'recording') {diff --git a/openwhispr-mobile/src/screens/onboarding/steps/__tests__/VoiceAgentStep.test.tsx b/openwhispr-mobile/src/screens/onboarding/steps/__tests__/VoiceAgentStep.test.tsxindex 26401edf9..061c742fe 100644--- a/openwhispr-mobile/src/screens/onboarding/steps/__tests__/VoiceAgentStep.test.tsx+++ b/openwhispr-mobile/src/screens/onboarding/steps/__tests__/VoiceAgentStep.test.tsx@@ -29,7 +29,12 @@ jest.mock('../../../../../modules/app-group-storage/src', () => ({},}));let mockDraft: string | null = null;-jest.mock('@/lib/keyboardAgentSync', () => ({ readKeyboardAgentDraft: () => mockDraft }));+const mockShowAgentHints = jest.fn();+const mockHideAgentHints = jest.fn(() => mockShowAgentHints);+jest.mock('@/lib/keyboardAgentSync', () => ({+ readKeyboardAgentDraft: () => mockDraft,+ hideKeyboardAgentHints: () => mockHideAgentHints(),+}));const mockNext = jest.fn();const mockBack = jest.fn();jest.mock('@/hooks/useOnboardingStep', () => ({@@ -101,6 +106,15 @@ it('starts by pointing to the agent button on the keyboard', () => {expect(screen.queryByText('Example request')).toBeNull();});+// The card says what to dictate, so the keyboard's example instruction would contradict it.+it("hides the keyboard's example instructions while the step is open", () => {+ const screen = render(<VoiceAgentStep />);+ expect(mockHideAgentHints).toHaveBeenCalledTimes(1);+ expect(mockShowAgentHints).not.toHaveBeenCalled();+ screen.unmount();+ expect(mockShowAgentHints).toHaveBeenCalledTimes(1);+});+it('says what the agent does in one line', () => {const screen = render(<VoiceAgentStep />);expect(screen.getByText('Say what you need, and it writes it for you in any app.')).toBeTruthy();