Skip to content

Dock icon appears after interacting with the menu bar icon and never goes away (and there's no option to hide it) #3

Open

Description

@kazimshah39

Aktar launches as a menu-bar-only app (LSUIElement = YES), which is what I want. Right after launch there is no Dock icon.

But after I click the menu bar icon a second time, the Dock icon appears. Closing windows with the X button does not remove it. The only way to get rid of it is to quit and relaunch Aktar, and it can come back.

There is also no setting anywhere in the app to keep the Dock icon hidden while Aktar is running.

Expected behavior

  1. Closing the last real window (Library, Settings, Welcome, QR Code, Request Files, Share) with the X button should return the app to menu-bar-only mode and hide the Dock icon.
  2. A preference such as Settings → General → "Show Dock icon" (or "Always hide Dock icon") so users can keep Aktar menu-bar-only while it runs, even when windows are open.

Steps to reproduce

  1. Launch Aktar. There is no Dock icon.
  2. Click the menu bar icon to open the panel, then click again to close it. Repeat once or twice.
  3. The Dock icon appears.
  4. Open Library or Settings, then close it with the X button.
  5. The Dock icon is still there.

Environment

  • Mac: MacBook Pro, Apple M4 Pro
  • macOS: 26.6.2
  • Aktar: 0.21.0 (replace with the installed version if different)
  • Install method: DMG / Homebrew (delete one)

Suspected cause (from reading the source, not yet confirmed by debugging)

The Dock icon is controlled only by two calls in Sources/Aktar/AppDelegate.swift:

  • windowDidBecomeKey calls NSApp.setActivationPolicy(.regular), which shows the Dock icon, for any window where isTrackedWindow is true.
  • windowWillClose calls NSApp.setActivationPolicy(.accessory), which hides it, but only if no other tracked window is still visible:
private func isTrackedWindow(_ window: NSWindow) -> Bool {
    !(window is MenuBarPanel) && !(window is NSOpenPanel) && !(window is NSSavePanel)
}
let hasOtherTrackedWindows = NSApp.windows.contains { candidate in
    candidate !== closingWindow && candidate.isVisible && self.isTrackedWindow(candidate)
}
if !hasOtherTrackedWindows {
    NSApp.setActivationPolicy(.accessory)
}

isTrackedWindow is a deny-list: every window that is not MenuBarPanel, NSOpenPanel or NSSavePanel counts as an app window. That likely includes windows that are not user-facing, for example:

  • the status item's own NSStatusBarWindow, which is always visible
  • SwiftUI or AppKit helper windows

Two consequences:

  • Icon appears on menu bar interaction. If one of those windows becomes key when the menu bar icon is clicked, windowDidBecomeKey promotes the app to .regular. This matches the icon appearing after clicking the menu bar icon, without opening any real window.
  • Icon never goes away. If one of those windows stays visible, hasOtherTrackedWindows is always true, so the app never goes back to .accessory.

Other paths where the icon can get stuck

  • Minimize or hide. Minimizing a window (yellow button) or hiding the app (⌘H) sends no close notification, so nothing demotes the app.
  • Hand-built windows. RequestFilesView.swift, QRCodeView.swift and ShareDestinationView.swift create plain NSWindow instances that go through the same track-and-demote logic, so they share the same problem.
  • Race on close. The demotion check runs in DispatchQueue.main.async after the close notification and reads window state at that moment, which is fragile.

How to confirm

Log the windows at the moment the Dock icon appears, and again after closing a window:

NSApp.windows.forEach {
    print(type(of: $0), $0.title, $0.isVisible, $0.identifier?.rawValue ?? "-")
}

Suggested fix

  1. Use an allow-list instead of a deny-list. Only treat Aktar's own windows (library, settings, onboarding, and the QR Code, Request Files and Share windows) as windows that justify showing the Dock icon, for example by checking the window identifier or title. Never count NSStatusBarWindow or other system or helper windows.
  2. Re-evaluate on more events. Also handle minimize (didMiniaturizeNotification) and app hide, not only close.
  3. Add a preference, such as "Show Dock icon" (on or off), stored in UserDefaults. When off, never call setActivationPolicy(.regular). The tradeoff is that Aktar will not appear in ⌘-Tab while windows are open, which is why this should be a choice and not forced.

Additional context

Aktar is otherwise great as a menu bar tool. The Dock icon getting stuck defeats the point of a menu-bar-only app, and the only workaround is quitting and relaunching.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions