vm: support disabling screenshots completely

Resolves #6620
This commit is contained in:
osy
2025-07-27 18:49:41 -07:00
parent cd76346069
commit 569f9a73a5
4 changed files with 25 additions and 6 deletions
+8
View File
@@ -91,6 +91,7 @@ struct ApplicationSettingsView: View {
}
struct DisplaySettingsView: View {
@AppStorage("NoScreenshot") var isNoScreenshot = false
@AppStorage("NoSaveScreenshot") var isNoSaveScreenshot = false
@AppStorage("QEMURendererBackend") var qemuRendererBackend: UTMQEMURendererBackend = .qemuRendererBackendDefault
@AppStorage("QEMURendererFPSLimit") var qemuRendererFpsLimit: Int = 0
@@ -98,9 +99,16 @@ struct DisplaySettingsView: View {
var body: some View {
Form {
Section(header: Text("Display")) {
Toggle(isOn: $isNoScreenshot) {
Text("Disable VM screenshot")
}.help("No VM screenshots will be taken.")
.onChange(of: isNoScreenshot) { newValue in
isNoSaveScreenshot = newValue
}
Toggle(isOn: $isNoSaveScreenshot) {
Text("Do not save VM screenshot to disk")
}.help("If enabled, any existing screenshot will be deleted the next time the VM is started.")
.disabled(isNoScreenshot)
}
Section(header: Text("QEMU Graphics Acceleration")) {
+5 -3
View File
@@ -326,9 +326,11 @@ final class UTMAppleVirtualMachine: UTMVirtualMachine {
continuation.resume(throwing: UTMAppleVirtualMachineError.operationNotAvailable)
return
}
Task { @MainActor in
await self.takeScreenshot()
try? self.saveScreenshot()
if self.isScreenshotEnabled {
Task { @MainActor in
await self.takeScreenshot()
try? self.saveScreenshot()
}
}
apple.pause { result in
continuation.resume(with: result)
+3 -1
View File
@@ -538,7 +538,9 @@ extension UTMQemuVirtualMachine {
guard let monitor = await monitor else {
throw UTMQemuVirtualMachineError.invalidVmState
}
await takeScreenshot()
if isScreenshotEnabled {
await takeScreenshot()
}
try await monitor.qemuStop()
}
+9 -2
View File
@@ -331,8 +331,12 @@ struct UTMVirtualMachineScreenshot {
}
extension UTMVirtualMachine {
private var isScreenshotSaveEnabled: Bool {
!UserDefaults.standard.bool(forKey: "NoSaveScreenshot")
nonisolated var isScreenshotEnabled: Bool {
!UserDefaults.standard.bool(forKey: "NoScreenshot")
}
nonisolated private var isScreenshotSaveEnabled: Bool {
isScreenshotEnabled && !UserDefaults.standard.bool(forKey: "NoSaveScreenshot")
}
private var screenshotUrl: URL {
@@ -349,6 +353,9 @@ extension UTMVirtualMachine {
timer.invalidate()
return
}
guard self.isScreenshotEnabled else {
return
}
if self.state == .started {
Task { @MainActor in
await self.takeScreenshot()