refactor: use auto-released notification observer api

This commit is contained in:
lwouis committed 2024-12-24 02:17:59 +01:00
1 parent 6215b65ec9
commit 9e932799ee
2 files changed
+12 -8

No files matched your search

+2 -2
View File
@@ -2,10 +2,10 @@ import Cocoa
class SpacesEvents {
static func observe() {
NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.activeSpaceDidChangeNotification, object: nil, queue: nil, using: handleEvent)
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(handleEvent), name: NSWorkspace.activeSpaceDidChangeNotification, object: nil)
}
private static func handleEvent(_ notification: Notification) {
@objc private static func handleEvent(_ notification: Notification) {
Logger.debug(notification.name.rawValue)
// if UI was kept open during Space transition, the Spaces may be obsolete; we refresh them
Spaces.refreshSpacesAndWindows()
+10 -6
View File
@@ -258,12 +258,16 @@ class ScrollView: NSScrollView {
}
private func observeScrollingEvents() {
NotificationCenter.default.addObserver(forName: NSScrollView.didEndLiveScrollNotification, object: nil, queue: nil) { [weak self] _ in
self?.isCurrentlyScrolling = false
}
NotificationCenter.default.addObserver(forName: NSScrollView.willStartLiveScrollNotification, object: nil, queue: nil) { [weak self] _ in
self?.isCurrentlyScrolling = true
}
NotificationCenter.default.addObserver(self, selector: #selector(scrollingStarted), name: NSScrollView.willStartLiveScrollNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(scrollingEnded), name: NSScrollView.didEndLiveScrollNotification, object: nil)
}
@objc private func scrollingStarted() {
isCurrentlyScrolling = true
}
@objc private func scrollingEnded() {
isCurrentlyScrolling = false
}
private func resetHoveredWindow() {