From a4350d213a8085b4e9a05e5b0938ad68c5cb58b8 Mon Sep 17 00:00:00 2001 From: Niklas Rousset <75939868+niklasr22@users.noreply.github.com> Date: Sun, 12 Jan 2025 20:00:40 +0100 Subject: [PATCH] Adds a new keyboard shortcut to open settings (#201) --- BrightIntosh.xcodeproj/project.pbxproj | 16 ++++++++-------- BrightIntosh/AppDelegate.swift | 11 +++++++++-- BrightIntosh/Constants.swift | 1 + BrightIntosh/Localizable.xcstrings | 3 +++ BrightIntosh/UI/SettingsWindow.swift | 2 ++ BrightIntosh/UI/StatusBarMenu.swift | 1 + 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/BrightIntosh.xcodeproj/project.pbxproj b/BrightIntosh.xcodeproj/project.pbxproj index 5348010..d0de018 100644 --- a/BrightIntosh.xcodeproj/project.pbxproj +++ b/BrightIntosh.xcodeproj/project.pbxproj @@ -392,7 +392,7 @@ CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh_SE.entitlements; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 61; + CURRENT_PROJECT_VERSION = 62; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = 9K32WDUN2H; @@ -419,7 +419,7 @@ LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 3.6.0; + MARKETING_VERSION = 3.7.0; PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app; PRODUCT_NAME = BrightIntosh; SDKROOT = auto; @@ -444,7 +444,7 @@ CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh_SE.entitlements; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 61; + CURRENT_PROJECT_VERSION = 62; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = 9K32WDUN2H; @@ -471,7 +471,7 @@ LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 3.6.0; + MARKETING_VERSION = 3.7.0; PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app; PRODUCT_NAME = BrightIntosh; SDKROOT = auto; @@ -494,7 +494,7 @@ CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh.entitlements; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 61; + CURRENT_PROJECT_VERSION = 62; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = 9K32WDUN2H; @@ -521,7 +521,7 @@ LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 3.6.0; + MARKETING_VERSION = 3.7.0; PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; @@ -545,7 +545,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 61; + CURRENT_PROJECT_VERSION = 62; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = 9K32WDUN2H; @@ -572,7 +572,7 @@ LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 3.6.0; + MARKETING_VERSION = 3.7.0; PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; diff --git a/BrightIntosh/AppDelegate.swift b/BrightIntosh/AppDelegate.swift index 7dc46c9..d059795 100644 --- a/BrightIntosh/AppDelegate.swift +++ b/BrightIntosh/AppDelegate.swift @@ -35,7 +35,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { if userActivity.activityType == CSSearchableItemActionType, let uniqueIdentifier = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String { if uniqueIdentifier == "de.brightintosh.app.settings" { - self.settingsWindowController.showWindow(nil) + self.showSettingsWindow() return true } } @@ -83,7 +83,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let stillEntitledToTrial = (try await TrialData.getTrialData()).stillEntitled() if !stillEntitledToTrial && offerUpgrade { DispatchQueue.main.async { - self.settingsWindowController.showWindow(nil) + self.showSettingsWindow() } } startTrialTimer() @@ -114,6 +114,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { KeyboardShortcuts.onKeyUp(for: .decreaseBrightness) { self.decreaseBrightness() } + KeyboardShortcuts.onKeyUp(for: .openSettings, action: { + self.showSettingsWindow() + }) } @objc func toggleBrightIntosh() { @@ -131,6 +134,10 @@ class AppDelegate: NSObject, NSApplicationDelegate { UserDefaults.standard.set(true, forKey: "agreementAccepted") } + func showSettingsWindow() { + self.settingsWindowController.showWindow(nil) + } + func startTrialTimer() { if trialTimer != nil { return diff --git a/BrightIntosh/Constants.swift b/BrightIntosh/Constants.swift index d338fbe..148b870 100644 --- a/BrightIntosh/Constants.swift +++ b/BrightIntosh/Constants.swift @@ -21,6 +21,7 @@ extension KeyboardShortcuts.Name { static let toggleBrightIntosh = Self("toggleIncreasedBrightness", default: .init(carbonKeyCode: kVK_ANSI_B, carbonModifiers: (0 | optionKey | cmdKey))) static let increaseBrightness = Self("increaseBrightness", default: .init(carbonKeyCode: kVK_ANSI_N, carbonModifiers: (0 | optionKey | cmdKey))) static let decreaseBrightness = Self("decreaseBrightness", default: .init(carbonKeyCode: kVK_ANSI_M, carbonModifiers: (0 | optionKey | cmdKey))) + static let openSettings = Self("openSettings", default: .init(carbonKeyCode: kVK_ANSI_B, carbonModifiers: (0 | optionKey | cmdKey | shiftKey))) } let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String)! diff --git a/BrightIntosh/Localizable.xcstrings b/BrightIntosh/Localizable.xcstrings index 63008b4..d61ad74 100644 --- a/BrightIntosh/Localizable.xcstrings +++ b/BrightIntosh/Localizable.xcstrings @@ -1145,6 +1145,9 @@ } } } + }, + "Open settings:" : { + }, "Quit" : { "localizations" : { diff --git a/BrightIntosh/UI/SettingsWindow.swift b/BrightIntosh/UI/SettingsWindow.swift index 88e2cbf..b03b13b 100644 --- a/BrightIntosh/UI/SettingsWindow.swift +++ b/BrightIntosh/UI/SettingsWindow.swift @@ -151,6 +151,8 @@ struct BasicSettings: View { "Increase brightness:", name: .increaseBrightness) KeyboardShortcuts.Recorder( "Decrease brightness:", name: .decreaseBrightness) + KeyboardShortcuts.Recorder( + "Open settings:", name: .openSettings) } } Section(header: Text("General").bold()) { diff --git a/BrightIntosh/UI/StatusBarMenu.swift b/BrightIntosh/UI/StatusBarMenu.swift index 37d904f..8c84da8 100644 --- a/BrightIntosh/UI/StatusBarMenu.swift +++ b/BrightIntosh/UI/StatusBarMenu.swift @@ -74,6 +74,7 @@ class StatusBarMenu : NSObject, NSMenuDelegate { toggleTimerItem.target = self let settingsItem = NSMenuItem(title: String(localized: "Settings"), action: #selector(openSettings), keyEquivalent: "") + settingsItem.setShortcut(for: .openSettings) settingsItem.target = self let aboutUsItem = NSMenuItem(title: String(localized: "About us"), action: #selector(openLegalNotice), keyEquivalent: "")