Fixed --no-graphics (#132)

Followup to #129 which broke CLI integration because `--no-graphics` option didn't wait for anything.
This commit is contained in:
Fedor Korotkov 2022-06-20 10:28:10 -04:00 committed by GitHub
parent b581db5be4
commit 2020324ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -37,9 +37,14 @@ struct Run: AsyncParsableCommand {
let vmDir = try VMStorageLocal().open(name)
vm = try VM(vmDir: vmDir)
Task {
let runTask = Task {
do {
try await vm!.run(recovery)
// wait for VM to be in a final state before exit
while !(vm?.inFinalState ?? false) {
try await Task.sleep(nanoseconds: 1_000_000)
}
Foundation.exit(0)
} catch {
@ -65,12 +70,12 @@ struct Run: AsyncParsableCommand {
} catch {
print("Failed to get an IP for screen sharing: \(error)")
}
while !(vm?.inFinalState ?? false) {
try await Task.sleep(nanoseconds: 1_000_000)
}
} else if !noGraphics {
runUI()
}
// wait for VM to get into a final state
try await runTask.value
}
private func runUI() {