Use Ventura APIs for recovery mode (#175)

This commit is contained in:
Fedor Korotkov 2022-08-12 01:02:44 -04:00 committed by GitHub
parent 131827802a
commit 2cab49b3f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View File

@ -32,7 +32,7 @@ brews:
tap:
owner: cirruslabs
name: homebrew-cli
caveats: See the Github repository for more information
caveats: See the GitHub repository for more information
homepage: https://github.com/cirruslabs/tart
description: Run macOS VMs on Apple Silicon
skip_upload: auto

View File

@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7
import PackageDescription
let package = Package(

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

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()