From e465acba12e6ead4afa1d650749280ccc66756e1 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sun, 27 Sep 2026 10:26:09 +0800 Subject: [PATCH] Close the panel when a tray item is selected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Selecting a tile opened the app's menu while SimpleTopBar's own panel stayed on top of it, and could leave menus such as Spotlight stranded behind it. Dismiss the panel first so the selected menu is unobstructed. 💘 Generated with Crush Assisted-by: Crush:deepseek-v4.1-flash --- AGENTS.md | 3 +++ Sources/SimpleTopBar/App.swift | 8 ++++++++ Sources/SimpleTopBar/MenuBarItems.swift | 7 +++++++ build-app.sh | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 52647e1..8ae0baf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -141,6 +141,9 @@ preferred position controls where the hidden/kept boundary lands: (`kAXPressAction`, then `kAXShowMenuAction`), and `resume()`s ~0.1s later. The menu is its own window anchored at the item's on-screen spot, so it survives re-hiding. +- `press` first calls `onWillPress`, which `AppDelegate` wires to close the + popover. Without it the panel stays open on top of the menu that opens and can + leave menus (e.g. Spotlight) stranded behind it. - **Cannot reveal a single icon.** The spacer hides a contiguous block to its left, so a press can only reveal the whole block. Isolating one item would need either per-item ordering control (not available) or covering the icons diff --git a/Sources/SimpleTopBar/App.swift b/Sources/SimpleTopBar/App.swift index 5131ba3..97a5f50 100644 --- a/Sources/SimpleTopBar/App.swift +++ b/Sources/SimpleTopBar/App.swift @@ -132,6 +132,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate { ) ) self.popover = popover + + // Selecting a tray item must dismiss our panel, otherwise it stays on + // top of the menu that opens (and can strand menus behind it). + Task { @MainActor [weak self] in + MenuBarItemManager.shared.onWillPress = { + self?.popover?.performClose(nil) + } + } } @objc private func togglePopover() { diff --git a/Sources/SimpleTopBar/MenuBarItems.swift b/Sources/SimpleTopBar/MenuBarItems.swift index 75f9337..8ba4450 100644 --- a/Sources/SimpleTopBar/MenuBarItems.swift +++ b/Sources/SimpleTopBar/MenuBarItems.swift @@ -30,6 +30,9 @@ final class MenuBarItemManager: ObservableObject { private var observers: [NSObjectProtocol] = [] + /// Called just before pressing an item so the owner can close its panel. + var onWillPress: (() -> Void)? + private init() {} func start() { @@ -113,6 +116,10 @@ final class MenuBarItemManager: ObservableObject { /// hide again shortly after. The reveal is momentary rather than lasting the /// whole time the panel is open. func press(_ item: MenuBarItem) { + // Close our own panel first, otherwise it stays open on top of the + // menu that is about to appear (and can leave menus behind it). + onWillPress?() + let hider = MenuBarHider.shared let needsReveal = hider.isHiding guard needsReveal else { diff --git a/build-app.sh b/build-app.sh index fe4abe4..82a81a9 100755 --- a/build-app.sh +++ b/build-app.sh @@ -2,7 +2,7 @@ set -euo pipefail cd "$(dirname "$0")" -VERSION="${1:-0.4.2}" +VERSION="${1:-0.4.3}" swift build -c release