Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import Foundation
@MainActorfinal class AccessibilityPanelSession { enum State: Equatable { case closed case hidden case visible(CGRect) }
private(set) var state = State.closed private let isTrusted: () -> Bool private let windowFrame: () throws -> CGRect? private let present: (CGRect) -> Void private let hide: () -> Void private let polling: (Bool) -> Void private let reportError: (any Error) -> Void
init( isTrusted: @escaping () -> Bool, windowFrame: @escaping () throws -> CGRect?, present: @escaping (CGRect) -> Void, hide: @escaping () -> Void, polling: @escaping (Bool) -> Void, reportError: @escaping (any Error) -> Void ) { self.isTrusted = isTrusted self.windowFrame = windowFrame self.present = present self.hide = hide self.polling = polling self.reportError = reportError }
func show() { if state == .closed { state = .hidden } refresh() }
func refresh() { guard state != .closed else { return } guard !isTrusted() else { close(); return } do { guard let frame = try windowFrame() else { conceal(); return } let wasHidden = state == .hidden guard state != .visible(frame) else { return } state = .visible(frame) present(frame) if wasHidden { polling(true) } } catch { close() reportError(error) } }
func close() { conceal() state = .closed }
private func conceal() { guard case .visible = state else { return } polling(false) hide() state = .hidden }}