diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index dd3a547..07d68be 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -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() diff --git a/Sources/tart/VM.swift b/Sources/tart/VM.swift index d93d875..a97ee2c 100644 --- a/Sources/tart/VM.swift +++ b/Sources/tart/VM.swift @@ -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