-
Notifications
You must be signed in to change notification settings - Fork 389
/
Copy pathCustomDNSViewController.swift
151 lines (121 loc) · 4.83 KB
/
CustomDNSViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// CustomDNSViewController.swift
// MullvadVPN
//
// Created by Jon Petersson on 2023-11-09.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//
import MullvadSettings
import UIKit
class CustomDNSViewController: UITableViewController, VPNSettingsDataSourceDelegate {
private let interactor: VPNSettingsInteractor
private var dataSource: CustomDNSDataSource?
private let alertPresenter: AlertPresenter
override var preferredStatusBarStyle: UIStatusBarStyle {
.lightContent
}
init(interactor: VPNSettingsInteractor, alertPresenter: AlertPresenter) {
self.interactor = interactor
self.alertPresenter = alertPresenter
super.init(style: .grouped)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.accessibilityIdentifier = .dnsSettingsTableView
tableView.backgroundColor = .secondaryColor
tableView.separatorColor = .secondaryColor
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 60
tableView.estimatedSectionHeaderHeight = tableView.estimatedRowHeight
dataSource = CustomDNSDataSource(tableView: tableView)
dataSource?.delegate = self
navigationItem.title = NSLocalizedString(
"NAVIGATION_TITLE",
tableName: "VPNSettings",
value: "DNS settings",
comment: ""
)
navigationItem.rightBarButtonItem = editButtonItem
navigationItem.rightBarButtonItem?.accessibilityIdentifier = .dnsSettingsEditButton
interactor.tunnelSettingsDidChange = { [weak self] newSettings in
self?.dataSource?.update(from: newSettings)
}
dataSource?.update(from: interactor.tunnelSettings)
tableView.tableHeaderView = UIView(frame: CGRect(
origin: .zero,
size: CGSize(width: 0, height: UIMetrics.TableView.sectionSpacing)
))
}
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
dataSource?.setEditing(editing, animated: animated)
navigationItem.setHidesBackButton(editing, animated: animated)
// Disable swipe to dismiss when editing
isModalInPresentation = editing
}
private func showInfo(with message: NSAttributedString) {
let presentation = AlertPresentation(
id: "vpn-settings-content-blockers-alert",
icon: .info,
attributedMessage: message,
buttons: [
AlertAction(
title: NSLocalizedString(
"VPN_SETTINGS_DNS_SETTINGS_OK_ACTION",
tableName: "ContentBlockers",
value: "Got it!",
comment: ""
),
style: .default
),
]
)
alertPresenter.showAlert(presentation: presentation, animated: true)
}
// MARK: - VPNSettingsDataSourceDelegate
func didChangeViewModel(_ viewModel: VPNSettingsViewModel) {
interactor.updateSettings([.dnsSettings(viewModel.asDNSSettings())])
}
func showInfo(for item: VPNSettingsInfoButtonItem) {
var message = NSAttributedString()
switch item {
case .contentBlockers:
message = NSAttributedString(markdownString: NSLocalizedString(
"VPN_SETTINGS_CONTENT_BLOCKERS_GENERAL",
tableName: "ContentBlockers",
value: """
When this feature is enabled it stops the device from contacting certain \
domains or websites known for distributing ads, malware, trackers and more. \
This might cause issues on certain websites, services, and apps.
Attention: this setting cannot be used in combination with **Use custom DNS**.
""",
comment: ""
), options: MarkdownStylingOptions(font: .preferredFont(forTextStyle: .body)))
case .blockMalware:
message = NSAttributedString(string: NSLocalizedString(
"VPN_SETTINGS_CONTENT_BLOCKERS_MALWARE",
tableName: "ContentBlockers",
value: """
Warning: The malware blocker is not an anti-virus and should not \
be treated as such, this is just an extra layer of protection.
""",
comment: ""
))
default:
assertionFailure("No matching InfoButtonItem")
}
showInfo(with: message)
}
func showDNSSettings() {
// No op.
}
func showIPOverrides() {
// No op.
}
func didSelectWireGuardPort(_ port: UInt16?) {
// No op.
}
}