From 31fad014a93f8f36fb5674f8a531f40aa600f22c Mon Sep 17 00:00:00 2001 From: Will Coates Date: Sun, 2 Jul 2023 12:22:39 +0100 Subject: [PATCH] feat: added dynamic menu bar option --- auto-clicker/Constants/Defaults.swift | 1 + .../en-GB.lproj/Localizable.strings | 3 +++ .../AutoClickSimulator.swift | 4 ++++ auto-clicker/Services/MenuBarService.swift | 10 +++++++++ auto-clicker/Views/Main/MainView.swift | 1 + .../Views/Settings/SettingsView.swift | 2 +- .../Tabs/GeneralSettingsTabView.swift | 21 +++++++++++++++++++ 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/auto-clicker/Constants/Defaults.swift b/auto-clicker/Constants/Defaults.swift index c0a493e..caa4c67 100644 --- a/auto-clicker/Constants/Defaults.swift +++ b/auto-clicker/Constants/Defaults.swift @@ -15,6 +15,7 @@ extension Defaults.Keys { static let windowShouldKeepOnTop = Key("window_should_keep_on_top", default: false) static let menuBarShowIcon = Key("menu_bar_show_icon", default: true) + static let menuBarShowDynamicIcon = Key("menu_bar_show_dynamic_icon", default: false) static let menuBarHideDock = Key("menu_bar_hide_dock", default: false) static let appearanceSelectedTheme = Key("appearance_selected_theme", default: ThemeService()) diff --git a/auto-clicker/Localisation/en-GB.lproj/Localizable.strings b/auto-clicker/Localisation/en-GB.lproj/Localizable.strings index 954dc5e..345ce8c 100644 --- a/auto-clicker/Localisation/en-GB.lproj/Localizable.strings +++ b/auto-clicker/Localisation/en-GB.lproj/Localizable.strings @@ -48,6 +48,9 @@ "settings_general_menu_bar_show_icon" = "Show menu bar icon"; "settings_general_menu_bar_show_icon_help" = "Always show an icon in the macOS menu bar where the app and quick access functionality can be accessed."; +"settings_general_menu_bar_show_dynamic_icon" = "Show dynamic menu bar icon"; +"settings_general_menu_bar_show_dynamic_icon_help" = "The menu bar icon will update based on the state of the auto clicker.\nOrange = Counting down to start\nGreen = Auto clicker running"; + "settings_general_menu_bar_hide_dock" = "Hide dock icon"; "settings_general_menu_bar_hide_dock_help" = "Instead of the app running from the dock, the app will instead run from the menu bar."; diff --git a/auto-clicker/Observable Objects/AutoClickSimulator.swift b/auto-clicker/Observable Objects/AutoClickSimulator.swift index 1c51525..c581c19 100644 --- a/auto-clicker/Observable Objects/AutoClickSimulator.swift +++ b/auto-clicker/Observable Objects/AutoClickSimulator.swift @@ -43,6 +43,8 @@ final class AutoClickSimulator: ObservableObject { stopMenuItem.isEnabled = true } + MenuBarService.changeImageColor(newColor: .green) + self.activity = ProcessInfo.processInfo.beginActivity(.autoClicking) self.duration = Defaults[.autoClickerState].pressIntervalDuration @@ -81,6 +83,8 @@ final class AutoClickSimulator: ObservableObject { stopMenuItem.isEnabled = false } + MenuBarService.changeImageColor(newColor: .white) + self.activity?.cancel() self.activity = nil diff --git a/auto-clicker/Services/MenuBarService.swift b/auto-clicker/Services/MenuBarService.swift index 55864af..fa798f7 100644 --- a/auto-clicker/Services/MenuBarService.swift +++ b/auto-clicker/Services/MenuBarService.swift @@ -41,6 +41,8 @@ final class MenuBarService { statusBarButton.image = NSImage(systemSymbolName: "cursorarrow.click.badge.clock", accessibilityDescription: "auto clicker") statusBarButton.action = #selector(togglePopover(sender:)) statusBarButton.target = self + + self.changeImageColor(newColor: .white) } // Styling just didn't really work, this would work well for a Menu Bar app, but not for just simple clickable Menu Items... @@ -139,6 +141,14 @@ final class MenuBarService { self.toggle(Defaults[.menuBarShowIcon]) } + static func changeImageColor(newColor: NSColor) { + if Defaults[.menuBarShowDynamicIcon], #available(macOS 12.0, *), + let statusBarButton = self.statusBarItem!.button { + let config = NSImage.SymbolConfiguration(paletteColors: [.white, newColor]) + statusBarButton.image = statusBarButton.image!.withSymbolConfiguration(config) + } + } + @objc static func togglePopover(sender: AnyObject) { if self.statusBarPopover!.isShown { self.hidePopover(sender) diff --git a/auto-clicker/Views/Main/MainView.swift b/auto-clicker/Views/Main/MainView.swift index b6971d8..e73af85 100644 --- a/auto-clicker/Views/Main/MainView.swift +++ b/auto-clicker/Views/Main/MainView.swift @@ -40,6 +40,7 @@ struct MainView: View { func start() { if !self.hasStarted { self.delayTimer.start(onFinish: self.autoClickSimulator.start) + MenuBarService.changeImageColor(newColor: .orange) } } diff --git a/auto-clicker/Views/Settings/SettingsView.swift b/auto-clicker/Views/Settings/SettingsView.swift index 33a45ee..fc1bde7 100644 --- a/auto-clicker/Views/Settings/SettingsView.swift +++ b/auto-clicker/Views/Settings/SettingsView.swift @@ -29,7 +29,7 @@ struct SettingsView: View { Label("settings_general", systemImage: "gear") } .onAppear { - self.changeFrameHeight(330) + self.changeFrameHeight(390) } KeyboardShortcutsSettingsTabView() diff --git a/auto-clicker/Views/Settings/Tabs/GeneralSettingsTabView.swift b/auto-clicker/Views/Settings/Tabs/GeneralSettingsTabView.swift index 6485fda..a914f25 100644 --- a/auto-clicker/Views/Settings/Tabs/GeneralSettingsTabView.swift +++ b/auto-clicker/Views/Settings/Tabs/GeneralSettingsTabView.swift @@ -61,6 +61,27 @@ struct GeneralSettingsTabView: View { } } + if #available(macOS 12.0, *) { + SettingsTabItemView( + help: "settings_general_menu_bar_show_dynamic_icon_help" + ) { + HStack { + Defaults.Toggle( + " " + String(format: NSLocalizedString("settings_general_menu_bar_show_dynamic_icon", comment: "Dynamic icon in menu bar toggle")), + key: .menuBarShowDynamicIcon + ) + .disabled(!self.menuBarShowIcon) + + Image(systemName: "cursorarrow.click.badge.clock") + .symbolRenderingMode(.palette) + .foregroundStyle(.white, .orange) + Image(systemName: "cursorarrow.click.badge.clock") + .symbolRenderingMode(.palette) + .foregroundStyle(.white, .green) + } + } + } + SettingsTabItemView( help: "settings_general_menu_bar_hide_dock_help" ) {