feat: add setting to keep transcript in clipboard after pasting#107
feat: add setting to keep transcript in clipboard after pasting#107HNKNTA wants to merge 2 commits intoamicalhq:mainfrom
Conversation
Add a "Keep transcript in clipboard" toggle to Advanced Settings that skips restoring the original clipboard contents after dictation paste, leaving the transcribed text available for subsequent manual pastes. Addresses issue amicalhq#100.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new user preference to optionally retain transcribed text in the clipboard after pasting; updates schema, default settings, migrations, UI, settings service, recording logic, type defs, and native paste implementations for macOS and Windows to respect the flag. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant SettingsUI as Settings UI
participant SettingsService as Settings Service
participant RecordingMgr as Recording Manager
participant NativeBridge as Native Bridge (macOS/Windows)
participant Clipboard as System Clipboard
User->>SettingsUI: Toggle "Keep Transcript in Clipboard"
SettingsUI->>SettingsService: updatePreferences(keepTranscriptInClipboard)
SettingsService-->>SettingsUI: ack
Note over RecordingMgr,SettingsService: Later: user requests paste
RecordingMgr->>SettingsService: getPreferences()
SettingsService-->>RecordingMgr: preferences (keepTranscriptInClipboard)
RecordingMgr->>NativeBridge: pasteText(transcript, keepInClipboard)
rect rgba(100, 150, 255, 0.5)
Note over NativeBridge,Clipboard: keepInClipboard = true
NativeBridge->>Clipboard: Paste transcribed text (do not restore)
end
rect rgba(100, 200, 150, 0.5)
Note over NativeBridge,Clipboard: keepInClipboard = false
NativeBridge->>Clipboard: Paste transcribed text
NativeBridge->>NativeBridge: Schedule restore original clipboard content
end
Clipboard-->>User: Clipboard updated
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/desktop/src/main/managers/recording-manager.ts (1)
773-804:⚠️ Potential issue | 🟠 MajorDo not block paste when preference lookup fails.
A failure reading preferences currently aborts paste. This creates a functional regression under transient settings/DB errors. Fallback to
falseand continue pasting.💡 Proposed fix
try { const nativeBridge = this.serviceManager.getService("nativeBridge"); - const settingsService = - this.serviceManager.getService("settingsService"); - const preferences = await settingsService.getPreferences(); - const keepInClipboard = - preferences?.keepTranscriptInClipboard ?? false; + let keepInClipboard = false; + try { + const settingsService = + this.serviceManager.getService("settingsService"); + const preferences = await settingsService.getPreferences(); + keepInClipboard = preferences?.keepTranscriptInClipboard ?? false; + } catch (error) { + logger.main.warn( + "Failed to load keepTranscriptInClipboard, using default=false", + { error: error instanceof Error ? error.message : String(error) }, + ); + } logger.main.info("Pasting transcription to active application", { textLength: transcription.length, keepInClipboard, }); if (nativeBridge) { void nativeBridge .call("pasteText", { transcript: transcription, keepInClipboard, })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/main/managers/recording-manager.ts` around lines 773 - 804, The current preference lookup via settingsService.getPreferences() can throw and abort the paste; change the flow in the paste routine in recording-manager (around serviceManager.getService("settingsService") and getPreferences()) to catch errors from getPreferences() separately, log a warning, and fall back to keepInClipboard = false so the paste still proceeds; ensure you still call nativeBridge.call("pasteText", { transcript: transcription, keepInClipboard }) and preserve the existing error handling for nativeBridge.call failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/desktop/src/renderer/main/pages/settings/advanced/index.tsx`:
- Around line 63-73: The mutation handler updatePreferencesMutation currently
logs and shows a toast on error but doesn't revert optimistic UI changes; update
the onError callback in updatePreferencesMutation (and the other mutation at
lines ~149-154) to either refetch the preference cache via
utils.settings.getPreferences.invalidate() or explicitly roll back the local
toggle state used by the settings page component (the state/handler that flips
the switch) so the switch reflects the server value after a failed update;
ensure the rollback runs before showing the error toast to keep the UI
consistent.
In `@packages/native-helpers/windows-helper/src/RpcHandler.cs`:
- Around line 309-310: The current RPC handler calls
accessibilityService.PasteText(parameters.Transcript, keepInClipboard, out var
errorMessage) and always returns the fixed string "Pasted successfully", which
discards any non-fatal warning in errorMessage; update the response creation in
the method that handles the PasteText RPC (RpcHandler.cs) to surface
errorMessage when it is non-empty even if success==true—e.g., append or include
the warning text in the success message or add an explicit warning field in the
response object—so when parameters.KeepInClipboard is false and restore fails
the client sees the warning instead of losing the errorMessage.
---
Outside diff comments:
In `@apps/desktop/src/main/managers/recording-manager.ts`:
- Around line 773-804: The current preference lookup via
settingsService.getPreferences() can throw and abort the paste; change the flow
in the paste routine in recording-manager (around
serviceManager.getService("settingsService") and getPreferences()) to catch
errors from getPreferences() separately, log a warning, and fall back to
keepInClipboard = false so the paste still proceeds; ensure you still call
nativeBridge.call("pasteText", { transcript: transcription, keepInClipboard })
and preserve the existing error handling for nativeBridge.call failures.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
packages/native-helpers/windows-helper/src/Models/Generated/Models.csis excluded by!**/generated/**
📒 Files selected for processing (15)
apps/desktop/src/db/app-settings.tsapps/desktop/src/db/schema.tsapps/desktop/src/db/settings-migrations/index.tsapps/desktop/src/i18n/locales/en.jsonapps/desktop/src/i18n/locales/es.jsonapps/desktop/src/i18n/locales/ja.jsonapps/desktop/src/main/managers/recording-manager.tsapps/desktop/src/renderer/main/pages/settings/advanced/index.tsxapps/desktop/src/services/settings-service.tsapps/desktop/src/trpc/routers/settings.tspackages/native-helpers/swift-helper/Sources/SwiftHelper/AccessibilityService.swiftpackages/native-helpers/swift-helper/Sources/SwiftHelper/RpcHandler.swiftpackages/native-helpers/windows-helper/src/RpcHandler.cspackages/native-helpers/windows-helper/src/Services/AccessibilityService.cspackages/types/src/schemas/methods/paste-text.ts
… paste warnings Invalidate preferences query cache on updatePreferencesMutation error so the toggle resyncs to the server value. Also fix Windows RPC handler to surface clipboard restore warnings instead of discarding them when paste succeeds with a non-fatal error.
Add a "Keep transcript in clipboard" toggle to Advanced Settings that skips restoring the original clipboard contents after dictation paste, leaving the transcribed text available for subsequent manual pastes.
Addresses issue #100.
Summary by CodeRabbit
New Features
Localization