Use Ventura APIs for recovery mode (#175)

This commit is contained in:
Fedor Korotkov
2022-08-12 08:02:44 +03:00
committed by GitHub
parent 131827802a
commit 2cab49b3f1
4 changed files with 16 additions and 3 deletions
+1
View File
@@ -5,6 +5,7 @@ import Dynamic
// Kudos to @saagarjha's VirtualApple for finding about _VZVirtualMachineStartOptions
extension VZVirtualMachine {
@available(macOS 12, *)
func start(_ recovery: Bool) async throws {
if !recovery {
// just use the regular API
+13 -1
View File
@@ -167,7 +167,19 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
try softnet.run()
}
try await virtualMachine.start(recovery)
DispatchQueue.main.sync {
Task {
if #available(macOS 13, *) {
// new API introduced in Ventura
let startOptions = VZMacOSVirtualMachineStartOptions()
startOptions.startUpFromMacOSRecovery = recovery
try await virtualMachine.start(options: startOptions)
} else {
// use method that also available on Monterey
try await virtualMachine.start(recovery)
}
}
}
await withTaskCancellationHandler(operation: {
sema.wait()