Skip to content

Commit 3d97037

Browse files
Add check for permissions on onboarding (MonitorControl#955)
1 parent 2f8cca2 commit 3d97037

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "checkmark.png",
5+
"idiom" : "mac",
6+
"scale" : "1x"
7+
},
8+
{
9+
"filename" : "[email protected]",
10+
"idiom" : "mac",
11+
"scale" : "2x"
12+
}
13+
],
14+
"info" : {
15+
"author" : "xcode",
16+
"version" : 1
17+
}
18+
}
1.15 KB
Loading
2.04 KB
Loading

MonitorControl/UI/Base.lproj/Main.storyboard

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ You can enable it by adding MonitorControl in System Preferences > Security a
22492249
</textField>
22502250
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="j2w-H2-9zU">
22512251
<rect key="frame" x="65" y="74" width="202" height="32"/>
2252-
<buttonCell key="cell" type="push" title="Open System Preferences…" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="pVc-wG-Bdh">
2252+
<buttonCell key="cell" type="push" title="Open System Preferences…" bezelStyle="rounded" imagePosition="trailing" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="pVc-wG-Bdh">
22532253
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
22542254
<font key="font" metaFont="system"/>
22552255
</buttonCell>
@@ -2322,6 +2322,9 @@ DQ
23222322
<constraint firstItem="smN-BX-6Bx" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="7ij-vC-Tcj" secondAttribute="leading" constant="24" id="zyv-XU-eAi"/>
23232323
</constraints>
23242324
</view>
2325+
<connections>
2326+
<outlet property="permissionsButton" destination="j2w-H2-9zU" id="4Eb-J5-znC"/>
2327+
</connections>
23252328
</viewController>
23262329
<customObject id="YML-6F-4Tw" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
23272330
</objects>

MonitorControl/View Controllers/Onboarding/OnboardingViewController.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import Cocoa
44

55
class OnboardingViewController: NSViewController {
6+
@IBOutlet private var permissionsButton: NSButton!
7+
68
override func viewDidLoad() {
79
super.viewDidLoad()
10+
self.setPermissionsButtonState()
811
}
912

1013
// MARK: - Actions
@@ -23,4 +26,14 @@ class OnboardingViewController: NSViewController {
2326
app.statusItem.button?.performClick(self)
2427
}
2528
}
29+
30+
// MARK: - Style
31+
32+
private func setPermissionsButtonState() {
33+
let volumePermissions: Bool = [KeyboardVolume.media.rawValue, KeyboardVolume.both.rawValue].contains(prefs.integer(forKey: PrefKey.keyboardVolume.rawValue))
34+
let brigthnessPermissions: Bool = [KeyboardBrightness.media.rawValue, KeyboardBrightness.both.rawValue].contains(prefs.integer(forKey: PrefKey.keyboardBrightness.rawValue))
35+
let permissionsRequired: Bool = volumePermissions || brigthnessPermissions
36+
let enabled: Bool = !MediaKeyTapManager.readPrivileges(prompt: false) && permissionsRequired
37+
self.permissionsButton.image = enabled ? nil : NSImage(named: "onboarding_icon_checkmark")
38+
}
2639
}

0 commit comments

Comments
 (0)