blob: 85f0de05ad738e76bc3f69248be7aac846f1d077 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
//
// TunnelErrorNotificationProvider.swift
// TunnelErrorNotificationProvider
//
// Created by pronebird on 20/08/2021.
// Copyright © 2021 Mullvad VPN AB. All rights reserved.
//
import Foundation
class TunnelErrorNotificationProvider: NotificationProvider, InAppNotificationProvider, TunnelObserver {
override var identifier: String {
return "net.mullvad.MullvadVPN.TunnelErrorNotificationProvider"
}
var notificationDescriptor: InAppNotificationDescriptor? {
guard let lastError = lastError else { return nil }
return InAppNotificationDescriptor(
identifier: identifier,
style: .error,
title: NSLocalizedString("TUNNEL_ERROR_INAPP_NOTIFICATION_TITLE", comment: ""),
body: lastError.errorChainDescription ?? "No error description provided."
)
}
private var lastError: TunnelManager.Error?
override init() {
super.init()
TunnelManager.shared.addObserver(self)
}
func tunnelManager(_ manager: TunnelManager, didUpdateTunnelState tunnelState: TunnelState) {
// Reset error with each new connection attempt
if case .connecting = tunnelState {
lastError = nil
}
// Tell manager to refresh displayed notifications
invalidate()
}
func tunnelManager(_ manager: TunnelManager, didUpdateTunnelSettings tunnelInfo: TunnelInfo?) {
// no-op
}
func tunnelManager(_ manager: TunnelManager, didFailWithError error: TunnelManager.Error) {
// Save tunnel error
lastError = error
// Tell manager to refresh displayed notifications
invalidate()
}
}
|