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

fix: show menu bar icon only on app reopen, not on interact #98

Merged
merged 2 commits into from
Jul 8, 2024
Merged
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
29 changes: 20 additions & 9 deletions DockDoor/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
self.setupMenuBar()
if !Defaults[.showMenuBarIcon] {
self.scheduleMenuBarIconVisibilityUpdate()
}

if !Defaults[.launched] {
handleFirstTimeLaunch()
} else {
self.setupMenuBar()

// Schedule a timer to remove the menu bar icon after 10 seconds if it's turned off
if !Defaults[.showMenuBarIcon] {
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
self.updateMenuBarIconStatus()
}
}

dockObserver = DockObserver.shared
appClosureObserver = AppClosureObserver.shared
if Defaults[.enableWindowSwitcher] {
Expand All @@ -57,6 +53,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
self.setupMenuBar()
if !Defaults[.showMenuBarIcon] {
self.scheduleMenuBarIconVisibilityUpdate()
}

return false
}

private func setupMenuBar() {
guard statusBarItem == nil else { return }
// Show the menu bar icon initially
Expand Down Expand Up @@ -86,6 +91,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

private func scheduleMenuBarIconVisibilityUpdate() {
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
self.updateMenuBarIconStatus()
}
}

@objc func statusBarButtonClicked(_ sender: Any?) {
// Show the menu
if let button = statusBarItem?.button {
Expand Down