diff --git a/WhisperDictate b/WhisperDictate new file mode 100755 index 0000000..c51ea07 Binary files /dev/null and b/WhisperDictate differ diff --git a/macos/src/main.swift b/macos/src/main.swift index ff1a93d..e15c992 100644 --- a/macos/src/main.swift +++ b/macos/src/main.swift @@ -2,6 +2,7 @@ import Cocoa import AVFoundation import Carbon.HIToolbox import ServiceManagement +import ApplicationServices // MARK: - User Defaults Keys struct Defaults { @@ -38,6 +39,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { setupStatusItem() registerHotkey() requestMicrophonePermission() + checkAccessibilityPermission() checkModelExists() NSLog("WhisperDictate started. Press ⌃⌥D to toggle recording.") @@ -248,16 +250,42 @@ class AppDelegate: NSObject, NSApplicationDelegate { AVCaptureDevice.requestAccess(for: .audio) { granted in if !granted { DispatchQueue.main.async { - let alert = NSAlert() - alert.messageText = "Microphone Access Required" - alert.informativeText = "Please enable microphone access in System Settings → Privacy & Security → Microphone" - alert.alertStyle = .warning - alert.runModal() + self.showPermissionAlert( + title: "Microphone Access Required", + message: "WhisperDictate needs microphone access to record your voice.", + settingsURL: "x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone" + ) } } } } + func checkAccessibilityPermission() { + let trusted = AXIsProcessTrusted() + if !trusted { + showPermissionAlert( + title: "Accessibility Access Required", + message: "WhisperDictate needs accessibility access to paste transcribed text into other apps.", + settingsURL: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility" + ) + } + } + + func showPermissionAlert(title: String, message: String, settingsURL: String) { + let alert = NSAlert() + alert.messageText = title + alert.informativeText = message + alert.alertStyle = .warning + alert.addButton(withTitle: "Open Settings") + alert.addButton(withTitle: "Later") + + if alert.runModal() == .alertFirstButtonReturn { + if let url = URL(string: settingsURL) { + NSWorkspace.shared.open(url) + } + } + } + // MARK: - Hotkey Registration func registerHotkey() { var hotKeyRef: EventHotKeyRef?