Skip to content

Commit 9176aba

Browse files
committed
vm: fix screenshot timer
Fixes #5541
1 parent fc6a6e1 commit 9176aba

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Services/UTMAppleVirtualMachine.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ extension UTMAppleVirtualMachine: VZVirtualMachineDelegate {
534534
}
535535
}
536536
}
537+
try? saveScreenshot()
537538
state = .stopped
538539
}
539540

Services/UTMQemuVirtualMachine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ extension UTMQemuVirtualMachine {
415415
throw UTMQemuVirtualMachineError.invalidVmState
416416
}
417417
await takeScreenshot()
418-
try saveScreenshot()
419418
try await monitor.qemuStop()
420419
}
421420

@@ -551,6 +550,7 @@ extension UTMQemuVirtualMachine: QEMUVirtualMachineDelegate {
551550
swtpm = nil
552551
ioService = nil
553552
ioServiceDelegate = nil
553+
try? saveScreenshot()
554554
state = .stopped
555555
}
556556

Services/UTMVirtualMachine.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ extension UTMVirtualMachine {
293293
if !isScreenshotSaveEnabled && !isRunningAsDisposible {
294294
try? deleteScreenshot()
295295
}
296-
return Timer.scheduledTimer(withTimeInterval: kScreenshotPeriodSeconds, repeats: true) { [weak self] timer in
296+
let timer = Timer(timeInterval: kScreenshotPeriodSeconds, repeats: true) { [weak self] timer in
297297
guard let self = self else {
298298
timer.invalidate()
299299
return
@@ -304,6 +304,8 @@ extension UTMVirtualMachine {
304304
}
305305
}
306306
}
307+
RunLoop.main.add(timer, forMode: .default)
308+
return timer
307309
}
308310

309311
func loadScreenshot() -> PlatformImage? {

0 commit comments

Comments
 (0)