aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/ErrorPresenter.swift
blob: 1eb2b041bd8c093358712e9f2aed56468f956486 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// SPDX-License-Identifier: MIT
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.

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?()
        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?()
        }
    }
}