summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ios/MullvadVPN/PreferencesDataSource.swift34
-rw-r--r--ios/MullvadVPN/PreferencesViewModel.swift30
-rw-r--r--ios/MullvadVPN/en.lproj/Preferences.strings3
3 files changed, 61 insertions, 6 deletions
diff --git a/ios/MullvadVPN/PreferencesDataSource.swift b/ios/MullvadVPN/PreferencesDataSource.swift
index 2ec34c1a6d..63482db47f 100644
--- a/ios/MullvadVPN/PreferencesDataSource.swift
+++ b/ios/MullvadVPN/PreferencesDataSource.swift
@@ -48,6 +48,7 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat
private enum Item: Hashable {
case blockAdvertising
case blockTracking
+ case blockMalware
case useCustomDNS
case addDNSServer
case dnsServer(_ uniqueID: UUID)
@@ -308,7 +309,7 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat
private func updateSnapshot() {
var newSnapshot = DataSourceSnapshot<Section, Item>()
newSnapshot.appendSections([.mullvadDNS, .customDNS])
- newSnapshot.appendItems([.blockAdvertising, .blockTracking], in: .mullvadDNS)
+ newSnapshot.appendItems([.blockAdvertising, .blockTracking, .blockMalware], in: .mullvadDNS)
newSnapshot.appendItems([.useCustomDNS], in: .customDNS)
let dnsServerItems = viewModel.customDNSDomains.map { entry in
@@ -359,6 +360,23 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat
return cell
+ case .blockMalware:
+ let cell = tableView.dequeueReusableCell(withIdentifier: CellReuseIdentifiers.settingSwitch.rawValue, for: indexPath) as! SettingsSwitchCell
+
+ cell.titleLabel.text = NSLocalizedString(
+ "BLOCK_MALWARE_CELL_LABEL",
+ tableName: "Preferences",
+ value: "Block malware",
+ comment: ""
+ )
+ cell.accessibilityHint = nil
+ cell.setOn(viewModel.blockMalware, animated: false)
+ cell.action = { [weak self] isOn in
+ self?.setBlockMalware(isOn)
+ }
+
+ return cell
+
case .useCustomDNS:
let cell = tableView.dequeueReusableCell(withIdentifier: CellReuseIdentifiers.settingSwitch.rawValue, for: indexPath) as! SettingsSwitchCell
@@ -444,6 +462,20 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat
}
}
+ private func setBlockMalware(_ isEnabled: Bool) {
+ let oldViewModel = viewModel
+
+ viewModel.setBlockMalware(isEnabled)
+
+ if oldViewModel.customDNSPrecondition != viewModel.customDNSPrecondition {
+ reloadCustomDNSFooter()
+ }
+
+ if !isEditing {
+ delegate?.preferencesDataSource(self, didChangeViewModel: viewModel)
+ }
+ }
+
private func setEnableCustomDNS(_ isEnabled: Bool) {
viewModel.setEnableCustomDNS(isEnabled)
diff --git a/ios/MullvadVPN/PreferencesViewModel.swift b/ios/MullvadVPN/PreferencesViewModel.swift
index de4fdaba81..02107280b9 100644
--- a/ios/MullvadVPN/PreferencesViewModel.swift
+++ b/ios/MullvadVPN/PreferencesViewModel.swift
@@ -68,6 +68,7 @@ struct DNSServerEntry: Equatable, Hashable {
struct PreferencesViewModel: Equatable {
private(set) var blockAdvertising: Bool
private(set) var blockTracking: Bool
+ private(set) var blockMalware: Bool
private(set) var enableCustomDNS: Bool
var customDNSDomains: [DNSServerEntry]
@@ -81,6 +82,11 @@ struct PreferencesViewModel: Equatable {
enableCustomDNS = false
}
+ mutating func setBlockMalware(_ newValue: Bool) {
+ blockMalware = newValue
+ enableCustomDNS = false
+ }
+
mutating func setEnableCustomDNS(_ newValue: Bool) {
blockTracking = false
blockAdvertising = false
@@ -89,7 +95,7 @@ struct PreferencesViewModel: Equatable {
/// Precondition for enabling Custom DNS.
var customDNSPrecondition: CustomDNSPrecondition {
- if blockAdvertising || blockTracking {
+ if blockAdvertising || blockTracking || blockMalware {
return .conflictsWithOtherSettings
} else {
let hasValidDNSDomains = customDNSDomains.contains { entry in
@@ -110,8 +116,9 @@ struct PreferencesViewModel: Equatable {
}
init(from dnsSettings: DNSSettings = DNSSettings()) {
- blockAdvertising = dnsSettings.blockAdvertising
- blockTracking = dnsSettings.blockTracking
+ blockAdvertising = dnsSettings.blockingOptions.contains(.blockAdvertising)
+ blockTracking = dnsSettings.blockingOptions.contains(.blockTracking)
+ blockMalware = dnsSettings.blockingOptions.contains(.blockMalware)
enableCustomDNS = dnsSettings.enableCustomDNS
customDNSDomains = dnsSettings.customDNSDomains.map { ipAddress in
return DNSServerEntry(identifier: UUID(), address: "\(ipAddress)")
@@ -124,6 +131,7 @@ struct PreferencesViewModel: Equatable {
mergedViewModel.blockAdvertising = other.blockAdvertising
mergedViewModel.blockTracking = other.blockTracking
+ mergedViewModel.blockMalware = other.blockMalware
mergedViewModel.enableCustomDNS = other.enableCustomDNS
var oldDNSDomains = customDNSDomains
@@ -188,9 +196,21 @@ struct PreferencesViewModel: Equatable {
/// Converts view model into `DNSSettings`.
func asDNSSettings() -> DNSSettings {
+ var blockingOptions = DNSBlockingOptions()
+ if blockAdvertising {
+ blockingOptions.insert(.blockAdvertising)
+ }
+
+ if blockTracking {
+ blockingOptions.insert(.blockTracking)
+ }
+
+ if blockMalware {
+ blockingOptions.insert(.blockMalware)
+ }
+
var dnsSettings = DNSSettings()
- dnsSettings.blockAdvertising = blockAdvertising
- dnsSettings.blockTracking = blockTracking
+ dnsSettings.blockingOptions = blockingOptions
dnsSettings.enableCustomDNS = enableCustomDNS
dnsSettings.customDNSDomains = customDNSDomains.compactMap { entry in
return AnyIPAddress(entry.address)
diff --git a/ios/MullvadVPN/en.lproj/Preferences.strings b/ios/MullvadVPN/en.lproj/Preferences.strings
index 30be83d034..1bbb0150a5 100644
--- a/ios/MullvadVPN/en.lproj/Preferences.strings
+++ b/ios/MullvadVPN/en.lproj/Preferences.strings
@@ -5,6 +5,9 @@
"BLOCK_ADS_CELL_LABEL" = "Block ads";
/* No comment provided by engineer. */
+"BLOCK_MALWARE_CELL_LABEL" = "Block malware";
+
+/* No comment provided by engineer. */
"BLOCK_TRACKERS_CELL_LABEL" = "Block trackers";
/* No comment provided by engineer. */