Skip to content

Commit

Permalink
display(macOS): update clock with QEMU GA when waking from sleep
Browse files Browse the repository at this point in the history
Resolves #5252
  • Loading branch information
osy committed May 29, 2023
1 parent 3a9c8b4 commit 6f07ed0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Platform/macOS/Display/VMDisplayWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class VMDisplayWindowController: NSWindowController {
self.init(window: nil)
self.vm = vm
self.onClose = onClose
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(didWake), name: NSWorkspace.didWakeNotification, object: nil)
}

deinit {
NSWorkspace.shared.notificationCenter.removeObserver(self, name: NSWorkspace.didWakeNotification, object: nil)
}

@IBAction func stopButtonPressed(_ sender: Any) {
Expand Down Expand Up @@ -374,3 +379,12 @@ extension VMDisplayWindowController: UTMVirtualMachineDelegate {
}
}
}

// MARK: - Computer wakeup
extension VMDisplayWindowController {
@objc private func didWake(_ notification: NSNotification) {
if let qemuVM = vm as? UTMQemuVirtualMachine, let ga = qemuVM.guestAgent {
ga.guestSetTime(NSDate.now.timeIntervalSince1970)
}
}
}
14 changes: 14 additions & 0 deletions Platform/macOS/VMHeadlessSessionState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ import IOKit.pwr_mgt
self.onStop = onStop
super.init()
vm.delegate = self
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(didWake), name: NSWorkspace.didWakeNotification, object: nil)
}

deinit {
NSWorkspace.shared.notificationCenter.removeObserver(self, name: NSWorkspace.didWakeNotification, object: nil)
}
}

Expand Down Expand Up @@ -96,3 +101,12 @@ extension Notification.Name {
static let vmSessionEnded = Self("VMSessionEnded")
static let vmSessionError = Self("VMSessionError")
}

// MARK: - Computer wakeup
extension VMHeadlessSessionState {
@objc private func didWake(_ notification: NSNotification) {
if let qemuVM = vm as? UTMQemuVirtualMachine, let ga = qemuVM.guestAgent {
ga.guestSetTime(NSDate.now.timeIntervalSince1970)
}
}
}

0 comments on commit 6f07ed0

Please sign in to comment.