mirror of
https://github.com/utmapp/UTM.git
synced 2026-10-12 02:24:01 +00:00
scripting: add support for disposible mode
This commit is contained in:
+4
-1
@@ -141,11 +141,14 @@
|
||||
|
||||
<command name="start" code="UTMvstar">
|
||||
<direct-parameter description="Virtual machine to start." type="virtual machine"/>
|
||||
<parameter name="saving" code="SaVe" description="When false, do not save the VM changes to disk. Default value is true." type="boolean" optional="yes">
|
||||
<cocoa key="saveFlag"/>
|
||||
</parameter>
|
||||
</command>
|
||||
|
||||
<command name="suspend" code="UTMvsusp">
|
||||
<direct-parameter description="Virtual machine to suspend." type="virtual machine"/>
|
||||
<parameter name="saving" code="SaVe" description="Save VM state after suspend." type="boolean">
|
||||
<parameter name="saving" code="SaVe" description="Save VM state after suspend. Default value is false." type="boolean" optional="yes">
|
||||
<cocoa key="saveFlag"/>
|
||||
</parameter>
|
||||
</command>
|
||||
|
||||
@@ -125,7 +125,7 @@ extension SBObject: UTMScriptingWindow {}
|
||||
@objc optional var memory: String { get } // RAM size.
|
||||
@objc optional var backend: UTMScriptingBackend { get } // Emulation/virtualization engine used.
|
||||
@objc optional var status: UTMScriptingStatus { get } // Current running status.
|
||||
@objc optional func start()
|
||||
@objc optional func startSaving(_ saving: Bool)
|
||||
@objc optional func suspendSaving(_ saving: Bool)
|
||||
@objc optional func stopBy(_ by: UTMScriptingStopMethod)
|
||||
}
|
||||
|
||||
@@ -121,7 +121,14 @@ class UTMScriptingVirtualMachineImpl: NSObject {
|
||||
}
|
||||
|
||||
@objc func start(_ command: NSScriptCommand) {
|
||||
let shouldSaveState = command.evaluatedArguments?["saveFlag"] as? Bool ?? true
|
||||
withScriptCommand(command) { [self] in
|
||||
if !shouldSaveState {
|
||||
guard let vm = vm as? UTMQemuVirtualMachine else {
|
||||
throw ScriptingError.operationNotSupported
|
||||
}
|
||||
vm.isRunningAsSnapshot = true
|
||||
}
|
||||
data.run(vm: vm, startImmediately: false)
|
||||
if vm.state == .vmStopped {
|
||||
try await vm.vmStart()
|
||||
@@ -134,7 +141,7 @@ class UTMScriptingVirtualMachineImpl: NSObject {
|
||||
}
|
||||
|
||||
@objc func suspend(_ command: NSScriptCommand) {
|
||||
let shouldSaveState = command.evaluatedArguments?["doneFlag"] as? Bool ?? false
|
||||
let shouldSaveState = command.evaluatedArguments?["saveFlag"] as? Bool ?? false
|
||||
withScriptCommand(command) { [self] in
|
||||
try await vm.vmPause(save: shouldSaveState)
|
||||
}
|
||||
@@ -158,10 +165,12 @@ class UTMScriptingVirtualMachineImpl: NSObject {
|
||||
extension UTMScriptingVirtualMachineImpl {
|
||||
enum ScriptingError: Error, LocalizedError {
|
||||
case operationNotAvailable
|
||||
case operationNotSupported
|
||||
|
||||
var localizedDescription: String {
|
||||
switch self {
|
||||
case .operationNotAvailable: return NSLocalizedString("Operation not available.", comment: "UTMScriptingVirtualMachineImpl")
|
||||
case .operationNotSupported: return NSLocalizedString("Operation not supported by the backend.", comment: "UTMScriptingVirtualMachineImpl")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -203,9 +203,12 @@ extension UTMCtl {
|
||||
@Flag(name: .shortAndLong, help: "Attach to the first serial port after start.")
|
||||
var attach: Bool = false
|
||||
|
||||
@Flag(help: "Run VM as a snapshot and do not save changes to disk.")
|
||||
var disposible: Bool = false
|
||||
|
||||
func run(with application: UTMScriptingApplication) throws {
|
||||
let vm = try virtualMachine(forIdentifier: identifer, in: application)
|
||||
vm.start!()
|
||||
vm.startSaving!(!disposible)
|
||||
if attach {
|
||||
var attachCommand = Attach()
|
||||
attachCommand.environment = environment
|
||||
|
||||
Reference in New Issue
Block a user