display(macOS): fix crash due to error dialog showing on background thread

Fixes #5472
This commit is contained in:
osy 2023-07-21 18:36:41 -07:00
parent f7c38dc52b
commit 4d26f4a20a
2 changed files with 5 additions and 1 deletions

View File

@ -146,7 +146,9 @@ extension VMDisplayQemuTerminalWindowController: CSPortDelegate {
}
func port(_ port: CSPort, didError error: String) {
showErrorAlert(error)
Task { @MainActor in
showErrorAlert(error)
}
}
func port(_ port: CSPort, didRecieveData data: Data) {

View File

@ -204,6 +204,7 @@ class VMDisplayWindowController: NSWindowController, UTMVirtualMachineDelegate {
// MARK: - Alert
@MainActor
func showErrorAlert(_ message: String, completionHandler handler: ((NSApplication.ModalResponse) -> Void)? = nil) {
let alert = NSAlert()
alert.alertStyle = .critical
@ -212,6 +213,7 @@ class VMDisplayWindowController: NSWindowController, UTMVirtualMachineDelegate {
alert.beginSheetModal(for: window!, completionHandler: handler)
}
@MainActor
func showConfirmAlert(_ message: String, confirmHandler handler: (() -> Void)? = nil) {
let alert = NSAlert()
alert.alertStyle = .informational