Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Keep Peel in the Dock while one of its windows is minimized

Țugui Dragoș7e00604fb8b2
diff --git a/Peel/Model/DockPresence.swift b/Peel/Model/DockPresence.swift
index a8362186..3eca7034 100644
--- a/Peel/Model/DockPresence.swift
+++ b/Peel/Model/DockPresence.swift
@@ -19,7 +19,7 @@ final class DockPresence {
observers.append(center.addObserver(forName: NSWindow.willCloseNotification, object: nil, queue: nil) { note in
let window = note.object as? NSWindow
MainActor.assumeIsolated {
- guard let window, window.canBecomeMain else { return }
+ guard let window, window.countsAsOpen else { return }
DockPresence.shared.update(closing: window)
}
})
@@ -57,10 +57,14 @@ final class DockPresence {
}
}
+extension NSWindow {
+ /// Whether the window is open for the person: minimized, or on screen and able to be main. AppKit answers that a
+ /// minimized window can't be main, and the menu bar panel and the menu bar item's own window never can.
+ var countsAsOpen: Bool { isMiniaturized || canBecomeMain && isVisible }
+}
+
extension [NSWindow] {
- /// Whether a window that can be main is on screen or minimized, leaving out `closing`. The menu bar panel and
- /// the menu bar item's own window can't be main.
func containsAnOpenWindow(besides closing: NSWindow? = nil) -> Bool {
- contains { $0 !== closing && $0.canBecomeMain && ($0.isVisible || $0.isMiniaturized) }
+ contains { $0 !== closing && $0.countsAsOpen }
}
}
diff --git a/PeelTests/DockPresenceTests.swift b/PeelTests/DockPresenceTests.swift
index 9613eacd..b917eb8d 100644
--- a/PeelTests/DockPresenceTests.swift
+++ b/PeelTests/DockPresenceTests.swift
@@ -26,7 +26,7 @@ struct DockPresenceTests {
}
}
-/// Never ordered in, so the window server makes no window for it.
+/// Never ordered in, so the window server makes no window for it. Like AppKit's, it can become main only on screen.
private final class StandInWindow: NSWindow {
var onScreen = false
var minimized = false
@@ -34,5 +34,5 @@ private final class StandInWindow: NSWindow {
override var isVisible: Bool { onScreen }
override var isMiniaturized: Bool { minimized }
- override var canBecomeMain: Bool { mayBeMain }
+ override var canBecomeMain: Bool { mayBeMain && onScreen }
}