Skip to content

Commit

Permalink
feat: added dynamic menu bar option
Browse files Browse the repository at this point in the history
  • Loading branch information
will09122000 committed Jul 2, 2023
1 parent c63057b commit 31fad01
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions auto-clicker/Constants/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extension Defaults.Keys {
static let windowShouldKeepOnTop = Key<Bool>("window_should_keep_on_top", default: false)

static let menuBarShowIcon = Key<Bool>("menu_bar_show_icon", default: true)
static let menuBarShowDynamicIcon = Key<Bool>("menu_bar_show_dynamic_icon", default: false)
static let menuBarHideDock = Key<Bool>("menu_bar_hide_dock", default: false)

static let appearanceSelectedTheme = Key<ThemeService>("appearance_selected_theme", default: ThemeService())
Expand Down
3 changes: 3 additions & 0 deletions auto-clicker/Localisation/en-GB.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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.";

Expand Down
4 changes: 4 additions & 0 deletions auto-clicker/Observable Objects/AutoClickSimulator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,6 +83,8 @@ final class AutoClickSimulator: ObservableObject {
stopMenuItem.isEnabled = false
}

MenuBarService.changeImageColor(newColor: .white)

self.activity?.cancel()
self.activity = nil

Expand Down
10 changes: 10 additions & 0 deletions auto-clicker/Services/MenuBarService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions auto-clicker/Views/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct MainView: View {
func start() {
if !self.hasStarted {
self.delayTimer.start(onFinish: self.autoClickSimulator.start)
MenuBarService.changeImageColor(newColor: .orange)
}
}

Expand Down
2 changes: 1 addition & 1 deletion auto-clicker/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct SettingsView: View {
Label("settings_general", systemImage: "gear")
}
.onAppear {
self.changeFrameHeight(330)
self.changeFrameHeight(390)
}

KeyboardShortcutsSettingsTabView()
Expand Down
21 changes: 21 additions & 0 deletions auto-clicker/Views/Settings/Tabs/GeneralSettingsTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
) {
Expand Down

0 comments on commit 31fad01

Please sign in to comment.