Skip to content

Commit

Permalink
fix: removing accessibility permission breaks keyboard inputs
Browse files Browse the repository at this point in the history
closes #269
  • Loading branch information
lwouis committed Apr 25, 2020
1 parent ef6ee72 commit 4efd8c1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/logic/SystemPermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@ import Cocoa
class SystemPermissions {
static func ensureAccessibilityCheckboxIsChecked() {
guard #available(OSX 10.9, *) else { return }
if !AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary) {
if !AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeRetainedValue(): 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.",
"See https://help.rescuetime.com/article/59-how-do-i-enable-accessibility-permissions-on-mac-osx",
separator: "\n")
"Please authorize and re-launch.",
"See https://help.rescuetime.com/article/59-how-do-i-enable-accessibility-permissions-on-mac-osx",
separator: "\n")
App.shared.terminate(self)
} else {
// if the user removes the permission while the app is running, it can break keyboard inputs
DistributedNotificationCenter.default().addObserver(forName: NSNotification.Name("com.apple.accessibility.api"), object: nil, queue: nil) { _ in
// there is a delay between the notification and the permission being actually changed
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
ensureAccessibilityCheckboxIsChecked()
}
}
}
}

static func ensureScreenRecordingCheckboxIsChecked() {
guard #available(OSX 10.15, *) else { return }
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-",
separator: "\n")
"Please authorize and re-launch.",
"See https://dropshare.zendesk.com/hc/en-us/articles/360033453434-Enabling-Screen-Recording-Permission-on-macOS-Catalina-10-15-",
separator: "\n")
App.shared.terminate(self)
}
}
Expand Down

0 comments on commit 4efd8c1

Please sign in to comment.