Issue #6: Show UI to explain user's next steps to enable. Disable toggle as this cannot be used to activate DNS settings.
This commit is contained in:
parent
2e069897db
commit
0b2885461a
3 changed files with 43 additions and 10 deletions
|
|
@ -32,6 +32,15 @@ enum BlocklistOption: String, CaseIterable, Identifiable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var title: String {
|
||||||
|
switch self {
|
||||||
|
case .secure:
|
||||||
|
return String(format: NSLocalizedString( "%@: Malware and phishing protection", comment: ""), ViewModel.title)
|
||||||
|
case .securePlusAdblock:
|
||||||
|
return String(format: NSLocalizedString("%@: Security plus ad and tracker blocking", comment: ""), ViewModel.title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var icon: String {
|
var icon: String {
|
||||||
switch self {
|
switch self {
|
||||||
case .secure:
|
case .secure:
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,37 @@ struct HomeView: View {
|
||||||
|
|
||||||
Toggle("", isOn: $viewModel.isDnsEnabled)
|
Toggle("", isOn: $viewModel.isDnsEnabled)
|
||||||
.labelsHidden()
|
.labelsHidden()
|
||||||
|
.disabled(true)
|
||||||
.tint(.green)
|
.tint(.green)
|
||||||
}
|
}
|
||||||
.padding(.vertical, 4)
|
.padding(.vertical, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !viewModel.isDnsEnabled {
|
||||||
|
Section {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text(String(format: NSLocalizedString("To enable %@:", comment: ""), ViewModel.title))
|
||||||
|
Text(String(format: NSLocalizedString("%1$@ Tap \"%2$@\"", comment: ""), "–", NSLocalizedString("Open Settings", comment: "")))
|
||||||
|
Text(String(format: NSLocalizedString("%1$@ Go to General", comment: ""), "–"))
|
||||||
|
Text(String(format: NSLocalizedString("%1$@ VPN & Network", comment: ""), "–"))
|
||||||
|
Text(String(format: NSLocalizedString("%1$@ DNS", comment: ""), "–"))
|
||||||
|
Text(String(format: NSLocalizedString("%1$@ Select \"%2$@\"", comment: ""), "–", viewModel.blocklist.title))
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button {
|
||||||
|
if let url = URL(string: UIApplication.openSettingsURLString) {
|
||||||
|
UIApplication.shared.open(url)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Text(NSLocalizedString("Open Settings", comment: ""))
|
||||||
|
.frame(maxWidth: .infinity, minHeight: 32)
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Blocklist selection
|
// Blocklist selection
|
||||||
Section {
|
Section {
|
||||||
ForEach(BlocklistOption.allCases) { option in
|
ForEach(BlocklistOption.allCases) { option in
|
||||||
|
|
@ -176,7 +202,7 @@ struct HomeView: View {
|
||||||
}.foregroundStyle(.primary)
|
}.foregroundStyle(.primary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("SR2® Cloud DNS")
|
.navigationTitle(ViewModel.title)
|
||||||
.animation(.default, value: viewModel.isDnsEnabled)
|
.animation(.default, value: viewModel.isDnsEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ import OSLog
|
||||||
|
|
||||||
class ViewModel: NSObject, ObservableObject {
|
class ViewModel: NSObject, ObservableObject {
|
||||||
|
|
||||||
|
static let title = "SR2® Cloud DNS"
|
||||||
|
|
||||||
// MARK: Public Properties
|
// MARK: Public Properties
|
||||||
|
|
||||||
@Published
|
@Published
|
||||||
|
|
@ -29,11 +31,7 @@ class ViewModel: NSObject, ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Published
|
@Published
|
||||||
var isDnsEnabled = false {
|
var isDnsEnabled = false
|
||||||
didSet {
|
|
||||||
toggleDns()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Published
|
@Published
|
||||||
var summaryStatus: SummaryStatus = .pending
|
var summaryStatus: SummaryStatus = .pending
|
||||||
|
|
@ -51,6 +49,8 @@ class ViewModel: NSObject, ObservableObject {
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
|
isDnsEnabled = manager.isEnabled
|
||||||
|
|
||||||
isProgrammaticChange = true
|
isProgrammaticChange = true
|
||||||
blocklist = Settings.blocklist
|
blocklist = Settings.blocklist
|
||||||
|
|
||||||
|
|
@ -60,11 +60,9 @@ class ViewModel: NSObject, ObservableObject {
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
log.error("Error loading preferences: \(error)")
|
log.error("Error loading preferences: \(error)")
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if manager.isEnabled, let settings = manager.dnsSettings {
|
if let settings = manager.dnsSettings {
|
||||||
for dnsServer in BlocklistOption.allCases {
|
for dnsServer in BlocklistOption.allCases {
|
||||||
if settings.servers.contains(dnsServer.ipv4) {
|
if settings.servers.contains(dnsServer.ipv4) {
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
|
|
@ -99,7 +97,7 @@ class ViewModel: NSObject, ObservableObject {
|
||||||
Task {
|
Task {
|
||||||
if isDnsEnabled {
|
if isDnsEnabled {
|
||||||
manager.dnsSettings = blocklist.settings
|
manager.dnsSettings = blocklist.settings
|
||||||
manager.localizedDescription = blocklist.description
|
manager.localizedDescription = blocklist.title
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try await manager.saveToPreferences()
|
try await manager.saveToPreferences()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue