Don't use dispatchMain (#123)

This commit is contained in:
Fedor Korotkov 2022-06-14 11:31:31 -04:00 committed by GitHub
parent 4cc8a9925a
commit 7759c72a76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 21 deletions

View File

@ -37,23 +37,7 @@ struct Run: AsyncParsableCommand {
let vmDir = try VMStorageLocal().open(name)
vm = try VM(vmDir: vmDir)
await withThrowingTaskGroup(of: Void.self) { group in
if vnc {
group.addTask(operation: {
do {
print("Waiting for the VM to boot...")
let resolvedIP = try await IP.resolveIP(vm!.config, secondsToWait: 60)
guard let ip = resolvedIP else {
throw IPNotFound()
}
let url = URL(string: "vnc://\(ip)")!
print("Opening \(url)")
NSWorkspace.shared.open(url)
} catch {
print("Failed to get an IP for screen sharing: \(error)")
}
})
}
try await withThrowingTaskGroup(of: Void.self) { group in
group.addTask {
do {
try await vm!.run(recovery)
@ -69,12 +53,26 @@ struct Run: AsyncParsableCommand {
Foundation.exit(1)
}
}
if noGraphics || vnc {
dispatchMain()
} else {
if vnc {
group.addTask(operation: {
do {
print("Waiting for the VM to boot...")
let resolvedIP = try await IP.resolveIP(vm!.config, secondsToWait: 60)
guard let ip = resolvedIP else {
throw IPNotFound()
}
let url = URL(string: "vnc://\(ip)")!
print("Opening \(url)")
NSWorkspace.shared.open(url)
} catch {
print("Failed to get an IP for screen sharing: \(error)")
}
})
} else if !noGraphics {
runUI()
}
try await group.waitForAll()
}
}