Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripting: expose icon in config #6916

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions Scripting/UTM.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@
<record-type name="qemu configuration" code="QeCf" description="QEMU virtual machine configuration.">
<property name="name" code="pnam" type="text"
description="Virtual machine name."/>

<property name="icon" code="IcOn" type="text"
description="Virtual machine icon."/>

<property name="notes" code="NoTe" type="text"
description="User-specified notes."/>
Expand Down Expand Up @@ -567,6 +570,9 @@
<property name="name" code="pnam" type="text"
description="Virtual machine name."/>

<property name="icon" code="IcOn" type="text"
description="Virtual machine icon."/>

<property name="notes" code="NoTe" type="text"
description="User-specified notes."/>

Expand Down
18 changes: 18 additions & 0 deletions Scripting/UTMScriptingConfigImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ extension UTMScriptingConfigImpl {
private func serializeQemuConfiguration(_ config: UTMQemuConfiguration) -> [AnyHashable : Any] {
[
"name": config.information.name,
"icon": config.information.iconURL?.deletingPathExtension().lastPathComponent ?? "",
"notes": config.information.notes ?? "",
"architecture": config.system.architecture.rawValue,
"machine": config.system.target.rawValue,
Expand Down Expand Up @@ -200,6 +201,7 @@ extension UTMScriptingConfigImpl {
private func serializeAppleConfiguration(_ config: UTMAppleConfiguration) -> [AnyHashable : Any] {
[
"name": config.information.name,
"icon": config.information.iconURL?.deletingPathExtension().lastPathComponent ?? "",
"notes": config.information.notes ?? "",
"memory": config.system.memorySize,
"cpuCores": config.system.cpuCount,
Expand Down Expand Up @@ -307,6 +309,13 @@ extension UTMScriptingConfigImpl {
if let name = record["name"] as? String, !name.isEmpty {
config.information.name = name
}
if let icon = record["icon"] as? String, !icon.isEmpty {
if let url = UTMConfigurationInfo.builtinIcon(named: icon) {
config.information.iconURL = url
} else {
throw ConfigurationError.iconNotFound(icon: icon)
}
}
if let notes = record["notes"] as? String, !notes.isEmpty {
config.information.notes = notes
}
Expand Down Expand Up @@ -530,6 +539,13 @@ extension UTMScriptingConfigImpl {
if let name = record["name"] as? String, !name.isEmpty {
config.information.name = name
}
if let icon = record["icon"] as? String, !icon.isEmpty {
if let url = UTMConfigurationInfo.builtinIcon(named: icon) {
config.information.iconURL = url
} else {
throw ConfigurationError.iconNotFound(icon: icon)
}
}
if let notes = record["notes"] as? String, !notes.isEmpty {
config.information.notes = notes
}
Expand Down Expand Up @@ -652,13 +668,15 @@ extension UTMScriptingConfigImpl {
case invalidDriveDescription
case indexNotFound(index: Int)
case deviceNotSupported
case iconNotFound(icon: String)

var errorDescription: String? {
switch self {
case .identifierNotFound(let id): return String.localizedStringWithFormat(NSLocalizedString("Identifier '%@' cannot be found.", comment: "UTMScriptingConfigImpl"), String(describing: id))
case .invalidDriveDescription: return NSLocalizedString("Drive description is invalid.", comment: "UTMScriptingConfigImpl")
case .indexNotFound(let index): return String.localizedStringWithFormat(NSLocalizedString("Index %lld cannot be found.", comment: "UTMScriptingConfigImpl"), index)
case .deviceNotSupported: return NSLocalizedString("This device is not supported by the target.", comment: "UTMScriptingConfigImpl")
case .iconNotFound(let icon): return String.localizedStringWithFormat(NSLocalizedString("The icon named '%@' cannot be found in the built-in icons.", comment: "UTMScriptingConfigImpl"), icon)
}
}
}
Expand Down
Loading