| | |
| | | */ |
| | | import "C" |
| | | |
| | | import "os/exec" |
| | | import ( |
| | | "os/exec" |
| | | "voicesnap/internal/startup" |
| | | ) |
| | | |
| | | // Statuses returns the current macOS privacy permission state. |
| | | func Statuses() []Status { |
| | |
| | | State: grantedState(C.inputMonitoringGranted() != 0), |
| | | Required: true, |
| | | }, |
| | | { |
| | | ID: IDBackground, |
| | | Granted: startup.IsEnabled(), |
| | | State: enabledState(startup.IsEnabled()), |
| | | Required: false, |
| | | }, |
| | | } |
| | | } |
| | | |
| | |
| | | openSettings(id) |
| | | case IDInputMonitoring: |
| | | C.requestInputMonitoring() |
| | | openSettings(id) |
| | | case IDBackground: |
| | | _ = startup.SetEnabled(true) |
| | | openSettings(id) |
| | | } |
| | | } |
| | |
| | | return "denied" |
| | | } |
| | | |
| | | func enabledState(enabled bool) string { |
| | | if enabled { |
| | | return "enabled" |
| | | } |
| | | return "disabled" |
| | | } |
| | | |
| | | func openSettings(id string) { |
| | | url := "x-apple.systempreferences:com.apple.preference.security" |
| | | switch id { |
| | |
| | | url = "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility" |
| | | case IDInputMonitoring: |
| | | url = "x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent" |
| | | case IDBackground: |
| | | url = "x-apple.systempreferences:com.apple.LoginItems-Settings.extension" |
| | | } |
| | | _ = exec.Command("open", url).Start() |
| | | } |