Repository Public
1// Time from starting an isolated instance of the app to its first window being on screen (ms).2// Usage: launch-time <path/to/binary> <data-dir>3import CoreGraphics4import Foundation5let args = CommandLine.arguments6let process = Process()7process.executableURL = URL(fileURLWithPath: args[1])8process.arguments = ["-SPTermDataDir", args[2], "-SPTermFresh", "1"]9process.standardOutput = FileHandle.nullDevice10process.standardError = FileHandle.nullDevice11let start = Date()12try! process.run()13let pid = Int(process.processIdentifier)14while Date().timeIntervalSince(start) < 10 {15 let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as? [[String: Any]] ?? []16 if list.contains(where: { ($0["kCGWindowOwnerPID"] as? Int) == pid && ($0["kCGWindowLayer"] as? Int) == 0 }) { break }17 usleep(5_000)18}19print(Int(Date().timeIntervalSince(start) * 1000))20process.terminate()21process.waitUntilExit()22