mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-02 13:29:44 +08:00
* New host<>guest transport/protocol implementation * Implemented minimal legacy guest protocol to maintain clipboard functionality for guests that can't run the latest VirtualBuddyGuest app * Fix missing dependency * Change VMBridge Swift package to remote * Disable VirtualBuddyGuest clipboard sharing support on legacy OSes, leave macOS 13 support for shared folder mount
100 lines
3.3 KiB
Swift
100 lines
3.3 KiB
Swift
/*
|
||
See LICENSE folder for this sample’s licensing information.
|
||
|
||
Abstract:
|
||
Helper that creates various configuration objects exposed in the `VZVirtualMachineConfiguration`.
|
||
*/
|
||
|
||
import Foundation
|
||
import Virtualization
|
||
|
||
struct MacOSVirtualMachineConfigurationHelper: VirtualMachineConfigurationHelper {
|
||
let vm: VBVirtualMachine
|
||
let savedState: VBSavedStatePackage?
|
||
|
||
func createInstallDevice(installImageURL: URL) throws -> VZStorageDeviceConfiguration {
|
||
fatalError()
|
||
}
|
||
|
||
func createBootLoader() -> VZBootLoader {
|
||
return VZMacOSBootLoader()
|
||
}
|
||
|
||
func createGraphicsDevices() -> [VZGraphicsDeviceConfiguration] {
|
||
let graphicsConfiguration = VZMacGraphicsDeviceConfiguration()
|
||
|
||
graphicsConfiguration.displays = vm.configuration.hardware.displayDevices.map(\.vzDisplay)
|
||
|
||
return [graphicsConfiguration]
|
||
}
|
||
|
||
func createAdditionalBlockDevices() async throws -> [VZVirtioBlockDeviceConfiguration] {
|
||
var devices = try storageDeviceContainer.additionalBlockDevices(guestType: vm.configuration.systemType)
|
||
|
||
if vm.configuration.guestAdditionsEnabled, await vm.guestAppSupport != .unsupported {
|
||
do {
|
||
if let disk = try await VZVirtioBlockDeviceConfiguration.guestAdditionsDisk(for: vm.configuration) {
|
||
devices.append(disk)
|
||
}
|
||
} catch {
|
||
assertionFailure("VZVirtioBlockDeviceConfiguration initialization failed for guest additions disk: \(error)")
|
||
}
|
||
}
|
||
|
||
return devices
|
||
}
|
||
|
||
func createKeyboardConfiguration() -> VZKeyboardConfiguration {
|
||
if #available(macOS 14.0, *) {
|
||
switch vm.configuration.hardware.keyboardDevice.kind {
|
||
case .generic:
|
||
return VZUSBKeyboardConfiguration()
|
||
case .mac:
|
||
return VZMacKeyboardConfiguration()
|
||
}
|
||
} else {
|
||
return VZUSBKeyboardConfiguration()
|
||
}
|
||
}
|
||
|
||
func createEntropyDevices() -> [VZEntropyDeviceConfiguration] {
|
||
[VZVirtioEntropyDeviceConfiguration()]
|
||
}
|
||
|
||
@available(macOS 15.0, *)
|
||
func createUSBControllers() -> [VZUSBControllerConfiguration] {
|
||
let xhci = VZXHCIControllerConfiguration()
|
||
return [xhci]
|
||
}
|
||
|
||
@available(macOS 27.0, *)
|
||
static func createProvisioningOptions(for vm: VBVirtualMachine) -> VZMacGuestProvisioningOptions? {
|
||
guard vm.configuration.provisioningEnabled, let provisioning = vm.configuration.provisioning else { return nil }
|
||
|
||
return createProvisioningOptions(with: provisioning)
|
||
}
|
||
|
||
@available(macOS 27.0, *)
|
||
static func createProvisioningOptions(with provisioning: VBMacProvisioningConfiguration) -> VZMacGuestProvisioningOptions {
|
||
let options = VZMacGuestProvisioningOptions()
|
||
|
||
options.enablesRemoteLogin = provisioning.enablesRemoteLogin
|
||
options.fullName = provisioning.fullName
|
||
options.username = provisioning.username
|
||
options.password = provisioning.password
|
||
options.logsInAutomatically = provisioning.logsInAutomatically
|
||
|
||
return options
|
||
}
|
||
}
|
||
|
||
// MARK: - Configuration Models -> Virtualization
|
||
|
||
extension VBDisplayDevice {
|
||
|
||
var vzDisplay: VZMacGraphicsDisplayConfiguration {
|
||
VZMacGraphicsDisplayConfiguration(widthInPixels: width, heightInPixels: height, pixelsPerInch: pixelsPerInch)
|
||
}
|
||
|
||
}
|