Skip to content

Commit

Permalink
fix: handle new Screen Recording permission on Catalina (closes #29)
Browse files Browse the repository at this point in the history
This is a light rework of the work from #33
  • Loading branch information
shaqed authored and Louis Pontoise committed Oct 17, 2019
1 parent ee85a2f commit cbfa586
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion alt-tab-macos/ui/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Application: NSApplication, NSApplicationDelegate, NSWindowDelegate, NSCol
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
ensureScreenRecordingCheckboxIsChecked()
ensureAccessibilityCheckboxIsChecked()
updateThumbnailMaxSize()
makeStatusBarItem()
Expand Down Expand Up @@ -106,7 +107,16 @@ class Application: NSApplication, NSApplicationDelegate, NSWindowDelegate, NSCol

func ensureAccessibilityCheckboxIsChecked() {
if !AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary) {
debugPrint("The user hasn't checked the accessiblity permission checkbox; please authorize and re-launch\nSee https://help.rescuetime.com/article/59-how-do-i-enable-accessibility-permissions-on-mac-osx")
debugPrint("Before using this app, you need to give permission in System Preferences > Security & Privacy > Privacy > Accessibility.\nPlease authorize and re-launch.\nSee https://help.rescuetime.com/article/59-how-do-i-enable-accessibility-permissions-on-mac-osx")
NSApp.terminate(self)
}
}

func ensureScreenRecordingCheckboxIsChecked() {
let firstWindow = cgWindows()[0]
let windowImage = CGWindowListCreateImage(.null, .optionIncludingWindow, firstWindow[kCGWindowNumber] as! CGWindowID, [.boundsIgnoreFraming, .bestResolution])
if windowImage == nil {
debugPrint("Before using this app, you need to give permission in System Preferences > Security & Privacy > Privacy > Screen Recording.\nPlease authorize and re-launch.\nSee https://dropshare.zendesk.com/hc/en-us/articles/360033453434-Enabling-Screen-Recording-Permission-on-macOS-Catalina-10-15-")
NSApp.terminate(self)
}
}
Expand Down

0 comments on commit cbfa586

Please sign in to comment.