macOS: Present tunnel activation errors from the window when possible

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-01-05 14:26:20 +05:30
parent 252d940d34
commit df8b400850
2 changed files with 27 additions and 19 deletions

View File

@ -20,29 +20,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.statusItem = createStatusBarItem(with: statusMenu)
tunnelsManager.tunnelsListDelegate = statusMenu
tunnelsManager.activationDelegate = self
tunnelsManager.activationDelegate = statusMenu
}
}
}
extension AppDelegate: TunnelsManagerActivationDelegate {
func tunnelActivationAttemptFailed(tunnel: TunnelContainer, error: TunnelsManagerActivationAttemptError) {
ErrorPresenter.showErrorAlert(error: error, from: nil)
}
func tunnelActivationAttemptSucceeded(tunnel: TunnelContainer) {
// Nothing to do
}
func tunnelActivationFailed(tunnel: TunnelContainer, error: TunnelsManagerActivationError) {
ErrorPresenter.showErrorAlert(error: error, from: nil)
}
func tunnelActivationSucceeded(tunnel: TunnelContainer) {
// Nothing to do
}
}
func createStatusBarItem(with statusMenu: StatusMenu) -> NSStatusItem {
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
if let statusBarImage = NSImage(named: "WireGuardMacStatusBarIcon") {

View File

@ -217,3 +217,29 @@ extension StatusMenu: TunnelsManagerListDelegate {
manageTunnelsRootVC?.tunnelsListVC?.tunnelRemoved(at: index)
}
}
extension StatusMenu: TunnelsManagerActivationDelegate {
func tunnelActivationAttemptFailed(tunnel: TunnelContainer, error: TunnelsManagerActivationAttemptError) {
if let manageTunnelsRootVC = manageTunnelsRootVC, manageTunnelsWindow.isVisible {
ErrorPresenter.showErrorAlert(error: error, from: manageTunnelsRootVC)
} else {
ErrorPresenter.showErrorAlert(error: error, from: nil)
}
}
func tunnelActivationAttemptSucceeded(tunnel: TunnelContainer) {
// Nothing to do
}
func tunnelActivationFailed(tunnel: TunnelContainer, error: TunnelsManagerActivationError) {
if let manageTunnelsRootVC = manageTunnelsRootVC, manageTunnelsWindow.isVisible {
ErrorPresenter.showErrorAlert(error: error, from: manageTunnelsRootVC)
} else {
ErrorPresenter.showErrorAlert(error: error, from: nil)
}
}
func tunnelActivationSucceeded(tunnel: TunnelContainer) {
// Nothing to do
}
}