Add Open Settings buttons to permission dialogs
- Add checkAccessibilityPermission() with AXIsProcessTrusted check - Permission alerts now have "Open Settings" button - Button opens directly to the relevant Privacy settings pane - Import ApplicationServices for accessibility API Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
BINáris
WhisperDictate
Executable file
BINáris
WhisperDictate
Executable file
Binary file not shown.
@@ -2,6 +2,7 @@ import Cocoa
|
|||||||
import AVFoundation
|
import AVFoundation
|
||||||
import Carbon.HIToolbox
|
import Carbon.HIToolbox
|
||||||
import ServiceManagement
|
import ServiceManagement
|
||||||
|
import ApplicationServices
|
||||||
|
|
||||||
// MARK: - User Defaults Keys
|
// MARK: - User Defaults Keys
|
||||||
struct Defaults {
|
struct Defaults {
|
||||||
@@ -38,6 +39,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
setupStatusItem()
|
setupStatusItem()
|
||||||
registerHotkey()
|
registerHotkey()
|
||||||
requestMicrophonePermission()
|
requestMicrophonePermission()
|
||||||
|
checkAccessibilityPermission()
|
||||||
checkModelExists()
|
checkModelExists()
|
||||||
|
|
||||||
NSLog("WhisperDictate started. Press ⌃⌥D to toggle recording.")
|
NSLog("WhisperDictate started. Press ⌃⌥D to toggle recording.")
|
||||||
@@ -248,16 +250,42 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
AVCaptureDevice.requestAccess(for: .audio) { granted in
|
AVCaptureDevice.requestAccess(for: .audio) { granted in
|
||||||
if !granted {
|
if !granted {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
let alert = NSAlert()
|
self.showPermissionAlert(
|
||||||
alert.messageText = "Microphone Access Required"
|
title: "Microphone Access Required",
|
||||||
alert.informativeText = "Please enable microphone access in System Settings → Privacy & Security → Microphone"
|
message: "WhisperDictate needs microphone access to record your voice.",
|
||||||
alert.alertStyle = .warning
|
settingsURL: "x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone"
|
||||||
alert.runModal()
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// MARK: - Hotkey Registration
|
||||||
func registerHotkey() {
|
func registerHotkey() {
|
||||||
var hotKeyRef: EventHotKeyRef?
|
var hotKeyRef: EventHotKeyRef?
|
||||||
|
|||||||
Reference in New Issue
Block a user