Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Scripting/UTM.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,12 @@
<responds-to command="update configuration">
<cocoa method="updateConfiguration:"/>
</responds-to>

<responds-to command="reload configuration">
<cocoa method="reloadConfiguration:"/>
</responds-to>
</class-extension>

<command name="update configuration" code="UTMcUpDt" description="Update the configuration of the virtual machine. The VM must be in the stopped state.">
<direct-parameter description="Virtual machine to configure." type="virtual machine"/>
<parameter name="with" code="UpCf" description="The configuration to update the virtual machine. You cannot change the backend with this!">
Expand All @@ -408,6 +412,10 @@
</parameter>
</command>

<command name="reload configuration" code="UTMcReLd" description="Reload the configuration of the virtual machine from disk, discarding any unsaved in-memory changes. Useful when the .utm bundle has been modified externally (e.g. by an automation tool) and UTM's cached configuration needs to be refreshed. The VM must be in the stopped state.">
<direct-parameter description="Virtual machine to reload." type="virtual machine"/>
</command>

<record-type name="qemu configuration" code="QeCf" description="QEMU virtual machine configuration.">
<property name="name" code="pnam" type="text"
description="Virtual machine name."/>
Expand Down
9 changes: 9 additions & 0 deletions Scripting/UTMScriptingVirtualMachineImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ class UTMScriptingVirtualMachineImpl: NSObject, UTMScriptable {
try await data.delete(vm: box, alsoRegistry: true)
}
}

@objc func reloadConfiguration(_ command: NSScriptCommand) {
withScriptCommand(command) { [self] in
guard vm.state == .stopped else {
throw ScriptingError.notStopped
}
try data.discardChanges(for: box)
}
}

@objc func clone(_ command: NSCloneCommand) {
let properties = command.evaluatedArguments?["WithProperties"] as? [AnyHashable : Any]
Expand Down