Skip to content

Commit

Permalink
Merge pull request #4 from diddledani/add-shutting-down-notice
Browse files Browse the repository at this point in the history
Add shutting down notification
  • Loading branch information
lucyllewy authored Jun 18, 2022
2 parents 0763768 + 0e0d32f commit 2877fb9
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 2877fb9

Please # to comment.