From fff3449174a51bffad2c3be8342cc61e2dd57310 Mon Sep 17 00:00:00 2001 From: Seiike <122684677+Seeike@users.noreply.github.com> Date: Wed, 26 Mar 2025 20:52:12 +0100 Subject: [PATCH] prob very works --- Sora/Utils/NetworkDns/CustomDNS.swift | 20 ++++++- .../SettingsViewGeneral.swift | 59 +++++++------------ 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/Sora/Utils/NetworkDns/CustomDNS.swift b/Sora/Utils/NetworkDns/CustomDNS.swift index ee41506..14e7f5d 100644 --- a/Sora/Utils/NetworkDns/CustomDNS.swift +++ b/Sora/Utils/NetworkDns/CustomDNS.swift @@ -48,8 +48,24 @@ enum DNSProvider: String, CaseIterable, Hashable { } class CustomDNSResolver { + // Use custom DNS servers if "Custom" is selected; otherwise, fall back to the default provider's servers. + var dnsServers: [String] { + if let provider = UserDefaults.standard.string(forKey: "CustomDNSProvider"), + provider == "Custom" { + let primary = UserDefaults.standard.string(forKey: "customPrimaryDNS") ?? "" + let secondary = UserDefaults.standard.string(forKey: "customSecondaryDNS") ?? "" + var servers = [String]() + if !primary.isEmpty { servers.append(primary) } + if !secondary.isEmpty { servers.append(secondary) } + if !servers.isEmpty { + return servers + } + } + return DNSProvider.current.servers + } + var dnsServerIP: String { - return DNSProvider.current.servers.first ?? "1.1.1.1" + return dnsServers.first ?? "1.1.1.1" } func buildDNSQuery(for host: String) -> (Data, UInt16) { @@ -74,6 +90,7 @@ class CustomDNSResolver { } func parseDNSResponse(_ data: Data, queryID: UInt16) -> [String] { + // Existing implementation remains unchanged. var ips = [String]() var offset = 0 func readUInt16() -> UInt16? { @@ -173,6 +190,7 @@ class CustomDNSResolver { } } + class CustomURLProtocol: URLProtocol { static let resolver = CustomDNSResolver() override class func canInit(with request: URLRequest) -> Bool { diff --git a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewGeneral.swift b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewGeneral.swift index 310e5f3..fe08109 100644 --- a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewGeneral.swift +++ b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewGeneral.swift @@ -15,10 +15,12 @@ struct SettingsViewGeneral: View { @AppStorage("multiThreads") private var multiThreadsEnabled: Bool = false @AppStorage("metadataProviders") private var metadataProviders: String = "AniList" @AppStorage("CustomDNSProvider") private var customDNSProvider: String = "Cloudflare" + @AppStorage("customPrimaryDNS") private var customPrimaryDNS: String = "" + @AppStorage("customSecondaryDNS") private var customSecondaryDNS: String = "" @AppStorage("mediaColumnsPortrait") private var mediaColumnsPortrait: Int = 2 @AppStorage("mediaColumnsLandscape") private var mediaColumnsLandscape: Int = 4 - private let customDNSProviderList = ["Cloudflare", "Google", "OpenDNS", "Quad9", "AdGuard", "CleanBrowsing", "ControlD"] + private let customDNSProviderList = ["Cloudflare", "Google", "OpenDNS", "Quad9", "AdGuard", "CleanBrowsing", "ControlD", "Custom"] private let metadataProvidersList = ["AniList"] @EnvironmentObject var settings: Settings @@ -26,7 +28,7 @@ struct SettingsViewGeneral: View { Form { Section(header: Text("Interface")) { ColorPicker("Accent Color", selection: $settings.accentColor) - HStack() { + HStack { Text("Appearance") Picker("Appearance", selection: $settings.selectedAppearance) { Text("System").tag(Appearance.system) @@ -42,18 +44,10 @@ struct SettingsViewGeneral: View { Text("Episodes Range") Spacer() Menu { - Button(action: { episodeChunkSize = 25 }) { - Text("25") - } - Button(action: { episodeChunkSize = 50 }) { - Text("50") - } - Button(action: { episodeChunkSize = 75 }) { - Text("75") - } - Button(action: { episodeChunkSize = 100 }) { - Text("100") - } + Button(action: { episodeChunkSize = 25 }) { Text("25") } + Button(action: { episodeChunkSize = 50 }) { Text("50") } + Button(action: { episodeChunkSize = 75 }) { Text("75") } + Button(action: { episodeChunkSize = 100 }) { Text("100") } } label: { Text("\(episodeChunkSize)") } @@ -65,9 +59,7 @@ struct SettingsViewGeneral: View { Spacer() Menu(metadataProviders) { ForEach(metadataProvidersList, id: \.self) { provider in - Button(action: { - metadataProviders = provider - }) { + Button(action: { metadataProviders = provider }) { Text(provider) } } @@ -75,25 +67,16 @@ struct SettingsViewGeneral: View { } } - //Section(header: Text("Downloads"), footer: Text("Note that the modules will be replaced only if there is a different version string inside the JSON file.")) { - // Toggle("Multi Threads conversion", isOn: $multiThreadsEnabled) - // .tint(.accentColor) - //} - Section(header: Text("Media Grid Layout"), footer: Text("Adjust the number of media items per row in portrait and landscape modes.")) { HStack { if UIDevice.current.userInterfaceIdiom == .pad { Picker("Portrait Columns", selection: $mediaColumnsPortrait) { - ForEach(1..<6) { i in - Text("\(i)").tag(i) - } + ForEach(1..<6) { i in Text("\(i)").tag(i) } } .pickerStyle(MenuPickerStyle()) } else { Picker("Portrait Columns", selection: $mediaColumnsPortrait) { - ForEach(1..<5) { i in - Text("\(i)").tag(i) - } + ForEach(1..<5) { i in Text("\(i)").tag(i) } } .pickerStyle(MenuPickerStyle()) } @@ -101,16 +84,12 @@ struct SettingsViewGeneral: View { HStack { if UIDevice.current.userInterfaceIdiom == .pad { Picker("Landscape Columns", selection: $mediaColumnsLandscape) { - ForEach(2..<9) { i in - Text("\(i)").tag(i) - } + ForEach(2..<9) { i in Text("\(i)").tag(i) } } .pickerStyle(MenuPickerStyle()) } else { Picker("Landscape Columns", selection: $mediaColumnsLandscape) { - ForEach(2..<6) { i in - Text("\(i)").tag(i) - } + ForEach(2..<6) { i in Text("\(i)").tag(i) } } .pickerStyle(MenuPickerStyle()) } @@ -122,7 +101,7 @@ struct SettingsViewGeneral: View { .tint(.accentColor) } - Section(header: Text("Advanced"), footer: Text("Thanks to this Sora to collect anonymous data to improve the app. No personal information is collected. This can be disabled at any time.\n\n Information collected: \n- App version\n- Device model\n- Module Name/Version\n- Error Messages\n- Title of Watched Content")) { + Section(header: Text("Advanced"), footer: Text("Anonymous data is collected to improve the app. No personal information is collected. This can be disabled at any time.")) { Toggle("Enable Analytics", isOn: $analyticsEnabled) .tint(.accentColor) @@ -131,14 +110,18 @@ struct SettingsViewGeneral: View { Spacer() Menu(customDNSProvider) { ForEach(customDNSProviderList, id: \.self) { provider in - Button(action: { - customDNSProvider = provider - }) { + Button(action: { customDNSProvider = provider }) { Text(provider) } } } } + if customDNSProvider == "Custom" { + TextField("Primary DNS", text: $customPrimaryDNS) + .keyboardType(.numbersAndPunctuation) + TextField("Secondary DNS", text: $customSecondaryDNS) + .keyboardType(.numbersAndPunctuation) + } } } .navigationTitle("General")