Add auto-paste user toggle#16
Conversation
Agent-Id: agent-ccd5997d-22eb-4fb4-bf2f-c45d4b11c2c0
📝 WalkthroughWalkthroughAdds a persisted auto-paste toggle to AppState and Settings, threads a PermissionManager into TranscriptionService, and conditions transcription delivery to call copyAndPasteIfPossible when auto-paste is enabled and accessibility permission is available, otherwise falling back to copyToClipboard. Changes
Sequence DiagramsequenceDiagram
actor User
participant Settings as "Settings UI"
participant AppState
participant UserDefaults
participant Transcription as "TranscriptionService"
participant Permission as "PermissionManager"
participant Clipboard as "ClipboardManager / System"
User->>Settings: Toggle Auto-paste
Settings->>AppState: set autoPasteEnabled
AppState->>UserDefaults: persist autoPasteEnabled
User->>Transcription: trigger transcription
Transcription->>AppState: read autoPasteEnabled
alt autoPasteEnabled == true
Transcription->>Permission: accessibilityPermissionState(reason)
Permission-->>Transcription: hasAccessibilityPermission
alt permission granted
Transcription->>Clipboard: copyAndPasteIfPossible(transcript)
else permission denied
Transcription->>Clipboard: copyToClipboard(transcript)
end
else autoPasteEnabled == false
Transcription->>Clipboard: copyToClipboard(transcript)
end
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
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: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@dhavnii/Features/Transcription/TranscriptionService.swift`:
- Around line 231-234: The call to ClipboardManager.copyAndPasteIfPossible in
TranscriptionService is passing a non-existent parameter
hasAccessibilityPermission; update the invocation to match the method signature
by removing the second argument so only the transcription string is passed
(i.e., call copyAndPasteIfPossible(transcription)); reference:
ClipboardManager.copyAndPasteIfPossible, transcription,
hasAccessibilityPermission.
- Around line 34-42: TranscriptionService's initializer now requires a
permissionManager parameter; update the place that constructs the service (the
let service = TranscriptionService(...) call) to pass the existing
permissionManager variable as permissionManager: permissionManager alongside
appState and selectedProvider so the call matches internal
init(appState:permissionManager:selectedProvider:) and compiles.
- Around line 227-237: The auto-paste branch is calling a non-existent
permissionManager.accessibilityPermissionState(for:) and passing an extra
parameter to clipboardManager.copyAndPasteIfPossible(_:); remove the permission
check and call clipboardManager.copyAndPasteIfPossible(transcription) directly
when appState.autoPasteEnabled is true (fall back to
clipboardManager.copyToClipboard(transcription) in the else branch), and delete
the unused permissionManager.accessibilityPermissionState(...) invocation so the
code uses the existing hasAccessibilityPermission logic inside
copyAndPasteIfPossible.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 181c3273-cc42-4c22-8a6a-bb186e28332c
📒 Files selected for processing (3)
dhavnii/App/AppState.swiftdhavnii/Features/Settings/SettingsView.swiftdhavnii/Features/Transcription/TranscriptionService.swift
Agent-Id: agent-9f4e06c6-7785-477e-b5ab-fa6d7af53e47
Agent-Id: agent-ccd5997d-22eb-4fb4-bf2f-c45d4b11c2c0
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
dhavnii/Features/Clipboard/ClipboardManager.swift (1)
69-80: BypassesPermissionManagerby callingAXIsProcessTrusted()directly.
PermissionManagerwas enhanced withaccessibilityPermissionState(for:)to provide cached permission state with logging, but this code callsAXIsProcessTrusted()directly. This:
- Misses the debouncing/caching logic in
PermissionManager- Produces duplicate logging (here and in
PermissionManager)- Could report different state than what
PermissionManager.hasAccessibilityPermissionshowsConsider injecting
PermissionManagerintoClipboardManagerand usingpermissionManager.accessibilityPermissionState(for: "auto-paste")instead.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dhavnii/Features/Clipboard/ClipboardManager.swift` around lines 69 - 80, Replace the direct AXIsProcessTrusted() call in ClipboardManager with the injected PermissionManager: add a PermissionManager property to ClipboardManager, call permissionManager.accessibilityPermissionState(for: "auto-paste") to obtain the cached state (instead of AXIsProcessTrusted()), use that state's granted flag for the guard check, and remove the duplicate print logging so only PermissionManager handles accessibility logging; update any uses of the local hasAccessibilityPermission variable to use the permission state returned by accessibilityPermissionState(for:).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@dhavnii/Features/Permissions/PermissionManager.swift`:
- Around line 244-250: The method accessibilityPermissionState(for:) is
unused—either delete it or make ClipboardManager use it instead of calling
AXIsProcessTrusted() directly; to keep a single source of truth, update
ClipboardManager to call PermissionManager.accessibilityPermissionState(for:
"ClipboardManager") (or the instance method on your PermissionManager object)
and remove the direct AXIsProcessTrusted() usage, ensuring any logging/behaviour
still references hasAccessibilityPermission, lastAccessibilityState and
isMonitoring for consistency.
---
Nitpick comments:
In `@dhavnii/Features/Clipboard/ClipboardManager.swift`:
- Around line 69-80: Replace the direct AXIsProcessTrusted() call in
ClipboardManager with the injected PermissionManager: add a PermissionManager
property to ClipboardManager, call
permissionManager.accessibilityPermissionState(for: "auto-paste") to obtain the
cached state (instead of AXIsProcessTrusted()), use that state's granted flag
for the guard check, and remove the duplicate print logging so only
PermissionManager handles accessibility logging; update any uses of the local
hasAccessibilityPermission variable to use the permission state returned by
accessibilityPermissionState(for:).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a48252c8-c082-4a71-a5c0-98ac920d123c
📒 Files selected for processing (4)
dhavnii/Features/Clipboard/ClipboardManager.swiftdhavnii/Features/Permissions/PermissionManager.swiftdhavnii/Features/Transcription/TranscriptionService.swiftopenwispher/openwispherApp.swift
🚧 Files skipped from review as they are similar to previous changes (1)
- dhavnii/Features/Transcription/TranscriptionService.swift
| internal func accessibilityPermissionState(for reason: String) -> Bool { | ||
| let trusted = hasAccessibilityPermission | ||
| print( | ||
| "🔓 Accessibility permission queried for \(reason): cached=\(trusted), lastKnown=\(lastAccessibilityState), monitoring=\(isMonitoring)" | ||
| ) | ||
| return trusted | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Check if accessibilityPermissionState is used anywhere in the codebase
echo "=== Searching for usages of accessibilityPermissionState ==="
rg -n "accessibilityPermissionState" --type swift
echo ""
echo "=== Searching for direct AXIsProcessTrusted calls outside PermissionManager ==="
rg -n "AXIsProcessTrusted" --type swift -g '!*PermissionManager*'Repository: maker-or/openwispher
Length of output: 454
Remove unused method or update ClipboardManager to use it.
The method accessibilityPermissionState(for:) is never called anywhere in the codebase. Meanwhile, ClipboardManager.swift at line 70 calls AXIsProcessTrusted() directly instead of using this centralized method. Either remove the dead code or update ClipboardManager to use the new method for consistency.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@dhavnii/Features/Permissions/PermissionManager.swift` around lines 244 - 250,
The method accessibilityPermissionState(for:) is unused—either delete it or make
ClipboardManager use it instead of calling AXIsProcessTrusted() directly; to
keep a single source of truth, update ClipboardManager to call
PermissionManager.accessibilityPermissionState(for: "ClipboardManager") (or the
instance method on your PermissionManager object) and remove the direct
AXIsProcessTrusted() usage, ensuring any logging/behaviour still references
hasAccessibilityPermission, lastAccessibilityState and isMonitoring for
consistency.
Agent-Id: agent-ccd5997d-22eb-4fb4-bf2f-c45d4b11c2c0
Summary by CodeRabbit