Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions MonitorControl.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
F0445D3820023E710025AE82 /* MainPrefsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0445D3720023E710025AE82 /* MainPrefsViewController.swift */; };
F06792EA200A73460066C438 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = F06792E9200A73460066C438 /* main.swift */; };
F06792F6200A745F0066C438 /* MonitorControlHelper.app in [Login] Copy Helper to start at Login */ = {isa = PBXBuildFile; fileRef = F06792E7200A73460066C438 /* MonitorControlHelper.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
F0A489C4279C71B200BEDFD6 /* OnboardingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0A489C3279C71B200BEDFD6 /* OnboardingViewController.swift */; };
FE4E0896249D584C003A50BB /* OSDUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE4E0895249D584C003A50BB /* OSDUtils.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -157,6 +158,7 @@
F06792E9200A73460066C438 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
F06792F0200A73470066C438 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F06792F1200A73470066C438 /* MonitorControlHelper.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MonitorControlHelper.entitlements; sourceTree = "<group>"; };
F0A489C3279C71B200BEDFD6 /* OnboardingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingViewController.swift; sourceTree = "<group>"; };
FE4E0895249D584C003A50BB /* OSDUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSDUtils.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -311,12 +313,8 @@
F0445D3620023D5B0025AE82 /* View Controllers */ = {
isa = PBXGroup;
children = (
F0445D3720023E710025AE82 /* MainPrefsViewController.swift */,
AA25F6CE26E680510087F3A2 /* MenuslidersPrefsViewController.swift */,
AA25F6D026E681D30087F3A2 /* KeyboardPrefsViewController.swift */,
AA062E8926C9A039007E628C /* DisplaysPrefsViewController.swift */,
AA062E8D26CA7BE5007E628C /* DisplaysPrefsCellView.swift */,
AA665A5C26C5892800FEF2C1 /* AboutPrefsViewController.swift */,
F0A489C2279C719200BEDFD6 /* Onboarding */,
F0A489C1279C718400BEDFD6 /* Preferences */,
);
path = "View Controllers";
sourceTree = "<group>";
Expand All @@ -331,6 +329,27 @@
path = MonitorControlHelper;
sourceTree = "<group>";
};
F0A489C1279C718400BEDFD6 /* Preferences */ = {
isa = PBXGroup;
children = (
F0445D3720023E710025AE82 /* MainPrefsViewController.swift */,
AA25F6CE26E680510087F3A2 /* MenuslidersPrefsViewController.swift */,
AA25F6D026E681D30087F3A2 /* KeyboardPrefsViewController.swift */,
AA062E8926C9A039007E628C /* DisplaysPrefsViewController.swift */,
AA062E8D26CA7BE5007E628C /* DisplaysPrefsCellView.swift */,
AA665A5C26C5892800FEF2C1 /* AboutPrefsViewController.swift */,
);
path = Preferences;
sourceTree = "<group>";
};
F0A489C2279C719200BEDFD6 /* Onboarding */ = {
isa = PBXGroup;
children = (
F0A489C3279C71B200BEDFD6 /* OnboardingViewController.swift */,
);
path = Onboarding;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -581,6 +600,7 @@
F03A8DF21FFBAA6F0034DC27 /* OtherDisplay.swift in Sources */,
AA78BDBD2709FE7B00CA8DF7 /* UpdaterDelegate.swift in Sources */,
AA44E7052703790100E06865 /* KeyboardShortcuts+Extension.swift in Sources */,
F0A489C4279C71B200BEDFD6 /* OnboardingViewController.swift in Sources */,
AA16139B26BE772E00DCF027 /* Arm64DDC.swift in Sources */,
F0445D3820023E710025AE82 /* MainPrefsViewController.swift in Sources */,
28D1DDF2227FBE71004CB494 /* NSScreen+Extension.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"filename" : "icon_keyboard.png",
"idiom" : "mac",
"scale" : "1x"
},
{
"filename" : "icon_keyboard@2x.png",
"idiom" : "mac",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"filename" : "icon_person.png",
"idiom" : "mac",
"scale" : "1x"
},
{
"filename" : "icon_person@2x.png",
"idiom" : "mac",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"images" : [
{
"filename" : "onboarding_keyboard.png",
"idiom" : "mac",
"scale" : "1x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "onboarding_keyboard_dark.png",
"idiom" : "mac",
"scale" : "1x"
},
{
"filename" : "onboarding_keyboard@2x.png",
"idiom" : "mac",
"scale" : "2x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "onboarding_keyboard_dark@2x.png",
"idiom" : "mac",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion MonitorControl/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>6970</string>
<string>7000</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
72 changes: 47 additions & 25 deletions MonitorControl/Support/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(_: Notification) {
app = self
menu = MenuHandler()
menu.delegate = menu
self.subscribeEventListeners()
if NSEvent.modifierFlags.contains(NSEvent.ModifierFlags.shift) {
self.safeMode = true
let alert = NSAlert()
alert.messageText = NSLocalizedString("Safe Mode Activated", comment: "Shown in the alert dialog")
alert.informativeText = NSLocalizedString("Shift was pressed during launch. MonitorControl started in safe mode. Default preferences are reloaded, DDC read is blocked.", comment: "Shown in the alert dialog")
alert.runModal()
}
let currentBuildNumber = Int(Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "1") ?? 1
let previousBuildNumber: Int = (Int(prefs.string(forKey: PrefKey.buildNumber.rawValue) ?? "0") ?? 0)
if self.safeMode || ((previousBuildNumber < MIN_PREVIOUS_BUILD_NUMBER) && previousBuildNumber > 0) || (previousBuildNumber > currentBuildNumber), let bundleID = Bundle.main.bundleIdentifier {
if !self.safeMode {
let alert = NSAlert()
alert.messageText = NSLocalizedString("Incompatible previous version", comment: "Shown in the alert dialog")
alert.informativeText = NSLocalizedString("Preferences for an incompatible previous app version detected. Default preferences are reloaded.", comment: "Shown in the alert dialog")
alert.runModal()
}
prefs.removePersistentDomain(forName: bundleID)
self.showSafeModeAlertIfNeeded()
if !prefs.bool(forKey: PrefKey.appAlreadyLaunched.rawValue) {
self.showOnboardingWindow()
} else {
self.checkPermissions()
}
prefs.set(currentBuildNumber, forKey: PrefKey.buildNumber.rawValue)
self.setPrefsBuildNumber()
self.setDefaultPrefs()
self.statusItem.button?.image = NSImage(named: "status")
self.statusItem.menu = menu
self.checkPermissions()
self.setMenu()
CGDisplayRegisterReconfigurationCallback({ _, _, _ in app.displayReconfigured() }, nil)
self.configure(firstrun: true)
DisplayManager.shared.createGammaActivityEnforcer()
Expand Down Expand Up @@ -101,6 +85,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.statusItem.isVisible = true
}

private func setPrefsBuildNumber() {
let currentBuildNumber = Int(Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "1") ?? 1
let previousBuildNumber: Int = (Int(prefs.string(forKey: PrefKey.buildNumber.rawValue) ?? "0") ?? 0)
if self.safeMode || ((previousBuildNumber < MIN_PREVIOUS_BUILD_NUMBER) && previousBuildNumber > 0) || (previousBuildNumber > currentBuildNumber), let bundleID = Bundle.main.bundleIdentifier {
if !self.safeMode {
let alert = NSAlert()
alert.messageText = NSLocalizedString("Incompatible previous version", comment: "Shown in the alert dialog")
alert.informativeText = NSLocalizedString("Preferences for an incompatible previous app version detected. Default preferences are reloaded.", comment: "Shown in the alert dialog")
alert.runModal()
}
prefs.removePersistentDomain(forName: bundleID)
}
prefs.set(currentBuildNumber, forKey: PrefKey.buildNumber.rawValue)
}

func setDefaultPrefs() {
if !prefs.bool(forKey: PrefKey.appAlreadyLaunched.rawValue) {
// Only preferences that are not false, 0 or "" by default are set here. Assumes pre-wiped database.
Expand Down Expand Up @@ -154,10 +153,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.updateMediaKeyTap()
}

func checkPermissions() {
func checkPermissions(firstAsk: Bool = false) {
let permissionsRequired: Bool = [KeyboardVolume.media.rawValue, KeyboardVolume.both.rawValue].contains(prefs.integer(forKey: PrefKey.keyboardVolume.rawValue)) || [KeyboardBrightness.media.rawValue, KeyboardBrightness.both.rawValue].contains(prefs.integer(forKey: PrefKey.keyboardBrightness.rawValue))
if !MediaKeyTapManager.readPrivileges(prompt: false), permissionsRequired {
MediaKeyTapManager.acquirePrivileges()
MediaKeyTapManager.acquirePrivileges(firstAsk: firstAsk)
}
}

Expand Down Expand Up @@ -329,4 +328,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
os_log("%{public}@", type: .error, error.localizedDescription)
}
}

private func setMenu() {
menu = MenuHandler()
menu.delegate = menu
self.statusItem.button?.image = NSImage(named: "status")
self.statusItem.menu = menu
}

private func showSafeModeAlertIfNeeded() {
if NSEvent.modifierFlags.contains(NSEvent.ModifierFlags.shift) {
self.safeMode = true
let alert = NSAlert()
alert.messageText = NSLocalizedString("Safe Mode Activated", comment: "Shown in the alert dialog")
alert.informativeText = NSLocalizedString("Shift was pressed during launch. MonitorControl started in safe mode. Default preferences are reloaded, DDC read is blocked.", comment: "Shown in the alert dialog")
alert.runModal()
}
}

private func showOnboardingWindow() {
onboardingVc?.showWindow(self)
onboardingVc?.window?.center()
NSApp.activate(ignoringOtherApps: true)
}
}
4 changes: 2 additions & 2 deletions MonitorControl/Support/MediaKeyTapManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ class MediaKeyTapManager: MediaKeyTapDelegate {
return true
}

static func acquirePrivileges() {
if !self.readPrivileges(prompt: true) {
static func acquirePrivileges(firstAsk: Bool = false) {
if !self.readPrivileges(prompt: true), !firstAsk {
let alert = NSAlert()
alert.messageText = NSLocalizedString("Shortcuts not available", comment: "Shown in the alert dialog")
alert.informativeText = NSLocalizedString("You need to enable MonitorControl in System Preferences > Security and Privacy > Accessibility for the keyboard shortcuts to work", comment: "Shown in the alert dialog")
Expand Down
Loading