Skip to content

Commit

Permalink
fix: show menu bar icon only on app reopen, not on interact
Browse files Browse the repository at this point in the history
Moved initialization from `applicationDidBecomeActive` to `applicationShouldHandleReopen` to ensure the menu bar icon is only shown when the app is reopened, and not on other interactions.

closes ejbills#95
see ejbills#76
  • Loading branch information
ShlomoCode committed Jul 8, 2024
1 parent b6bb821 commit 239b489
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions DockDoor/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

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

if !Defaults[.launched] {
handleFirstTimeLaunch()
} else {
Expand All @@ -48,15 +53,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

func applicationDidBecomeActive(_ notification: Notification) {
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
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()
}
self.scheduleMenuBarIconVisibilityUpdate()
}

return false
}

private func setupMenuBar() {
Expand Down Expand Up @@ -88,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

0 comments on commit 239b489

Please sign in to comment.