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

Commit

Permalink
Add permissions prompt to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Dec 13, 2015
1 parent cedc005 commit 5fcdf02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Aware/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@
</customObject>
<menu id="099-Sz-hJX">
<items>
<menuItem title="Enable Keyboard Monitoring" id="o5y-5N-gZN">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="enableKeyboardMonitoring" target="9bV-Jf-Y2W" id="O6O-rh-jAD"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="gOL-aE-bl2"/>
<menuItem title="Quit Aware" id="nuW-Ky-b5C">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="terminate:" target="-2" id="wSz-0G-0n6"/>
</connections>
</menuItem>
</items>
<connections>
<outlet property="delegate" destination="9bV-Jf-Y2W" id="TZQ-Lk-Gvt"/>
</connections>
<point key="canvasLocation" x="0.0" y="0.0"/>
</menu>
</objects>
Expand Down
12 changes: 9 additions & 3 deletions Aware/StatusItem.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Cocoa

class StatusItem: NSObject {
class StatusItem: NSObject, NSMenuDelegate {
let item: NSStatusItem

@IBOutlet weak var menu: NSMenu!
Expand All @@ -15,8 +15,6 @@ class StatusItem: NSObject {
override func awakeFromNib() {
self.item.menu = menu

AXIsProcessTrustedWithOptions([TrustedCheckOptionPrompt: true])

setDuration(NSTimeInterval())
UserActivityTimer(onUpdate: { duration in
self.setDuration(duration)
Expand All @@ -34,4 +32,12 @@ class StatusItem: NSObject {
let minutes = seconds / 60
return "\(minutes)m"
}

@IBAction func enableKeyboardMonitoring(sender: NSMenuItem) {
AXIsProcessTrustedWithOptions([TrustedCheckOptionPrompt: true])
}

func menuNeedsUpdate(menu: NSMenu) {
menu.itemArray[0].hidden = AXIsProcessTrusted()
}
}

0 comments on commit 5fcdf02

Please sign in to comment.