summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndreas Lif <andreas.lif@shortcut.io>2022-06-02 17:55:18 +0200
committerAndrej Mihajlov <and@mullvad.net>2022-06-03 10:39:16 +0200
commit1488e78cd0b709c6d84b6f58b18affc996623b4d (patch)
tree77938e4bb722a52dc98fc105b6d54eab92f5fc26
parenteaf335fc913a7d73a269e778f77b389c050be600 (diff)
downloadmullvadvpn-1488e78cd0b709c6d84b6f58b18affc996623b4d.tar.xz
mullvadvpn-1488e78cd0b709c6d84b6f58b18affc996623b4d.zip
Add option to block adult content and gambling
-rw-r--r--ios/MullvadVPN/DNSSettings.swift2
-rw-r--r--ios/MullvadVPN/PreferencesDataSource.swift66
-rw-r--r--ios/MullvadVPN/PreferencesViewModel.swift26
3 files changed, 92 insertions, 2 deletions
diff --git a/ios/MullvadVPN/DNSSettings.swift b/ios/MullvadVPN/DNSSettings.swift
index bee5b1d7f1..f841b6cb1b 100644
--- a/ios/MullvadVPN/DNSSettings.swift
+++ b/ios/MullvadVPN/DNSSettings.swift
@@ -18,6 +18,8 @@ struct DNSBlockingOptions: OptionSet, Codable {
static let blockAdvertising = DNSBlockingOptions(rawValue: 1 << 0)
static let blockTracking = DNSBlockingOptions(rawValue: 1 << 1)
static let blockMalware = DNSBlockingOptions(rawValue: 1 << 2)
+ static let blockAdultContent = DNSBlockingOptions(rawValue: 1 << 3)
+ static let blockGambling = DNSBlockingOptions(rawValue: 1 << 4)
var serverAddress: IPv4Address? {
if isEmpty {
diff --git a/ios/MullvadVPN/PreferencesDataSource.swift b/ios/MullvadVPN/PreferencesDataSource.swift
index 63482db47f..46c0dc5470 100644
--- a/ios/MullvadVPN/PreferencesDataSource.swift
+++ b/ios/MullvadVPN/PreferencesDataSource.swift
@@ -49,6 +49,8 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat
case blockAdvertising
case blockTracking
case blockMalware
+ case blockAdultContent
+ case blockGambling
case useCustomDNS
case addDNSServer
case dnsServer(_ uniqueID: UUID)
@@ -309,7 +311,7 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat
private func updateSnapshot() {
var newSnapshot = DataSourceSnapshot<Section, Item>()
newSnapshot.appendSections([.mullvadDNS, .customDNS])
- newSnapshot.appendItems([.blockAdvertising, .blockTracking, .blockMalware], in: .mullvadDNS)
+ newSnapshot.appendItems([.blockAdvertising, .blockTracking, .blockMalware, .blockAdultContent, .blockGambling], in: .mullvadDNS)
newSnapshot.appendItems([.useCustomDNS], in: .customDNS)
let dnsServerItems = viewModel.customDNSDomains.map { entry in
@@ -377,6 +379,40 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat
return cell
+ case .blockAdultContent:
+ let cell = tableView.dequeueReusableCell(withIdentifier: CellReuseIdentifiers.settingSwitch.rawValue, for: indexPath) as! SettingsSwitchCell
+
+ cell.titleLabel.text = NSLocalizedString(
+ "BLOCK_ADULT_CELL_LABEL",
+ tableName: "Preferences",
+ value: "Block adult content",
+ comment: ""
+ )
+ cell.accessibilityHint = nil
+ cell.setOn(viewModel.blockAdultContent, animated: false)
+ cell.action = { [weak self] isOn in
+ self?.setBlockAdultContent(isOn)
+ }
+
+ return cell
+
+ case .blockGambling:
+ let cell = tableView.dequeueReusableCell(withIdentifier: CellReuseIdentifiers.settingSwitch.rawValue, for: indexPath) as! SettingsSwitchCell
+
+ cell.titleLabel.text = NSLocalizedString(
+ "BLOCK_GAMBLING_CELL_LABEL",
+ tableName: "Preferences",
+ value: "Block gambling",
+ comment: ""
+ )
+ cell.accessibilityHint = nil
+ cell.setOn(viewModel.blockGambling, animated: false)
+ cell.action = { [weak self] isOn in
+ self?.setBlockGambling(isOn)
+ }
+
+ return cell
+
case .useCustomDNS:
let cell = tableView.dequeueReusableCell(withIdentifier: CellReuseIdentifiers.settingSwitch.rawValue, for: indexPath) as! SettingsSwitchCell
@@ -476,6 +512,34 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat
}
}
+ private func setBlockAdultContent(_ isEnabled: Bool) {
+ let oldViewModel = viewModel
+
+ viewModel.setBlockAdultContent(isEnabled)
+
+ if oldViewModel.customDNSPrecondition != viewModel.customDNSPrecondition {
+ reloadCustomDNSFooter()
+ }
+
+ if !isEditing {
+ delegate?.preferencesDataSource(self, didChangeViewModel: viewModel)
+ }
+ }
+
+ private func setBlockGambling(_ isEnabled: Bool) {
+ let oldViewModel = viewModel
+
+ viewModel.setBlockGambling(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 e303e5bae4..23ee33f570 100644
--- a/ios/MullvadVPN/PreferencesViewModel.swift
+++ b/ios/MullvadVPN/PreferencesViewModel.swift
@@ -78,6 +78,8 @@ struct PreferencesViewModel: Equatable {
private(set) var blockAdvertising: Bool
private(set) var blockTracking: Bool
private(set) var blockMalware: Bool
+ private(set) var blockAdultContent: Bool
+ private(set) var blockGambling: Bool
private(set) var enableCustomDNS: Bool
var customDNSDomains: [DNSServerEntry]
@@ -96,6 +98,16 @@ struct PreferencesViewModel: Equatable {
enableCustomDNS = false
}
+ mutating func setBlockAdultContent(_ newValue: Bool) {
+ blockAdultContent = newValue
+ enableCustomDNS = false
+ }
+
+ mutating func setBlockGambling(_ newValue: Bool) {
+ blockGambling = newValue
+ enableCustomDNS = false
+ }
+
mutating func setEnableCustomDNS(_ newValue: Bool) {
blockTracking = false
blockAdvertising = false
@@ -104,7 +116,7 @@ struct PreferencesViewModel: Equatable {
/// Precondition for enabling Custom DNS.
var customDNSPrecondition: CustomDNSPrecondition {
- if blockAdvertising || blockTracking || blockMalware {
+ if blockAdvertising || blockTracking || blockMalware || blockAdultContent || blockGambling {
return .conflictsWithOtherSettings
} else {
let hasValidDNSDomains = customDNSDomains.contains { entry in
@@ -128,6 +140,8 @@ struct PreferencesViewModel: Equatable {
blockAdvertising = dnsSettings.blockingOptions.contains(.blockAdvertising)
blockTracking = dnsSettings.blockingOptions.contains(.blockTracking)
blockMalware = dnsSettings.blockingOptions.contains(.blockMalware)
+ blockAdultContent = dnsSettings.blockingOptions.contains(.blockAdultContent)
+ blockGambling = dnsSettings.blockingOptions.contains(.blockGambling)
enableCustomDNS = dnsSettings.enableCustomDNS
customDNSDomains = dnsSettings.customDNSDomains.map { ipAddress in
return DNSServerEntry(identifier: UUID(), address: "\(ipAddress)")
@@ -141,6 +155,8 @@ struct PreferencesViewModel: Equatable {
mergedViewModel.blockAdvertising = other.blockAdvertising
mergedViewModel.blockTracking = other.blockTracking
mergedViewModel.blockMalware = other.blockMalware
+ mergedViewModel.blockAdultContent = other.blockAdultContent
+ mergedViewModel.blockGambling = other.blockGambling
mergedViewModel.enableCustomDNS = other.enableCustomDNS
var oldDNSDomains = customDNSDomains
@@ -218,6 +234,14 @@ struct PreferencesViewModel: Equatable {
blockingOptions.insert(.blockMalware)
}
+ if blockAdultContent {
+ blockingOptions.insert(.blockAdultContent)
+ }
+
+ if blockGambling {
+ blockingOptions.insert(.blockGambling)
+ }
+
var dnsSettings = DNSSettings()
dnsSettings.blockingOptions = blockingOptions
dnsSettings.enableCustomDNS = enableCustomDNS