Skip to content

Commit

Permalink
display(macOS): fix crash due to error dialog showing on background t…
Browse files Browse the repository at this point in the history
…hread

Fixes #5472
  • Loading branch information
osy committed Jul 22, 2023
1 parent f7c38dc commit 4d26f4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions Platform/macOS/Display/VMDisplayWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4d26f4a

Please sign in to comment.