Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added dynamic menu bar option #70

Merged
merged 1 commit into from
Jul 2, 2023
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
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