Skip to content

Commit

Permalink
vm: fix screenshot timer
Browse files Browse the repository at this point in the history
Fixes #5541
  • Loading branch information
osy committed Aug 21, 2023
1 parent fc6a6e1 commit 9176aba
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions Services/UTMAppleVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ extension UTMAppleVirtualMachine: VZVirtualMachineDelegate {
}
}
}
try? saveScreenshot()
state = .stopped
}

Expand Down
2 changes: 1 addition & 1 deletion Services/UTMQemuVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ extension UTMQemuVirtualMachine {
throw UTMQemuVirtualMachineError.invalidVmState
}
await takeScreenshot()
try saveScreenshot()
try await monitor.qemuStop()
}

Expand Down Expand Up @@ -551,6 +550,7 @@ extension UTMQemuVirtualMachine: QEMUVirtualMachineDelegate {
swtpm = nil
ioService = nil
ioServiceDelegate = nil
try? saveScreenshot()
state = .stopped
}

Expand Down
4 changes: 3 additions & 1 deletion Services/UTMVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ extension UTMVirtualMachine {
if !isScreenshotSaveEnabled && !isRunningAsDisposible {
try? deleteScreenshot()
}
return Timer.scheduledTimer(withTimeInterval: kScreenshotPeriodSeconds, repeats: true) { [weak self] timer in
let timer = Timer(timeInterval: kScreenshotPeriodSeconds, repeats: true) { [weak self] timer in
guard let self = self else {
timer.invalidate()
return
Expand All @@ -304,6 +304,8 @@ extension UTMVirtualMachine {
}
}
}
RunLoop.main.add(timer, forMode: .default)
return timer
}

func loadScreenshot() -> PlatformImage? {
Expand Down

0 comments on commit 9176aba

Please sign in to comment.