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.

The frame watch reads a window's visibility on the main thread

Țugui Dragoșdf5990ef34c9
diff --git a/Peel/FrameWatch.swift b/Peel/FrameWatch.swift
index 6a42d035..493ae214 100644
--- a/Peel/FrameWatch.swift
+++ b/Peel/FrameWatch.swift
@@ -32,11 +32,14 @@ final class FrameWatch: NSObject {
link.add(to: .main, forMode: .common)
self.link = link
// The display asks no frames for a window out of sight (minimized, hidden, or covered), which is no hitch.
+ let window = view.window
sight = NotificationCenter.default.addObserver(
- forName: NSWindow.didChangeOcclusionStateNotification, object: view.window, queue: .main
- ) { [weak self] note in
- guard let window = note.object as? NSWindow, !window.occlusionState.contains(.visible) else { return }
- MainActor.assumeIsolated { self?.hitches.pause() }
+ forName: NSWindow.didChangeOcclusionStateNotification, object: window, queue: .main
+ ) { [weak self, weak window] _ in
+ MainActor.assumeIsolated {
+ guard let window, !window.occlusionState.contains(.visible) else { return }
+ self?.hitches.pause()
+ }
}
guard observer == nil else { return }
watchTheMainThread()