Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import Foundation
struct RealAppDiscardProgress { enum Action: String, Codable { case waitForIdentity, requestDiscard, waitForExit, complete }
private(set) var requestIssued = false private(set) var processGone = false private var stableExitObservations = 0
mutating func observe( launch: RealAppLaunchReceipt, retained: RealAppProcessIdentity, current: RealAppProcessIdentity?, presence: RealAppProcessPresence, windows: [RealWindow], closeRequested: Bool, cleanup: Bool ) throws -> Action { _ = try launch.validatedPID() guard launch.app != .finder, launch.app != .fixture, let birth = launch.launchDate, birth.timeIntervalSinceReferenceDate.isFinite else { throw RealityError("Safety stop: discard lacks an exact isolated application launch") }
if presence == .present { try retained.validateAvailableExitMetadata(against: launch) if let current { try current.validateAvailableExitMetadata(against: launch) } processGone = false stableExitObservations = 0 if requestIssued { return .waitForExit }
// A missing lookup is not an exit or a discard request. Revalidate on the next observation. guard let current, !retained.isTerminated, !current.isTerminated, retained.bundleID != nil, retained.bundleURL != nil, retained.launchDate != nil, current.bundleID != nil, current.bundleURL != nil, current.launchDate != nil else { return .waitForIdentity } try launch.validateDiscardIdentity( pid: retained.pid, bundleID: retained.bundleID, bundleURL: retained.bundleURL, launchDate: retained.launchDate, isTerminated: retained.isTerminated) try launch.validateDiscardIdentity( pid: current.pid, bundleID: current.bundleID, bundleURL: current.bundleURL, launchDate: current.launchDate, isTerminated: current.isTerminated) requestIssued = true return .requestDiscard }
processGone = try RealAppLaunchReadback.expectedExit( launch: launch, closeRequested: closeRequested || requestIssued, retained: retained, current: current, presence: presence, windows: windows, cleanup: cleanup) stableExitObservations = processGone ? stableExitObservations + 1 : 0 return stableExitObservations >= 3 ? .complete : .waitForExit }}