on master help sign in
fix: popover reopen bug with .transient behavior

With .transient popover behavior, clicking the status item while the popover is open causes macOS to close the popover on mouse-down (outside popover). By the time the .leftMouseUp action fires, popover.isShown is already false, so togglePopover sees it as closed and reopens it — the user can never dismiss the popover by clicking the icon. Fix: togglePopover now only shows (guard !isShown → return). The .transient behavior handles closing automatically. Removed closePopover helper and inlined performClose in showContextMenu, the only other caller.

commit461e147c952859612269fadb72447f4b75457366 authoriko <mail@iko.soy> dateSat 11 Jul 2026, 17:24 (3 months ago) parent29f4f3f
1 file changed+12−11
HyperCreditsMenubar/HyperCreditsApp.swift+12−11
HyperCreditsMenubar/HyperCreditsApp.swift+12−11
@@ -168,7 +168,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
168168
169169 private func showContextMenu() {
170170 if popover.isShown {
171− closePopover()
171+ popover.performClose(nil)
172172 }
173173
174174 let menu = NSMenu()
@@ -209,18 +209,19 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
209209
210210 // MARK: - Popover
211211
212+ /// Shows the popover if it isn't already visible.
213+ ///
214+ /// We don't toggle: the popover has `.transient` behavior, which closes it
215+ /// automatically when the user clicks outside it — including on the status
216+ /// item. By the time our `.leftMouseUp` action fires, a previously-shown
217+ /// popover has already closed, so `isShown` is `false` and a toggle would
218+ /// reopen it instead of dismissing it. Always showing means the first click
219+ /// opens and `.transient` handles the rest.
212220 private func togglePopover() {
213221 guard let button = statusItem.button else { return }
214− if popover.isShown {
215− closePopover()
216− } else {
217− popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)
218− NSApp.activate(ignoringOtherApps: true)
219− }
220− }
221−
222− private func closePopover() {
223− popover.performClose(nil)
222+ guard !popover.isShown else { return }
223+ popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)
224+ NSApp.activate(ignoringOtherApps: true)
224225 }
225226}
226227