Skip to content

Commit

Permalink
fix: only test permissions on the correct os versions
Browse files Browse the repository at this point in the history
  • Loading branch information
louis.pontoise authored and lwouis committed Mar 10, 2020
1 parent 9a96e49 commit 4612e37
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions alt-tab-macos/logic/SystemPermissions.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation
import Cocoa

// macOS has some privacy restrictions. The user needs to grant certain permissions, app by app, in System Preferences > Security & Privacy > Privacy
// macOS has some privacy restrictions. The user needs to grant certain permissions, app by app, in System Preferences > Security & Privacy
class SystemPermissions {
// macOS 10.9+
static func ensureAccessibilityCheckboxIsChecked() {
guard #available(OSX 10.9, *) else { return }
if !AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary) {
debugPrint("Before using this app, you need to give permission in System Preferences > Security & Privacy > Privacy > Accessibility.",
"Please authorize and re-launch.",
Expand All @@ -14,8 +14,9 @@ class SystemPermissions {
}
}

// macOS 10.15+
static func ensureScreenRecordingCheckboxIsChecked() {
guard #available(OSX 10.15, *) else { return }
// there is no API to check this permission; we try to get a screenshot to check indirectly
let firstWindow = CGWindow.windows(.optionOnScreenOnly)[0]
if let cgId = firstWindow.id(), cgId.screenshot() == nil {
debugPrint("Before using this app, you need to give permission in System Preferences > Security & Privacy > Privacy > Screen Recording.",
Expand Down

0 comments on commit 4612e37

Please sign in to comment.