fix: more robust screen-recording permission check

This commit is contained in:
louis.pontoise authored and lwouis committed 2020-03-10 14:00:37 +09:00
1 parent 34a32f329d
commit ce574a2678
3 files changed
+8 -4

No files matched your search

@@ -128,6 +128,12 @@ func CGSCopySpacesForWindows(_ cid: CGSConnectionID, _ mask: CGSSpaceMask.RawVal
@_silgen_name("CGSGetWindowLevel") @discardableResult
func CGSGetWindowLevel(_ cid: CGSConnectionID, _ wid: CGWindowID, _ level: inout CGWindowLevel) -> CGError
// returns status of the checkbox in System Preferences > Security & Privacy > Privacy > Screen Recording
// returns 1 if checked or 0 if unchecked; also prompts the user the first time if unchecked
@_silgen_name("SLSRequestScreenCaptureAccess") @discardableResult
func SLSRequestScreenCaptureAccess() -> UInt8
// ------------------------------------------------------------
+1 -3
View File
@@ -16,9 +16,7 @@ class SystemPermissions {
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 {
if SLSRequestScreenCaptureAccess() != 1 {
debugPrint("Before using this app, you need to give permission in System Preferences > Security & Privacy > Privacy > Screen Recording.",
"Please authorize and re-launch.",
"See https://dropshare.zendesk.com/hc/en-us/articles/360033453434-Enabling-Screen-Recording-Permission-on-macOS-Catalina-10-15-",
+1 -1
View File
@@ -22,8 +22,8 @@ class App: NSApplication, NSApplicationDelegate, NSWindowDelegate {
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
SystemPermissions.ensureScreenRecordingCheckboxIsChecked()
SystemPermissions.ensureAccessibilityCheckboxIsChecked()
SystemPermissions.ensureScreenRecordingCheckboxIsChecked()
Preferences.loadFromDiskAndUpdateValues()
statusItem = StatusItem.make(self)
initPreferencesDependentComponents()