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 {
|
||||
switch self {
|
||||
case .secure:
|
||||
|
|
|
|||
|
|
@ -31,11 +31,37 @@ struct HomeView: View {
|
|||
|
||||
Toggle("", isOn: $viewModel.isDnsEnabled)
|
||||
.labelsHidden()
|
||||
.disabled(true)
|
||||
.tint(.green)
|
||||
}
|
||||
.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
|
||||
Section {
|
||||
ForEach(BlocklistOption.allCases) { option in
|
||||
|
|
@ -176,7 +202,7 @@ struct HomeView: View {
|
|||
}.foregroundStyle(.primary)
|
||||
}
|
||||
}
|
||||
.navigationTitle("SR2® Cloud DNS")
|
||||
.navigationTitle(ViewModel.title)
|
||||
.animation(.default, value: viewModel.isDnsEnabled)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import OSLog
|
|||
|
||||
class ViewModel: NSObject, ObservableObject {
|
||||
|
||||
static let title = "SR2® Cloud DNS"
|
||||
|
||||
// MARK: Public Properties
|
||||
|
||||
@Published
|
||||
|
|
@ -29,11 +31,7 @@ class ViewModel: NSObject, ObservableObject {
|
|||
}
|
||||
|
||||
@Published
|
||||
var isDnsEnabled = false {
|
||||
didSet {
|
||||
toggleDns()
|
||||
}
|
||||
}
|
||||
var isDnsEnabled = false
|
||||
|
||||
@Published
|
||||
var summaryStatus: SummaryStatus = .pending
|
||||
|
|
@ -51,6 +49,8 @@ class ViewModel: NSObject, ObservableObject {
|
|||
override init() {
|
||||
super.init()
|
||||
|
||||
isDnsEnabled = manager.isEnabled
|
||||
|
||||
isProgrammaticChange = true
|
||||
blocklist = Settings.blocklist
|
||||
|
||||
|
|
@ -60,11 +60,9 @@ class ViewModel: NSObject, ObservableObject {
|
|||
}
|
||||
catch {
|
||||
log.error("Error loading preferences: \(error)")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if manager.isEnabled, let settings = manager.dnsSettings {
|
||||
if let settings = manager.dnsSettings {
|
||||
for dnsServer in BlocklistOption.allCases {
|
||||
if settings.servers.contains(dnsServer.ipv4) {
|
||||
await MainActor.run {
|
||||
|
|
@ -99,7 +97,7 @@ class ViewModel: NSObject, ObservableObject {
|
|||
Task {
|
||||
if isDnsEnabled {
|
||||
manager.dnsSettings = blocklist.settings
|
||||
manager.localizedDescription = blocklist.description
|
||||
manager.localizedDescription = blocklist.title
|
||||
|
||||
do {
|
||||
try await manager.saveToPreferences()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue