import AppKit @MainActor public final class VoiceOverObservation { private let center: NotificationCenter private var tokens: [any NSObjectProtocol] = [] init(center: NotificationCenter, onChange: @escaping @MainActor () -> Void) { self.center = center for name in [NSWorkspace.didLaunchApplicationNotification, NSWorkspace.didTerminateApplicationNotification] { tokens.append( center.addObserver(forName: name, object: nil, queue: .main) { _ in MainActor.assumeIsolated { onChange() } }) } } public func cancel() { for token in tokens { center.removeObserver(token) } tokens.removeAll() } isolated deinit { cancel() } }