From 3077f4a1b9f5c41ac23cbb14f99cb6c9b13f8615 Mon Sep 17 00:00:00 2001 From: Marcel Mendes Filho Date: Mon, 23 Dec 2024 11:03:20 -0300 Subject: [PATCH] fix: #157 Simulator isn't visible on booting it from Control Room --- ControlRoom/Controllers/SimCtl.swift | 8 +++++++- ControlRoom/Controllers/SnapshotCtl+Commands.swift | 4 ++++ ControlRoom/Controllers/SnapshotCtl.swift | 8 +++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ControlRoom/Controllers/SimCtl.swift b/ControlRoom/Controllers/SimCtl.swift index ed9d80f..ad7f28b 100644 --- a/ControlRoom/Controllers/SimCtl.swift +++ b/ControlRoom/Controllers/SimCtl.swift @@ -42,7 +42,13 @@ enum SimCtl: CommandLineCommandExecuter { } static func boot(_ simulator: Simulator) { - execute(.boot(simulator: simulator)) + /// No need to check if Simulator app is already running since no second SImulator app will be spawned + SnapshotCtl.startSimulatorApp { + /// Wait for a little while Simulator app starts running, then proceed to boot simulator + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + execute(.boot(simulator: simulator)) + } + } } static func shutdown(_ simulator: String, completion: ((Result) -> Void)? = nil) { diff --git a/ControlRoom/Controllers/SnapshotCtl+Commands.swift b/ControlRoom/Controllers/SnapshotCtl+Commands.swift index ff9f5b1..48f05cc 100644 --- a/ControlRoom/Controllers/SnapshotCtl+Commands.swift +++ b/ControlRoom/Controllers/SnapshotCtl+Commands.swift @@ -27,6 +27,10 @@ extension SnapshotCtl { Command("/bin/mkdir", arguments:["-p", "\(devicesPath)/\(snapshotsFolder)/\(deviceId)/\(snapshotName)"]) } + /// Open app + static func open(app: String) -> Command { + Command("/usr/bin/open", arguments: ["-a", app]) + } } } diff --git a/ControlRoom/Controllers/SnapshotCtl.swift b/ControlRoom/Controllers/SnapshotCtl.swift index 854b8a5..9f494f6 100644 --- a/ControlRoom/Controllers/SnapshotCtl.swift +++ b/ControlRoom/Controllers/SnapshotCtl.swift @@ -93,10 +93,16 @@ enum SnapshotCtl: CommandLineCommandExecuter { } } + static func startSimulatorApp(completion: @escaping (() -> Void)) { + execute(.open(app: "Simulator.app")) { _ in + return completion() + } + } + private static func getSnapshotAttributes(_ snapshotPath: String) -> URLFileAttribute { let snapshotURL: URL = URL(fileURLWithPath: snapshotPath) let snapshotAttributes = URLFileAttribute(url: snapshotURL) return snapshotAttributes } - + }