From 0b2885461ac1f6a013dd7b23a39154c43347af4c Mon Sep 17 00:00:00 2001 From: Benjamin Erhart Date: Fri, 29 May 2026 15:41:27 +0200 Subject: [PATCH] Issue #6: Show UI to explain user's next steps to enable. Disable toggle as this cannot be used to activate DNS settings. --- dns/BlocklistOption.swift | 9 +++++++++ dns/HomeView.swift | 28 +++++++++++++++++++++++++++- dns/ViewModel.swift | 16 +++++++--------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/dns/BlocklistOption.swift b/dns/BlocklistOption.swift index 2afffe1..7935deb 100644 --- a/dns/BlocklistOption.swift +++ b/dns/BlocklistOption.swift @@ -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: diff --git a/dns/HomeView.swift b/dns/HomeView.swift index f1df067..21dfa9b 100644 --- a/dns/HomeView.swift +++ b/dns/HomeView.swift @@ -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) } } diff --git a/dns/ViewModel.swift b/dns/ViewModel.swift index 5b331d0..64e9782 100644 --- a/dns/ViewModel.swift +++ b/dns/ViewModel.swift @@ -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()