diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-11-01 06:33:49 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-11-01 08:47:58 +0100 |
| commit | 4da92196fba6f5d4899be96350e27d44d5cff653 (patch) | |
| tree | 70679d828318b88948daeebbee29fc5781697313 | |
| parent | 8b523fe3b84a2a28d231274dfdc0dce0cdcaaf68 (diff) | |
| download | mullvadvpn-4da92196fba6f5d4899be96350e27d44d5cff653.tar.xz mullvadvpn-4da92196fba6f5d4899be96350e27d44d5cff653.zip | |
Add TunnelBlockObserver
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 4 | ||||
| -rw-r--r-- | ios/MullvadVPN/TunnelManager/TunnelBlockObserver.swift | 60 |
2 files changed, 64 insertions, 0 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index d1d1a4c0e3..12d7a6d8ba 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -158,6 +158,7 @@ 587425C12299833500CA2045 /* RootContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587425C02299833500CA2045 /* RootContainerViewController.swift */; }; 5875960A26F371FC00BF6711 /* Tunnel+Messaging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5875960926F371FC00BF6711 /* Tunnel+Messaging.swift */; }; 5877D70F282137E8002FCFC7 /* SettingsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FF2C02281BDE02009EF542 /* SettingsManager.swift */; }; + 5878A27329091D6D0096FC88 /* TunnelBlockObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5878A27229091D6D0096FC88 /* TunnelBlockObserver.swift */; }; 5878A27529093A310096FC88 /* StorePaymentEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5878A27429093A310096FC88 /* StorePaymentEvent.swift */; }; 5878A27729093A4F0096FC88 /* StorePaymentBlockObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5878A27629093A4F0096FC88 /* StorePaymentBlockObserver.swift */; }; 5878A279290954790096FC88 /* ConnectInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5878A278290954790096FC88 /* ConnectInteractor.swift */; }; @@ -638,6 +639,7 @@ 5875960926F371FC00BF6711 /* Tunnel+Messaging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Tunnel+Messaging.swift"; sourceTree = "<group>"; }; 58781CC822AE7CA8009B9D8E /* RelayConstraints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayConstraints.swift; sourceTree = "<group>"; }; 58781CD422AFBA39009B9D8E /* RelaySelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelaySelector.swift; sourceTree = "<group>"; }; + 5878A27229091D6D0096FC88 /* TunnelBlockObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelBlockObserver.swift; sourceTree = "<group>"; }; 5878A27429093A310096FC88 /* StorePaymentEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorePaymentEvent.swift; sourceTree = "<group>"; }; 5878A27629093A4F0096FC88 /* StorePaymentBlockObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorePaymentBlockObserver.swift; sourceTree = "<group>"; }; 5878A278290954790096FC88 /* ConnectInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectInteractor.swift; sourceTree = "<group>"; }; @@ -1038,6 +1040,7 @@ 58B93A1226C3F13600A55733 /* TunnelState.swift */, 5842102F282D8A3C00F24E46 /* UpdateAccountDataOperation.swift */, 58421031282E42B000F24E46 /* UpdateDeviceDataOperation.swift */, + 5878A27229091D6D0096FC88 /* TunnelBlockObserver.swift */, ); path = TunnelManager; sourceTree = "<group>"; @@ -2150,6 +2153,7 @@ 58FEEB46260A028D00A621A8 /* GeoJSON.swift in Sources */, 753D6C0C28B4BF3E0052D9E1 /* ShortcutsManager.swift in Sources */, 58CE5E64224146200008646E /* AppDelegate.swift in Sources */, + 5878A27329091D6D0096FC88 /* TunnelBlockObserver.swift in Sources */, 5872D6E8286304DE00DB5F4E /* TermsOfService.swift in Sources */, 58E0A98827C8F46300FE6BDD /* Tunnel.swift in Sources */, 58ACF64F26567A7100ACE4B7 /* CustomSwitchContainer.swift in Sources */, diff --git a/ios/MullvadVPN/TunnelManager/TunnelBlockObserver.swift b/ios/MullvadVPN/TunnelManager/TunnelBlockObserver.swift new file mode 100644 index 0000000000..43b74bd33e --- /dev/null +++ b/ios/MullvadVPN/TunnelManager/TunnelBlockObserver.swift @@ -0,0 +1,60 @@ +// +// TunnelBlockObserver.swift +// MullvadVPN +// +// Created by pronebird on 26/10/2022. +// Copyright © 2022 Mullvad VPN AB. All rights reserved. +// + +import Foundation + +final class TunnelBlockObserver: TunnelObserver { + typealias DidLoadConfigurationHandler = (TunnelManager) -> Void + typealias DidUpdateTunnelStatusHandler = (TunnelManager, TunnelStatus) -> Void + typealias DidUpdateDeviceStateHandler = (TunnelManager, DeviceState) -> Void + typealias DidUpdateTunnelSettingsHandler = (TunnelManager, TunnelSettingsV2) -> Void + typealias DidFailWithErrorHandler = (TunnelManager, Error) -> Void + + private let didLoadConfiguration: DidLoadConfigurationHandler? + private let didUpdateTunnelStatus: DidUpdateTunnelStatusHandler? + private let didUpdateDeviceState: DidUpdateDeviceStateHandler? + private let didUpdateTunnelSettings: DidUpdateTunnelSettingsHandler? + private let didFailWithError: DidFailWithErrorHandler? + + init( + didLoadConfiguration: DidLoadConfigurationHandler? = nil, + didUpdateTunnelStatus: DidUpdateTunnelStatusHandler? = nil, + didUpdateDeviceState: DidUpdateDeviceStateHandler? = nil, + didUpdateTunnelSettings: DidUpdateTunnelSettingsHandler? = nil, + didFailWithError: DidFailWithErrorHandler? = nil + ) { + self.didLoadConfiguration = didLoadConfiguration + self.didUpdateTunnelStatus = didUpdateTunnelStatus + self.didUpdateDeviceState = didUpdateDeviceState + self.didUpdateTunnelSettings = didUpdateTunnelSettings + self.didFailWithError = didFailWithError + } + + func tunnelManagerDidLoadConfiguration(_ manager: TunnelManager) { + didLoadConfiguration?(manager) + } + + func tunnelManager(_ manager: TunnelManager, didUpdateTunnelStatus tunnelStatus: TunnelStatus) { + didUpdateTunnelStatus?(manager, tunnelStatus) + } + + func tunnelManager(_ manager: TunnelManager, didUpdateDeviceState deviceState: DeviceState) { + didUpdateDeviceState?(manager, deviceState) + } + + func tunnelManager( + _ manager: TunnelManager, + didUpdateTunnelSettings tunnelSettings: TunnelSettingsV2 + ) { + didUpdateTunnelSettings?(manager, tunnelSettings) + } + + func tunnelManager(_ manager: TunnelManager, didFailWithError error: Error) { + didFailWithError?(manager, error) + } +} |
