Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Sources/Pesty/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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 {
Expand Down