Skip to content

Commit

Permalink
appdelegate: do not auto-quit when headless vm is running still
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Oct 10, 2022
1 parent bf531d5 commit 63e1bfa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Platform/macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {

@Setting("KeepRunningAfterLastWindowClosed") private var isKeepRunningAfterLastWindowClosed: Bool = false

private var hasRunningVirtualMachines: Bool {
guard let vmList = data?.vmWindows.keys else {
return false
}
return vmList.contains(where: { $0.state == .vmStarted || ($0.state == .vmPaused && !$0.hasSaveState) })
}

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
!isKeepRunningAfterLastWindowClosed // FIXME: check if any VMs are running once we support headless VMs
!isKeepRunningAfterLastWindowClosed && !hasRunningVirtualMachines
}

func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
Expand All @@ -29,7 +36,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

let vmList = data.vmWindows.keys
if vmList.contains(where: { $0.state == .vmStarted || ($0.state == .vmPaused && !$0.hasSaveState) }) { // There is at least 1 running VM
if hasRunningVirtualMachines { // There is at least 1 running VM
DispatchQueue.main.async {
let alert = NSAlert()
alert.alertStyle = .informational
Expand Down

0 comments on commit 63e1bfa

Please sign in to comment.