Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add shutting down notification #4

Merged
merged 1 commit into from
Jun 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions RosettaVM/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, VZVirtualMachineDelegate {
}
}
}

func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
do {
if self.virtualMachine.canRequestStop == true {
let alert = NSAlert()
alert.messageText = "Stopping VM"
alert.informativeText = "Sent a stop command to the guest operating system. You might need to manually trigger the shutdown within the guest OS if it doesn't shutdown automatically."

alert.beginSheetModal(for: self.window)

try self.virtualMachine.requestStop()
return NSApplication.TerminateReply.terminateCancel
} else {
Expand All @@ -420,7 +426,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, VZVirtualMachineDelegate {
alert.informativeText = "Could not automatically shut down the guest operating system: \(error.localizedDescription)"
alert.addButton(withTitle: "Force close")
alert.addButton(withTitle: "Continue running")

var forceClose: NSApplication.TerminateReply = .terminateLater
alert.beginSheetModal(for: self.window) { (result) in
switch result {
Expand Down