summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-11-01 06:36:13 +0100
committerAndrej Mihajlov <and@mullvad.net>2022-11-03 10:58:53 +0100
commit4a92804d47f26a3c2b55b68fa4893b98a053e7a2 (patch)
tree670fd11fa0ad77f1dbab9531cd6b32cece92ac5d
parentd63505854f5fb5c55ecf04811a845b77464b6027 (diff)
downloadmullvadvpn-4a92804d47f26a3c2b55b68fa4893b98a053e7a2.tar.xz
mullvadvpn-4a92804d47f26a3c2b55b68fa4893b98a053e7a2.zip
Add preferences interactor
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj4
-rw-r--r--ios/MullvadVPN/PreferencesInteractor.swift32
-rw-r--r--ios/MullvadVPN/PreferencesViewController.swift43
3 files changed, 46 insertions, 33 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index a290b56022..cd607eea5c 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -150,6 +150,7 @@
586A9516290133ED007BAF2B /* AnyIPAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 584D26BE270C550B004EA533 /* AnyIPAddress.swift */; };
586A95172901344A007BAF2B /* IPAddress+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AC115628F848D00037AF9A /* IPAddress+Codable.swift */; };
586E54FB27A2DF6D0029B88B /* SendTunnelProviderMessageOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 586E54FA27A2DF6D0029B88B /* SendTunnelProviderMessageOperation.swift */; };
+ 5871167F2910035700D41AAC /* PreferencesInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5871167E2910035700D41AAC /* PreferencesInteractor.swift */; };
5871FB96254ADE4E0051A0A4 /* ConsolidatedApplicationLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5871FB95254ADE4E0051A0A4 /* ConsolidatedApplicationLog.swift */; };
5871FBA0254C26C00051A0A4 /* NSRegularExpression+IPAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5871FB9F254C26BF0051A0A4 /* NSRegularExpression+IPAddress.swift */; };
5872631B283F6EAB00E14ADF /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 5872631A283F6EAB00E14ADF /* Intents.intentdefinition */; };
@@ -634,6 +635,7 @@
586A95112901321B007BAF2B /* IPv6Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPv6Endpoint.swift; sourceTree = "<group>"; };
586A951329013235007BAF2B /* AnyIPEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyIPEndpoint.swift; sourceTree = "<group>"; };
586E54FA27A2DF6D0029B88B /* SendTunnelProviderMessageOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendTunnelProviderMessageOperation.swift; sourceTree = "<group>"; };
+ 5871167E2910035700D41AAC /* PreferencesInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesInteractor.swift; sourceTree = "<group>"; };
5871FB95254ADE4E0051A0A4 /* ConsolidatedApplicationLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsolidatedApplicationLog.swift; sourceTree = "<group>"; };
5871FB9F254C26BF0051A0A4 /* NSRegularExpression+IPAddress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSRegularExpression+IPAddress.swift"; sourceTree = "<group>"; };
5872631A283F6EAB00E14ADF /* Intents.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = Intents.intentdefinition; sourceTree = "<group>"; };
@@ -1293,6 +1295,7 @@
584D26C3270C855A004EA533 /* PreferencesDataSource.swift */,
587EB6732714520600123C75 /* PreferencesDataSourceDelegate.swift */,
58ACF6482655365700ACE4B7 /* PreferencesViewController.swift */,
+ 5871167E2910035700D41AAC /* PreferencesInteractor.swift */,
587EB671271451E300123C75 /* PreferencesViewModel.swift */,
58F8AC0D25D3F8CE002BE0ED /* ProblemReportReviewViewController.swift */,
58EF580A25D69D7A00AEBA94 /* ProblemReportSubmissionOverlayView.swift */,
@@ -2198,6 +2201,7 @@
58293FB725138B88005D0BB5 /* CustomNavigationController.swift in Sources */,
587425C12299833500CA2045 /* RootContainerViewController.swift in Sources */,
5896AE84246D5889005B36CB /* CustomDateComponentsFormatting.swift in Sources */,
+ 5871167F2910035700D41AAC /* PreferencesInteractor.swift in Sources */,
587AD7C623421D7000E93A53 /* TunnelSettingsV1.swift in Sources */,
58E20771274672CA00DE5D77 /* LaunchViewController.swift in Sources */,
584D26C4270C855B004EA533 /* PreferencesDataSource.swift in Sources */,
diff --git a/ios/MullvadVPN/PreferencesInteractor.swift b/ios/MullvadVPN/PreferencesInteractor.swift
new file mode 100644
index 0000000000..8029669841
--- /dev/null
+++ b/ios/MullvadVPN/PreferencesInteractor.swift
@@ -0,0 +1,32 @@
+//
+// PreferencesInteractor.swift
+// MullvadVPN
+//
+// Created by pronebird on 31/10/2022.
+// Copyright © 2022 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+
+final class PreferencesInteractor {
+ private let tunnelManager: TunnelManager
+ private var tunnelObserver: TunnelObserver?
+
+ var dnsSettingsDidChange: ((DNSSettings) -> Void)?
+
+ init(tunnelManager: TunnelManager) {
+ self.tunnelManager = tunnelManager
+ tunnelObserver =
+ TunnelBlockObserver(didUpdateTunnelSettings: { [weak self] manager, newSettings in
+ self?.dnsSettingsDidChange?(newSettings.dnsSettings)
+ })
+ }
+
+ var dnsSettings: DNSSettings {
+ return tunnelManager.settings.dnsSettings
+ }
+
+ func setDNSSettings(_ newDNSSettings: DNSSettings, completion: (() -> Void)? = nil) {
+ tunnelManager.setDNSSettings(newDNSSettings, completionHandler: completion)
+ }
+}
diff --git a/ios/MullvadVPN/PreferencesViewController.swift b/ios/MullvadVPN/PreferencesViewController.swift
index 5d70790569..ea85b62b0f 100644
--- a/ios/MullvadVPN/PreferencesViewController.swift
+++ b/ios/MullvadVPN/PreferencesViewController.swift
@@ -6,19 +6,18 @@
// Copyright © 2021 Mullvad VPN AB. All rights reserved.
//
-import MullvadLogging
import UIKit
-class PreferencesViewController: UITableViewController, PreferencesDataSourceDelegate,
- TunnelObserver
-{
+class PreferencesViewController: UITableViewController, PreferencesDataSourceDelegate {
+ private let interactor: PreferencesInteractor
private let dataSource = PreferencesDataSource()
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
- init() {
+ init(interactor: PreferencesInteractor) {
+ self.interactor = interactor
super.init(style: .grouped)
}
@@ -45,8 +44,11 @@ class PreferencesViewController: UITableViewController, PreferencesDataSourceDel
)
navigationItem.rightBarButtonItem = editButtonItem
- TunnelManager.shared.addObserver(self)
- dataSource.update(from: TunnelManager.shared.settings.dnsSettings)
+ interactor.dnsSettingsDidChange = { [weak self] newDNSSettings in
+ self?.dataSource.update(from: newDNSSettings)
+ }
+
+ dataSource.update(from: interactor.dnsSettings)
}
override func setEditing(_ editing: Bool, animated: Bool) {
@@ -68,31 +70,6 @@ class PreferencesViewController: UITableViewController, PreferencesDataSourceDel
) {
let dnsSettings = dataModel.asDNSSettings()
- TunnelManager.shared.setDNSSettings(dnsSettings)
- }
-
- // MARK: - TunnelObserver
-
- func tunnelManagerDidLoadConfiguration(_ manager: TunnelManager) {
- // no-op
- }
-
- func tunnelManager(_ manager: TunnelManager, didUpdateTunnelStatus tunnelStatus: TunnelStatus) {
- // no-op
- }
-
- func tunnelManager(_ manager: TunnelManager, didFailWithError error: Error) {
- // no-op
- }
-
- func tunnelManager(
- _ manager: TunnelManager,
- didUpdateTunnelSettings tunnelSettings: TunnelSettingsV2
- ) {
- dataSource.update(from: tunnelSettings.dnsSettings)
- }
-
- func tunnelManager(_ manager: TunnelManager, didUpdateDeviceState deviceState: DeviceState) {
- // no-op
+ interactor.setDNSSettings(dnsSettings)
}
}