Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import ParcelCoreimport Synchronization
final class NativeFullscreenCancellation: Sendable { private let cancelled = Mutex(false)
func cancel() { cancelled.withLock { $0 = true } }
func check() throws { if cancelled.withLock({ $0 }) { throw CancellationError() } }}
@MainActorfunc performNativeFullscreenTransition<Request: Sendable>( window: WindowID, retain: @MainActor () async throws -> Request, change: @MainActor (Request, NativeFullscreenCancellation) async throws -> Bool, read: @MainActor (Request) async throws -> Bool, release: @MainActor (Request) async -> Void, timeout: Duration = .seconds(3)) async throws { let cancellation = NativeFullscreenCancellation() try await withTaskCancellationHandler { try Task.checkCancellation() let request = try await retain() do { try Task.checkCancellation() let target = try await change(request, cancellation) let deadline = ContinuousClock.now.advanced(by: timeout) repeat { try Task.checkCancellation() let actual = try await read(request) try Task.checkCancellation() if actual == target { await release(request) return } try await Task.sleep(for: .milliseconds(25)) } while ContinuousClock.now < deadline throw EngineWindowCommandError.fullscreenUnchanged(window) } catch { await release(request) throw error } } onCancel: { // A queued AX operation runs outside the caller's task context. cancellation.cancel() }}