import CoreGraphics import Foundation struct TabViewConsoleSession: Decodable, Sendable { let onConsole: Bool let loginDone: Bool let screenLocked: Bool? private enum CodingKeys: String, CodingKey { case onConsole = "kCGSSessionOnConsoleKey" case loginDone = "kCGSessionLoginDoneKey" case screenLocked = "CGSSessionScreenIsLocked" } static func requireUnlockedConsole() throws { guard let dictionary = CGSessionCopyCurrentDictionary() else { throw RealityError( "Safety stop: Tab View reality requires a signed-in, active, unlocked desktop; console state is unavailable" ) } let session: Self do { let data = try PropertyListSerialization.data(fromPropertyList: dictionary, format: .binary, options: 0) session = try PropertyListDecoder().decode(Self.self, from: data) } catch { throw RealityError( "Safety stop: Tab View console state could not be verified: \(error). Input is withheld.") } try session.requireUnlocked() } func requireUnlocked() throws { guard onConsole, loginDone, screenLocked != true else { throw RealityError( "Safety stop: Tab View reality requires an active unlocked desktop: onConsole=\(onConsole), loginDone=\(loginDone), screenLocked=\(String(describing: screenLocked)). Input is withheld." ) } } }