Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Add check for accessibility permission
Browse files Browse the repository at this point in the history
Fixes #60
  • Loading branch information
sindresorhus committed Feb 10, 2020
1 parent bd5bb77 commit e89f8eb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Touch Bar Simulator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,36 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}

func applicationDidFinishLaunching(_ notification: Notification) {
checkAccessibilityPermission()
NSApp.servicesProvider = self
_ = SUUpdater()
_ = window
_ = statusItem
}

func checkAccessibilityPermission() {
// We intentionally don't use the system prompt as our dialog explains it better.
let options = [kAXTrustedCheckOptionPrompt.takeRetainedValue() as String: false] as CFDictionary
if AXIsProcessTrustedWithOptions(options) {
return
}

NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!)

let alert = NSAlert()
alert.messageText = "Touch Bar Simulator needs accessibility access."
alert.informativeText = "In the System Preferences window that just opened, find “Touch Bar Simulator” in the list and check its checkbox. Then click the “Continue” button here."
alert.addButton(withTitle: "Continue")
alert.addButton(withTitle: "Quit")

guard alert.runModal() == .alertFirstButtonReturn else {
App.quit()
return
}

App.relaunch()
}

@objc
func captureScreenshot() {
let KEY_6: CGKeyCode = 0x58
Expand Down

0 comments on commit e89f8eb

Please sign in to comment.