Update BlockedCount to fetch from the specific server #2

Closed
opened 2026-04-13 13:02:51 +00:00 by irl · 5 comments
Owner

Right now this is hardcoded to dns.sr2.uk as I don't know how to pass values to components. It should be the server value from the BlocklistOption that is currently selected.

Right now this is hardcoded to dns.sr2.uk as I don't know how to pass values to components. It should be the server value from the BlocklistOption that is currently selected.
Author
Owner

Warning on this one that only dns.sr2.uk exists, the plus one will not produce a response because it doesn't exist yet.

Warning on this one that only dns.sr2.uk exists, the plus one will not produce a response because it doesn't exist yet.
tla was assigned by irl 2026-04-14 15:59:56 +00:00
Collaborator

Please test!

Please test!
irl was assigned by tla 2026-04-14 16:23:52 +00:00
tla removed their assignment 2026-04-14 16:23:52 +00:00
tla referenced this issue from a commit 2026-04-14 16:24:28 +00:00
Author
Owner

Ok, but doesn't update when you change the blocklist. How about this patch?

diff --git a/dns/BlockedCount.swift b/dns/BlockedCount.swift
index e18f5b5..bd5856d 100644
--- a/dns/BlockedCount.swift
+++ b/dns/BlockedCount.swift
@@ -23,6 +23,9 @@ struct BlockedCount: View {
         .onAppear {
             fetchTXTRecord()
         }
+        .onChange(of: viewModel.blocklist) {
+            fetchTXTRecord()
+        }
     }

     func parseResponse(data: Data) -> String? {
@@ -48,9 +51,10 @@ struct BlockedCount: View {

     func fetchTXTRecord() {
         let dohURL = URL(string: "https://\(viewModel.blocklist.server)/dns-query?dns=DoQBAAABAAAAAAAABXN0YXRzB2ludmFsaWQAABAAAQ")!
-
         let request = URLRequest(url: dohURL)

+        txtRecord = "…"
+
         Task {
             do {
                 let (data, _) = try await URLSession.shared.data(for: request)

Minimum iOS version needs to bump to 17.

Ok, but doesn't update when you change the blocklist. How about this patch? ```diff diff --git a/dns/BlockedCount.swift b/dns/BlockedCount.swift index e18f5b5..bd5856d 100644 --- a/dns/BlockedCount.swift +++ b/dns/BlockedCount.swift @@ -23,6 +23,9 @@ struct BlockedCount: View { .onAppear { fetchTXTRecord() } + .onChange(of: viewModel.blocklist) { + fetchTXTRecord() + } } func parseResponse(data: Data) -> String? { @@ -48,9 +51,10 @@ struct BlockedCount: View { func fetchTXTRecord() { let dohURL = URL(string: "https://\(viewModel.blocklist.server)/dns-query?dns=DoQBAAABAAAAAAAABXN0YXRzB2ludmFsaWQAABAAAQ")! - let request = URLRequest(url: dohURL) + txtRecord = "…" + Task { do { let (data, _) = try await URLSession.shared.data(for: request) ``` Minimum iOS version needs to bump to 17.
irl removed their assignment 2026-04-14 16:48:28 +00:00
tla was assigned by irl 2026-04-14 16:48:28 +00:00
Collaborator

Probably no version change needed, if you change

+        .onChange(of: viewModel.blocklist) {
+            fetchTXTRecord()
+        }

to

+        .onChange(of: viewModel.blocklist) { _ in
+            fetchTXTRecord()
+        }
Probably no version change needed, if you change ```swift + .onChange(of: viewModel.blocklist) { + fetchTXTRecord() + } ``` to ```swift + .onChange(of: viewModel.blocklist) { _ in + fetchTXTRecord() + } ```
Author
Owner

Yep you are correct, that works on iOS 16.

Committed the change.

Yep you are correct, that works on iOS 16. Committed the change.
irl closed this issue 2026-04-14 20:03:26 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: sr2/cloud-dns-ios#2
No description provided.