From 184e84603ef7cbcc5d385c9d024aca4ee23fd86f Mon Sep 17 00:00:00 2001 From: Alvie Stoddard Date: Fri, 24 Jul 2026 12:17:50 -0700 Subject: [PATCH] Show bar when Pesty is reopened --- Sources/Pesty/AppController.swift | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sources/Pesty/AppController.swift b/Sources/Pesty/AppController.swift index 168016f..3746e75 100644 --- a/Sources/Pesty/AppController.swift +++ b/Sources/Pesty/AppController.swift @@ -17,6 +17,7 @@ final class AppController: NSObject, NSApplicationDelegate { private var pasteStackController: PasteStackWindowController? private var keyMonitor: Any? private let copyToast = CopyToastController() + private var isReopenPresentationPending = false private(set) var previousApp: NSRunningApplication? private(set) var lastActiveApp: NSRunningApplication? @@ -56,6 +57,33 @@ final class AppController: NSObject, NSApplicationDelegate { } } + func applicationShouldHandleReopen(_ sender: NSApplication, + hasVisibleWindows flag: Bool) -> Bool { + // Finder, Spotlight, and the Dock deliver user-initiated reopens here. + // Deliberately do not use applicationDidBecomeActive for this: showing + // the bar activates Pesty itself, which would otherwise feed back into + // another bar presentation. + guard !flag, + !isReopenPresentationPending, + !hasVisiblePestySurface else { return true } + + isReopenPresentationPending = true + DispatchQueue.main.async { [weak self] in + guard let self else { return } + self.isReopenPresentationPending = false + + // A Pesty surface may have appeared between the reopen event and + // this run-loop turn (for example, Settings during onboarding). + guard !self.hasVisiblePestySurface else { return } + self.showBar() + } + return true + } + + private var hasVisiblePestySurface: Bool { + NSApp.windows.contains { $0.isVisible && !$0.isMiniaturized } + } + @objc private func appActivated(_ note: Notification) { guard let app = note.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication else { return } if app.bundleIdentifier != Bundle.main.bundleIdentifier {