Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import AppKitimport Foundation
struct SetupHideIdentity: Codable, Equatable, Sendable { let pid: Int32 let launchDate: Double
init(receipt: RealAppLaunchReceipt, window: OwnedWindow) throws { _ = try receipt.validatedPID() guard window.app == .calculator, window.id > 0, receipt.app == window.app, receipt.pid == window.pid, let date = receipt.launchDate, date.timeIntervalSince1970.isFinite else { throw RealityError("Safety stop: hide allowlist requires a fresh owned Calculator launch and window") } pid = receipt.pid launchDate = date.timeIntervalSince1970 }}
struct SetupOwnedVisibility: Sendable { let window: OwnedWindow let launch: RealAppLaunchReceipt let identity: SetupHideIdentity let startingFrame: ScreenRect
@MainActor init(window: OwnedWindow, apps: RealApps) throws { let launch = try apps.validatedLaunchReceipt(for: window) let identity = try SetupHideIdentity(receipt: launch, window: window) guard let current = NSRunningApplication(processIdentifier: window.pid), !current.isHidden, let row = try FrameOracle.read().first(where: { $0.id == window.id && $0.pid == window.pid && $0.onscreen }) else { throw RealityError("Safety stop: hide target was not independently visible before Parcel launch") } self.window = window self.launch = launch self.identity = identity startingFrame = row.frame }
@MainActor func isHidden(apps: RealApps) throws -> Bool { _ = try apps.validatedLaunchReceipt(for: window) guard let current = NSRunningApplication(processIdentifier: window.pid) else { throw RealityError("Safety stop: owned hide target disappeared during readback") } return current.isHidden }
static func hiddenReadback(_ rows: [RealWindow], window: OwnedWindow, hidden: Bool) -> Bool { hidden && !rows.contains { $0.pid == window.pid && $0.layer == 0 && $0.onscreen } }
static func visibleReadback( _ rows: [RealWindow], window: OwnedWindow, hidden: Bool, startingFrame: ScreenRect ) -> Bool { !hidden && rows.contains { $0.pid == window.pid && $0.id == window.id && $0.layer == 0 && $0.onscreen && $0.frame.matches(startingFrame) } }
private struct RestorationReceipt: Codable { let window: OwnedWindow let launch: RealAppLaunchReceipt var unhideAccepted: Bool? var restored = false var observations: [Observation] = [] var failure: String? }
@MainActor func restore(apps: RealApps, directory: URL) async throws { var receipt = RestorationReceipt(window: window, launch: launch) let url = directory.appendingPathComponent("setup-owned-visibility-restoration.json") do { _ = try apps.validatedLaunchReceipt(for: window) guard let current = NSRunningApplication(processIdentifier: window.pid) else { throw RealityError("Safety stop: owned hide target disappeared before visibility restoration") } if current.isHidden { receipt.unhideAccepted = current.unhide() } _ = try await pollRealFrames(timeout: .milliseconds(500), samples: &receipt.observations) { rows in try Self.visibleReadback( rows, window: window, hidden: isHidden(apps: apps), startingFrame: startingFrame) } receipt.restored = true try encodeJSON(receipt, to: url) } catch { receipt.failure = String(describing: error) try encodeJSON(receipt, to: url) throw RealityError("Safety stop: owned application visibility restoration failed: \(error)") } }}