summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBug Magnet <marco.nikic@mullvad.net>2024-10-18 18:07:20 +0200
committerBug Magnet <marco.nikic@mullvad.net>2024-10-28 10:33:32 +0100
commitb3e1c506c4fe7bb19c0cf13860a4675bedb3e7f7 (patch)
tree551da643c5e9cabcca3d907f35ad0c2d9a09265a
parent4cb784d9cc05088b77781feb25b80c1953e16259 (diff)
downloadmullvadvpn-b3e1c506c4fe7bb19c0cf13860a4675bedb3e7f7.tar.xz
mullvadvpn-b3e1c506c4fe7bb19c0cf13860a4675bedb3e7f7.zip
Fail to rewrite DNS settings with SwiftUI
-rw-r--r--ios/MullvadSettings/DNSSettings.swift13
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj16
-rw-r--r--ios/MullvadVPN/UI appearance/UIColor+Color.swift24
-rw-r--r--ios/MullvadVPN/View controllers/VPNSettings/CustomDNSSwiftUIView.swift86
-rw-r--r--ios/MullvadVPN/View controllers/VPNSettings/CustomDNSSwiftUIViewController.swift51
-rw-r--r--ios/MullvadVPN/View controllers/VPNSettings/ToggleStyle.swift52
-rw-r--r--ios/MullvadVPN/View controllers/VPNSettings/VPNSettingsViewController.swift3
-rwxr-xr-xios/build-wireguard-go.sh2
8 files changed, 246 insertions, 1 deletions
diff --git a/ios/MullvadSettings/DNSSettings.swift b/ios/MullvadSettings/DNSSettings.swift
index 4b7a3ae7cb..d120236e3d 100644
--- a/ios/MullvadSettings/DNSSettings.swift
+++ b/ios/MullvadSettings/DNSSettings.swift
@@ -29,6 +29,19 @@ public struct DNSBlockingOptions: OptionSet, Codable {
}
}
+ // TODO: Use localised strings ?
+ public var name: String {
+ switch self {
+ case .blockAdvertising: "Ads"
+ case .blockTracking: "Trackers"
+ case .blockMalware: "Malware"
+ case .blockGambling: "Gambling"
+ case .blockAdultContent: "Adult content"
+ case .blockSocialMedia: "Social media"
+ default: ""
+ }
+ }
+
public init(rawValue: UInt32) {
self.rawValue = rawValue
}
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 2bd37ffa6c..9cad7dc3fe 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -848,6 +848,10 @@
A9E0317A2ACB0AE70095D843 /* UIApplication+Stubs.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E031792ACB0AE70095D843 /* UIApplication+Stubs.swift */; };
A9E0317F2ACC331C0095D843 /* TunnelStatusBlockObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E0317D2ACC32920095D843 /* TunnelStatusBlockObserver.swift */; };
A9E034642ABB302000E59A5A /* UIEdgeInsets+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E034632ABB302000E59A5A /* UIEdgeInsets+Extensions.swift */; };
+ A9EBCE062CC2937F00146599 /* CustomDNSSwiftUIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EBCE052CC2937F00146599 /* CustomDNSSwiftUIViewController.swift */; };
+ A9EBCE082CC2945100146599 /* CustomDNSSwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EBCE072CC2945100146599 /* CustomDNSSwiftUIView.swift */; };
+ A9EBCE0A2CC2AB2400146599 /* UIColor+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EBCE092CC2AB2400146599 /* UIColor+Color.swift */; };
+ A9EBCE0C2CC2B5E000146599 /* ToggleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EBCE0B2CC2B5DF00146599 /* ToggleStyle.swift */; };
E1187ABC289BBB850024E748 /* OutOfTimeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1187ABA289BBB850024E748 /* OutOfTimeViewController.swift */; };
E1187ABD289BBB850024E748 /* OutOfTimeContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1187ABB289BBB850024E748 /* OutOfTimeContentView.swift */; };
E158B360285381C60002F069 /* String+AccountFormatting.swift in Sources */ = {isa = PBXBuildFile; fileRef = E158B35F285381C60002F069 /* String+AccountFormatting.swift */; };
@@ -2071,6 +2075,10 @@
A9E0317D2ACC32920095D843 /* TunnelStatusBlockObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelStatusBlockObserver.swift; sourceTree = "<group>"; };
A9E034632ABB302000E59A5A /* UIEdgeInsets+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIEdgeInsets+Extensions.swift"; sourceTree = "<group>"; };
A9EB4F9C2B7FAB21002A2D7A /* EphemeralPeerNegotiator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EphemeralPeerNegotiator.swift; sourceTree = "<group>"; };
+ A9EBCE052CC2937F00146599 /* CustomDNSSwiftUIViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomDNSSwiftUIViewController.swift; sourceTree = "<group>"; };
+ A9EBCE072CC2945100146599 /* CustomDNSSwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomDNSSwiftUIView.swift; sourceTree = "<group>"; };
+ A9EBCE092CC2AB2400146599 /* UIColor+Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Color.swift"; sourceTree = "<group>"; };
+ A9EBCE0B2CC2B5DF00146599 /* ToggleStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleStyle.swift; sourceTree = "<group>"; };
A9EC20E72A5D3A8C0040D56E /* CoordinatesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoordinatesTests.swift; sourceTree = "<group>"; };
A9F360332AAB626300F53531 /* VPNConnectionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNConnectionProtocol.swift; sourceTree = "<group>"; };
E1187ABA289BBB850024E748 /* OutOfTimeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OutOfTimeViewController.swift; sourceTree = "<group>"; };
@@ -2849,6 +2857,9 @@
5871167E2910035700D41AAC /* VPNSettingsInteractor.swift */,
58ACF6482655365700ACE4B7 /* VPNSettingsViewController.swift */,
587EB671271451E300123C75 /* VPNSettingsViewModel.swift */,
+ A9EBCE052CC2937F00146599 /* CustomDNSSwiftUIViewController.swift */,
+ A9EBCE072CC2945100146599 /* CustomDNSSwiftUIView.swift */,
+ A9EBCE0B2CC2B5DF00146599 /* ToggleStyle.swift */,
);
path = VPNSettings;
sourceTree = "<group>";
@@ -3023,6 +3034,7 @@
58CCA0152242560B004F3011 /* UIColor+Palette.swift */,
A9E034632ABB302000E59A5A /* UIEdgeInsets+Extensions.swift */,
585CA70E25F8C44600B47C62 /* UIMetrics.swift */,
+ A9EBCE092CC2AB2400146599 /* UIColor+Color.swift */,
);
path = "UI appearance";
sourceTree = "<group>";
@@ -5603,6 +5615,7 @@
58BFA5CC22A7CE1F00A6173D /* ApplicationConfiguration.swift in Sources */,
5891BF5125E66B1E006D6FB0 /* UIBarButtonItem+KeyboardNavigation.swift in Sources */,
58E511E628DDDEAC00B0BCDE /* CodingErrors+CustomErrorDescription.swift in Sources */,
+ A9EBCE082CC2945100146599 /* CustomDNSSwiftUIView.swift in Sources */,
58C76A0B2A338E4300100D75 /* BackgroundTask.swift in Sources */,
7A9CCCC32A96302800DD6A34 /* ApplicationCoordinator.swift in Sources */,
5864AF0729C78843005B0CD9 /* SettingsCellFactory.swift in Sources */,
@@ -5610,6 +5623,7 @@
587988C728A2A01F00E3DF54 /* AccountDataThrottling.swift in Sources */,
F04FBE612A8379EE009278D7 /* AppPreferences.swift in Sources */,
58DFF7D82B02774C00F864E0 /* ListItemPickerViewController.swift in Sources */,
+ A9EBCE0C2CC2B5E000146599 /* ToggleStyle.swift in Sources */,
5896CEF226972DEB00B0FAE8 /* AccountContentView.swift in Sources */,
7A3353932AAA089000F0A71C /* SimulatorTunnelInfo.swift in Sources */,
7A5869AB2B55527C00640D27 /* IPOverrideCoordinator.swift in Sources */,
@@ -5918,10 +5932,12 @@
58CEB2F52AFD0BB500E6E088 /* TextCellContentConfiguration.swift in Sources */,
58E20771274672CA00DE5D77 /* LaunchViewController.swift in Sources */,
F0E8CC032A4C753B007ED3B4 /* WelcomeViewController.swift in Sources */,
+ A9EBCE062CC2937F00146599 /* CustomDNSSwiftUIViewController.swift in Sources */,
584D26C4270C855B004EA533 /* VPNSettingsDataSource.swift in Sources */,
F0D8825B2B04F53600D3EF9A /* OutgoingConnectionData.swift in Sources */,
7A6F2FAF2AFE36E7006D0856 /* VPNSettingsInfoButtonItem.swift in Sources */,
7A6389DD2B7E3BD6008E77E1 /* CustomListDataSourceConfiguration.swift in Sources */,
+ A9EBCE0A2CC2AB2400146599 /* UIColor+Color.swift in Sources */,
5827B0BF2B14B37D00CCBBA1 /* Publisher+PreviousValue.swift in Sources */,
7A9CCCB62A96302800DD6A34 /* OutOfTimeCoordinator.swift in Sources */,
5827B0AA2B0F4C9100CCBBA1 /* EditAccessMethodViewControllerDelegate.swift in Sources */,
diff --git a/ios/MullvadVPN/UI appearance/UIColor+Color.swift b/ios/MullvadVPN/UI appearance/UIColor+Color.swift
new file mode 100644
index 0000000000..03ad81eea6
--- /dev/null
+++ b/ios/MullvadVPN/UI appearance/UIColor+Color.swift
@@ -0,0 +1,24 @@
+//
+// UIColor+Color.swift
+// MullvadVPN
+//
+// Created by Marco Nikic on 2024-10-18.
+// Copyright © 2024 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+import SwiftUI
+
+extension Color {
+ static var secondaryColor = Color(UIColor.secondaryColor)
+
+ enum Cell {
+ enum Background {
+ static let normal = Color(UIColor.Cell.Background.normal)
+ static let disabled = Color(UIColor.Cell.Background.disabled)
+ static let selected = Color(UIColor.Cell.Background.selected)
+ static let disabledSelected = Color(UIColor.Cell.Background.disabledSelected)
+ static let selectedAlt = Color(UIColor.Cell.Background.selectedAlt)
+ }
+ }
+}
diff --git a/ios/MullvadVPN/View controllers/VPNSettings/CustomDNSSwiftUIView.swift b/ios/MullvadVPN/View controllers/VPNSettings/CustomDNSSwiftUIView.swift
new file mode 100644
index 0000000000..be43ce3493
--- /dev/null
+++ b/ios/MullvadVPN/View controllers/VPNSettings/CustomDNSSwiftUIView.swift
@@ -0,0 +1,86 @@
+//
+// CustomDNSSwiftUIView.swift
+// MullvadVPN
+//
+// Created by Marco Nikic on 2024-10-18.
+// Copyright © 2024 Mullvad VPN AB. All rights reserved.
+//
+
+import MullvadSettings
+import SwiftUI
+
+class CustomDNSViewModel: ObservableObject {
+ @Published var blockAll = false
+ @Published var blockAdvertising = false
+ @Published var blockTracking = false
+ @Published var blockMalware = false
+ @Published var blockAdultContent = false
+ @Published var blockGambling = false
+ @Published var blockSocialMedia = false
+ @Published var enableCustomDNS = false
+ @Published var customDNSDomains: [DNSServerEntry] = []
+
+ @Published var isEditing = false
+ @Published var isExpanded = false
+
+ lazy var contentBlockers: [DNSRowViewModel] = [
+ DNSRowViewModel(name: "All", isEnabled: blockAll),
+ DNSRowViewModel(name: DNSBlockingOptions.blockAdvertising.name, isEnabled: blockAdvertising),
+ DNSRowViewModel(name: DNSBlockingOptions.blockTracking.name, isEnabled: blockTracking),
+ DNSRowViewModel(name: DNSBlockingOptions.blockMalware.name, isEnabled: blockMalware),
+ DNSRowViewModel(name: DNSBlockingOptions.blockAdultContent.name, isEnabled: blockAdultContent),
+ DNSRowViewModel(name: DNSBlockingOptions.blockGambling.name, isEnabled: blockGambling),
+ DNSRowViewModel(name: DNSBlockingOptions.blockSocialMedia.name, isEnabled: blockSocialMedia),
+ ]
+}
+
+class DNSRowViewModel: ObservableObject, Identifiable {
+ let name: String
+ @Published var isEnabled: Bool
+
+ init(name: String, isEnabled: Bool) {
+ self.name = name
+ self.isEnabled = isEnabled
+ }
+}
+
+struct CustomDNSSwiftUIView: View {
+ @ObservedObject var viewModel: CustomDNSViewModel
+
+ var body: some View {
+ GeometryReader { _ in
+ ScrollView {
+ Section {
+ DisclosureGroup("DNS content blockers", isExpanded: $viewModel.isExpanded) {
+ ForEach(viewModel.contentBlockers) { singleSetting in
+ DNSItemRow(viewModel: singleSetting)
+ .background(Color.Cell.Background.normal)
+ }
+ }
+ .listRowBackground(Color.Cell.Background.normal)
+ .foregroundColor(.white)
+ }
+ .background(Color.Cell.Background.normal)
+ .foregroundColor(.white)
+ }
+ }
+ .background(Color.secondaryColor)
+ }
+}
+
+struct DNSItemRow: View {
+ @ObservedObject var viewModel: DNSRowViewModel
+
+ var body: some View {
+ HStack {
+ Spacer()
+ Toggle(isOn: $viewModel.isEnabled, label: {
+ Text(viewModel.name)
+ }).toggleStyle(RedToggleStyle())
+ }
+ }
+}
+
+#Preview {
+ CustomDNSSwiftUIView(viewModel: CustomDNSViewModel())
+}
diff --git a/ios/MullvadVPN/View controllers/VPNSettings/CustomDNSSwiftUIViewController.swift b/ios/MullvadVPN/View controllers/VPNSettings/CustomDNSSwiftUIViewController.swift
new file mode 100644
index 0000000000..2e5e60f2c5
--- /dev/null
+++ b/ios/MullvadVPN/View controllers/VPNSettings/CustomDNSSwiftUIViewController.swift
@@ -0,0 +1,51 @@
+//
+// CustomDNSSwiftUIViewController.swift
+// MullvadVPN
+//
+// Created by Marco Nikic on 2024-10-18.
+// Copyright © 2024 Mullvad VPN AB. All rights reserved.
+//
+
+import MullvadSettings
+
+import Foundation
+import SwiftUI
+import UIKit
+
+class CustomDNSSwiftUIViewController: UIViewController {
+ private let interactor: VPNSettingsInteractor
+ private let alertPresenter: AlertPresenter
+
+ init(interactor: VPNSettingsInteractor, alertPresenter: AlertPresenter) {
+ self.interactor = interactor
+ self.alertPresenter = alertPresenter
+
+ super.init(nibName: nil, bundle: nil)
+ }
+
+ override func viewDidLoad() {
+ let rootView = CustomDNSSwiftUIView(viewModel: CustomDNSViewModel())
+
+ let hostingController = UIHostingController(rootView: rootView)
+
+ addChild(hostingController)
+
+ navigationItem.title = NSLocalizedString(
+ "NAVIGATION_TITLE",
+ tableName: "VPNSettings",
+ value: "DNS settings",
+ comment: ""
+ )
+
+ navigationItem.rightBarButtonItem = editButtonItem
+ navigationItem.rightBarButtonItem?.accessibilityIdentifier = .dnsSettingsEditButton
+
+ view.addConstrainedSubviews([hostingController.view]) {
+ hostingController.view.pinEdgesToSuperview()
+ }
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+}
diff --git a/ios/MullvadVPN/View controllers/VPNSettings/ToggleStyle.swift b/ios/MullvadVPN/View controllers/VPNSettings/ToggleStyle.swift
new file mode 100644
index 0000000000..4f0b081fb6
--- /dev/null
+++ b/ios/MullvadVPN/View controllers/VPNSettings/ToggleStyle.swift
@@ -0,0 +1,52 @@
+//
+// ToggleStyle.swift
+// MullvadVPN
+//
+// Created by Marco Nikic on 2024-10-18.
+// Copyright © 2024 Mullvad VPN AB. All rights reserved.
+//
+
+import SwiftUI
+
+struct RedToggleStyle: ToggleStyle {
+ let width: CGFloat = 50
+
+ func makeBody(configuration: Self.Configuration) -> some View {
+ HStack {
+ configuration.label
+ Spacer()
+
+ ZStack(alignment: configuration.isOn ? .trailing : .leading) {
+ RoundedRectangle(cornerRadius: 20)
+ .frame(width: width, height: width / 2)
+ .foregroundColor(.clear)
+ .overlay(
+ RoundedRectangle(cornerRadius: 25)
+ .stroke(.white, lineWidth: 2)
+ )
+
+ RoundedRectangle(cornerRadius: 20)
+ .frame(width: (width / 2) - 4, height: width / 2 - 6)
+ .padding(4)
+ .foregroundColor(configuration.isOn ? .green : .red)
+ .onTapGesture {
+ withAnimation {
+ configuration.$isOn.wrappedValue.toggle()
+ }
+ }
+ }
+ }
+ }
+}
+
+private struct ContainerView: View {
+ @State var isOn: Bool
+ var body: some View {
+ Toggle("hello", isOn: $isOn)
+ }
+}
+
+#Preview {
+ ContainerView(isOn: false).toggleStyle(RedToggleStyle())
+ .preferredColorScheme(.dark)
+}
diff --git a/ios/MullvadVPN/View controllers/VPNSettings/VPNSettingsViewController.swift b/ios/MullvadVPN/View controllers/VPNSettings/VPNSettingsViewController.swift
index c86db1b9d0..9a697acdaa 100644
--- a/ios/MullvadVPN/View controllers/VPNSettings/VPNSettingsViewController.swift
+++ b/ios/MullvadVPN/View controllers/VPNSettings/VPNSettingsViewController.swift
@@ -112,7 +112,8 @@ extension VPNSettingsViewController: VPNSettingsDataSourceDelegate {
}
func showDNSSettings() {
- let viewController = CustomDNSViewController(interactor: interactor, alertPresenter: alertPresenter)
+// let viewController = CustomDNSViewController(interactor: interactor, alertPresenter: alertPresenter)
+ let viewController = CustomDNSSwiftUIViewController(interactor: interactor, alertPresenter: alertPresenter)
navigationController?.pushViewController(viewController, animated: true)
}
diff --git a/ios/build-wireguard-go.sh b/ios/build-wireguard-go.sh
index dcb1f5831f..e26341ddbe 100755
--- a/ios/build-wireguard-go.sh
+++ b/ios/build-wireguard-go.sh
@@ -21,6 +21,8 @@ if [ "$SOURCE_PACKAGES_PATH" == "" ]; then
# When archiving, Xcode sets the action to "install"
if [ "$ACTION" == "install" ]; then
SOURCE_PACKAGES_PATH="$BUILD_DIR/../../../../../SourcePackages"
+ elif [ "$ENABLE_PREVIEWS" == "YES" ]; then
+ SOURCE_PACKAGES_PATH="$BUILD_DIR/../../../../../SourcePackages"
else
SOURCE_PACKAGES_PATH="$BUILD_DIR/../../SourcePackages"
fi