summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-11-01 06:16:04 +0100
committerAndrej Mihajlov <and@mullvad.net>2022-11-01 08:45:47 +0100
commit0ae390b4d67964ced5f3221c9de56fba5f0aa89d (patch)
tree85e38ec87b87c6dd5a81346547f68f2b23975a74
parent4f171aa45200f2412b29be2ba23a8e17d1536194 (diff)
downloadmullvadvpn-0ae390b4d67964ced5f3221c9de56fba5f0aa89d.tar.xz
mullvadvpn-0ae390b4d67964ced5f3221c9de56fba5f0aa89d.zip
Add connect interactor
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj4
-rw-r--r--ios/MullvadVPN/ConnectInteractor.swift53
-rw-r--r--ios/MullvadVPN/ConnectViewController.swift62
-rw-r--r--ios/MullvadVPN/SceneDelegate.swift4
4 files changed, 87 insertions, 36 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 4335c710f4..2a42abcc5e 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -160,6 +160,7 @@
5877D70F282137E8002FCFC7 /* SettingsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FF2C02281BDE02009EF542 /* SettingsManager.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 */; };
587988C728A2A01F00E3DF54 /* AccountDataThrottling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587988C628A2A01F00E3DF54 /* AccountDataThrottling.swift */; };
587A01FC23F1F0BE00B68763 /* SimulatorTunnelProviderHost.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587A01FB23F1F0BE00B68763 /* SimulatorTunnelProviderHost.swift */; };
587AD7C623421D7000E93A53 /* TunnelSettingsV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587AD7C523421D7000E93A53 /* TunnelSettingsV1.swift */; };
@@ -638,6 +639,7 @@
58781CD422AFBA39009B9D8E /* RelaySelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelaySelector.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>"; };
587988C628A2A01F00E3DF54 /* AccountDataThrottling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountDataThrottling.swift; sourceTree = "<group>"; };
587A01FB23F1F0BE00B68763 /* SimulatorTunnelProviderHost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorTunnelProviderHost.swift; sourceTree = "<group>"; };
587AD7C523421D7000E93A53 /* TunnelSettingsV1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TunnelSettingsV1.swift; sourceTree = "<group>"; };
@@ -1226,6 +1228,7 @@
58B43C1825F77DB60002C8C3 /* ConnectContentView.swift */,
58A1AA8B23F5584B009F7EA6 /* ConnectionPanelView.swift */,
58CCA00F224249A1004F3011 /* ConnectViewController.swift */,
+ 5878A278290954790096FC88 /* ConnectInteractor.swift */,
5871FB95254ADE4E0051A0A4 /* ConsolidatedApplicationLog.swift */,
5896AE83246D5889005B36CB /* CustomDateComponentsFormatting.swift */,
582BB1B0229569620055B6EF /* CustomNavigationBar.swift */,
@@ -2087,6 +2090,7 @@
58F2E146276A2C9900A79513 /* StopTunnelOperation.swift in Sources */,
E1187ABC289BBB850024E748 /* OutOfTimeViewController.swift in Sources */,
58293FB125124117005D0BB5 /* CustomTextField.swift in Sources */,
+ 5878A279290954790096FC88 /* ConnectInteractor.swift in Sources */,
582AE3102440A6CA00E6733A /* AccountTokenInput.swift in Sources */,
5820EDAB288FF0D2006BF4E4 /* DeviceRowView.swift in Sources */,
75FD0C2128B108570021E33E /* ShortcutsDataSource.swift in Sources */,
diff --git a/ios/MullvadVPN/ConnectInteractor.swift b/ios/MullvadVPN/ConnectInteractor.swift
new file mode 100644
index 0000000000..579febf1aa
--- /dev/null
+++ b/ios/MullvadVPN/ConnectInteractor.swift
@@ -0,0 +1,53 @@
+//
+// ConnectInteractor.swift
+// MullvadVPN
+//
+// Created by pronebird on 26/10/2022.
+// Copyright © 2022 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+
+final class ConnectInteractor {
+ private let tunnelManager: TunnelManager
+ private var tunnelObserver: TunnelObserver?
+
+ var didUpdateDeviceState: ((DeviceState) -> Void)?
+ var didUpdateTunnelStatus: ((TunnelStatus) -> Void)?
+
+ var tunnelStatus: TunnelStatus {
+ return tunnelManager.tunnelStatus
+ }
+
+ var deviceState: DeviceState {
+ return tunnelManager.deviceState
+ }
+
+ init(tunnelManager: TunnelManager) {
+ self.tunnelManager = tunnelManager
+
+ let tunnelObserver = TunnelBlockObserver(
+ didUpdateTunnelStatus: { [weak self] tunnelManager, tunnelStatus in
+ self?.didUpdateTunnelStatus?(tunnelStatus)
+ },
+ didUpdateDeviceState: { [weak self] tunnelManager, deviceState in
+ self?.didUpdateDeviceState?(deviceState)
+ }
+ )
+ tunnelManager.addObserver(tunnelObserver)
+
+ self.tunnelObserver = tunnelObserver
+ }
+
+ func startTunnel() {
+ tunnelManager.startTunnel()
+ }
+
+ func stopTunnel() {
+ tunnelManager.stopTunnel()
+ }
+
+ func reconnectTunnel(selectNewRelay: Bool) {
+ tunnelManager.reconnectTunnel(selectNewRelay: selectNewRelay)
+ }
+}
diff --git a/ios/MullvadVPN/ConnectViewController.swift b/ios/MullvadVPN/ConnectViewController.swift
index cb66dcccc7..ad16477ac7 100644
--- a/ios/MullvadVPN/ConnectViewController.swift
+++ b/ios/MullvadVPN/ConnectViewController.swift
@@ -24,10 +24,12 @@ protocol ConnectViewControllerDelegate: AnyObject {
func connectViewControllerShouldShowSelectLocationPicker(_ controller: ConnectViewController)
}
-class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainment, TunnelObserver {
+class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainment {
private static let geoJSONSourceFileName = "countries.geo.json"
private static let locationMarkerReuseIdentifier = "location"
+ private let interactor: ConnectInteractor
+
weak var delegate: ConnectViewControllerDelegate?
let notificationController = NotificationController()
@@ -51,7 +53,7 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen
}
var preferredHeaderBarPresentation: HeaderBarPresentation {
- switch TunnelManager.shared.deviceState {
+ switch interactor.deviceState {
case .loggedIn, .revoked:
return HeaderBarPresentation(
style: tunnelState.isSecured ? .secured : .unsecured,
@@ -74,12 +76,22 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen
// Avoid unnecessary animations, particularly when this property is changed from inside
// the `viewDidLoad`.
- let isViewVisible = self.viewIfLoaded?.window != nil
+ let isViewVisible = viewIfLoaded?.window != nil
updateLocation(animated: isViewVisible)
}
}
+ init(interactor: ConnectInteractor) {
+ self.interactor = interactor
+
+ super.init(nibName: nil, bundle: nil)
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
override func viewDidLoad() {
super.viewDidLoad()
@@ -110,15 +122,20 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen
for: .touchUpInside
)
- TunnelManager.shared.addObserver(self)
- tunnelState = TunnelManager.shared.tunnelStatus.state
+ interactor.didUpdateDeviceState = { [weak self] deviceState in
+ self?.setNeedsHeaderBarStyleAppearanceUpdate()
+ }
+
+ interactor.didUpdateTunnelStatus = { [weak self] tunnelStatus in
+ self?.tunnelState = tunnelStatus.state
+ }
+
+ tunnelState = interactor.tunnelStatus.state
addSubviews()
setupMapView()
updateLocation(animated: false)
addNotificationController()
-
- TunnelManager.shared.addObserver(self)
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
@@ -168,31 +185,6 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen
})
}
- // MARK: - TunnelObserver
-
- func tunnelManagerDidLoadConfiguration(_ manager: TunnelManager) {
- // no-op
- }
-
- func tunnelManager(
- _ manager: TunnelManager,
- didUpdateTunnelSettings tunnelSettings: TunnelSettingsV2
- ) {
- // no-op
- }
-
- func tunnelManager(_ manager: TunnelManager, didUpdateDeviceState deviceState: DeviceState) {
- setNeedsHeaderBarStyleAppearanceUpdate()
- }
-
- func tunnelManager(_ manager: TunnelManager, didUpdateTunnelStatus tunnelStatus: TunnelStatus) {
- tunnelState = tunnelStatus.state
- }
-
- func tunnelManager(_ manager: TunnelManager, didFailWithError error: Error) {
- // no-op
- }
-
// MARK: - Private
private func updateUserInterfaceForTunnelStateChange() {
@@ -438,15 +430,15 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen
// MARK: - Actions
@objc func handleConnect(_ sender: Any) {
- TunnelManager.shared.startTunnel()
+ interactor.startTunnel()
}
@objc func handleDisconnect(_ sender: Any) {
- TunnelManager.shared.stopTunnel()
+ interactor.stopTunnel()
}
@objc func handleReconnect(_ sender: Any) {
- TunnelManager.shared.reconnectTunnel(selectNewRelay: true)
+ interactor.reconnectTunnel(selectNewRelay: true)
}
@objc func handleSelectLocation(_ sender: Any) {
diff --git a/ios/MullvadVPN/SceneDelegate.swift b/ios/MullvadVPN/SceneDelegate.swift
index 1113eefb18..d4fc584bf7 100644
--- a/ios/MullvadVPN/SceneDelegate.swift
+++ b/ios/MullvadVPN/SceneDelegate.swift
@@ -375,7 +375,9 @@ extension SceneDelegate {
}
private func makeConnectViewController() -> ConnectViewController {
- let connectController = ConnectViewController()
+ let connectController = ConnectViewController(
+ interactor: ConnectInteractor(tunnelManager: .shared)
+ )
connectController.delegate = self
return connectController