Retrieve VM's IP for use in VNC after the VM is started #2 (#562)

This commit is contained in:
Nikolay Edigaryev 2023-07-17 12:51:43 +04:00 committed by GitHub
parent 4ce06279ff
commit 33ca96e1a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 13 deletions

View File

@ -220,17 +220,6 @@ struct Run: AsyncParsableCommand {
let task = Task {
do {
if let vncImpl = vncImpl {
let vncURL = try await vncImpl.waitForURL()
if noGraphics || ProcessInfo.processInfo.environment["CI"] != nil {
print("VNC server is running at \(vncURL)")
} else {
print("Opening \(vncURL)...")
NSWorkspace.shared.open(vncURL)
}
}
var resume = false
if #available(macOS 14, *) {
@ -243,7 +232,20 @@ struct Run: AsyncParsableCommand {
}
}
try await vm!.run(recovery: recovery, resume: resume)
try await vm!.start(recovery: recovery, resume: resume)
if let vncImpl = vncImpl {
let vncURL = try await vncImpl.waitForURL()
if noGraphics || ProcessInfo.processInfo.environment["CI"] != nil {
print("VNC server is running at \(vncURL)")
} else {
print("Opening \(vncURL)...")
NSWorkspace.shared.open(vncURL)
}
}
try await vm!.run()
if let vncImpl = vncImpl {
try vncImpl.stop()

View File

@ -225,7 +225,7 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
return try VM(vmDir: vmDir)
}
func run(recovery: Bool, resume shouldResume: Bool) async throws {
func start(recovery: Bool, resume shouldResume: Bool) async throws {
try network.run(sema)
if shouldResume {
@ -233,7 +233,9 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
} else {
try await start(recovery)
}
}
func run() async throws {
await withTaskCancellationHandler(operation: {
// Wait for the VM to finish running
// or for the exit condition