2018-12-29 10:03:41 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-06-17 14:56:46 +00:00
|
|
|
// Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.
|
2018-12-29 10:03:41 +00:00
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
class ErrorPresenter: ErrorPresenterProtocol {
|
|
|
|
static func showErrorAlert(title: String, message: String, from sourceVC: AnyObject?, onPresented: (() -> Void)?, onDismissal: (() -> Void)?) {
|
|
|
|
let alert = NSAlert()
|
|
|
|
alert.messageText = title
|
|
|
|
alert.informativeText = message
|
|
|
|
onPresented?()
|
2019-01-05 08:46:28 +00:00
|
|
|
if let sourceVC = sourceVC as? NSViewController {
|
|
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
|
|
sourceVC.view.window!.makeKeyAndOrderFront(nil)
|
|
|
|
alert.beginSheetModal(for: sourceVC.view.window!) { _ in
|
|
|
|
onDismissal?()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alert.runModal()
|
|
|
|
onDismissal?()
|
|
|
|
}
|
2018-12-29 10:03:41 +00:00
|
|
|
}
|
|
|
|
}
|