From 6dd32f68dd4cecb38bf99bd5d884833b526b0564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Thu, 21 Dec 2023 19:32:26 +0100 Subject: [PATCH] Custom config URL (#2278) Task/Issue URL: https://app.asana.com/0/72649045549333/1205661297103826/f Description: Enable custom configuration url debugging. --- Core/UserDefaultsPropertyWrapper.swift | 4 + DuckDuckGo.xcodeproj/project.pbxproj | 6 +- .../xcshareddata/swiftpm/Package.resolved | 4 +- DuckDuckGo/AppConfigurationFetch.swift | 7 +- DuckDuckGo/AppDelegate.swift | 10 +- DuckDuckGo/Base.lproj/Settings.storyboard | 36 +-- DuckDuckGo/BlankSnapshotViewController.swift | 3 +- .../Configuration/ConfigurationManager.swift | 12 +- .../ConfigurationDebugViewController.swift | 31 +-- .../ConfigurationURLDebugViewController.swift | 214 ++++++++++++++++++ DuckDuckGo/Debug.storyboard | 133 +++++++++-- DuckDuckGo/MainViewController+Segues.swift | 24 ++ DuckDuckGo/MainViewController.swift | 22 +- DuckDuckGo/OmniBar.swift | 30 ++- DuckDuckGo/OmniBarDelegate.swift | 22 +- LocalPackages/DuckUI/Package.swift | 2 +- LocalPackages/SyncUI/Package.swift | 2 +- LocalPackages/Waitlist/Package.swift | 2 +- 18 files changed, 491 insertions(+), 73 deletions(-) create mode 100644 DuckDuckGo/ConfigurationURLDebugViewController.swift diff --git a/Core/UserDefaultsPropertyWrapper.swift b/Core/UserDefaultsPropertyWrapper.swift index ae2dfa9071..2cd47169db 100644 --- a/Core/UserDefaultsPropertyWrapper.swift +++ b/Core/UserDefaultsPropertyWrapper.swift @@ -57,6 +57,7 @@ public struct UserDefaultsWrapper { case legacyCovidInfo = "com.duckduckgo.ios.home.covidInfo" case lastConfigurationRefreshDate = "com.duckduckgo.ios.lastConfigurationRefreshDate" + case lastConfigurationUpdateDate = "com.duckduckgo.ios.lastConfigurationUpdateDate" case lastRemoteMessagingRefreshDate = "com.duckduckgo.ios.lastRemoteMessagingRefreshDate" case doNotSell = "com.duckduckgo.ios.sendDoNotSell" @@ -113,6 +114,9 @@ public struct UserDefaultsWrapper { case addressBarPosition = "com.duckduckgo.ios.addressbarposition" case showFullSiteAddress = "com.duckduckgo.ios.showfullsiteaddress" + + case privacyConfigCustomURL = "com.duckduckgo.ios.privacyConfigCustomURL" + } private let key: Key diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index dc3413fa8d..228f4dc98d 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -766,6 +766,7 @@ CBDD5DDF29A6736A00832877 /* APIHeadersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBDD5DDE29A6736A00832877 /* APIHeadersTests.swift */; }; CBDD5DE129A6741300832877 /* MockBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBDD5DE029A6741300832877 /* MockBundle.swift */; }; CBEFB9142AE0844700DEDE7B /* CriticalAlerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBEFB9102ADFFE7900DEDE7B /* CriticalAlerts.swift */; }; + CBFCB30E2B2CD47800253E9E /* ConfigurationURLDebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBFCB30D2B2CD47800253E9E /* ConfigurationURLDebugViewController.swift */; }; D63657192A7BAE7C001AF19D /* EmailManagerRequestDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63657182A7BAE7C001AF19D /* EmailManagerRequestDelegate.swift */; }; EA39B7E2268A1A35000C62CD /* privacy-reference-tests in Resources */ = {isa = PBXBuildFile; fileRef = EA39B7E1268A1A35000C62CD /* privacy-reference-tests */; }; EAB19EDA268963510015D3EA /* DomainMatchingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB19ED9268963510015D3EA /* DomainMatchingTests.swift */; }; @@ -2365,6 +2366,7 @@ CBF14FC227970072001D94D0 /* HomeMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeMessageView.swift; sourceTree = ""; }; CBF14FC427970AB0001D94D0 /* HomeMessageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeMessageViewModel.swift; sourceTree = ""; }; CBF14FC627970C8A001D94D0 /* HomeMessageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeMessageCollectionViewCell.swift; sourceTree = ""; }; + CBFCB30D2B2CD47800253E9E /* ConfigurationURLDebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationURLDebugViewController.swift; sourceTree = ""; }; D63657182A7BAE7C001AF19D /* EmailManagerRequestDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmailManagerRequestDelegate.swift; sourceTree = ""; }; EA39B7E1268A1A35000C62CD /* privacy-reference-tests */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "privacy-reference-tests"; path = "submodules/privacy-reference-tests"; sourceTree = SOURCE_ROOT; }; EAB19ED9268963510015D3EA /* DomainMatchingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DomainMatchingTests.swift; sourceTree = ""; }; @@ -3839,6 +3841,7 @@ F46FEC5627987A5F0061D9DF /* KeychainItemsDebugViewController.swift */, 983D71B02A286E810072E26D /* SyncDebugViewController.swift */, EE72CA842A862D000043B5B3 /* NetworkProtectionDebugViewController.swift */, + CBFCB30D2B2CD47800253E9E /* ConfigurationURLDebugViewController.swift */, ); name = Debug; sourceTree = ""; @@ -6428,6 +6431,7 @@ 85582E0029D7409700E9AE35 /* SyncSettingsViewController+PDFRendering.swift in Sources */, EE0153EF2A70021E002A8B26 /* NetworkProtectionInviteView.swift in Sources */, 9888F77B2224980500C46159 /* FeedbackViewController.swift in Sources */, + CBFCB30E2B2CD47800253E9E /* ConfigurationURLDebugViewController.swift in Sources */, 982686AD2600C0850011A8D6 /* ActionMessageView.swift in Sources */, F446B9B5251150AC00324016 /* HomeMessageViewSectionRenderer.swift in Sources */, 98D98A8225ED88E300D8E3DF /* BrowsingMenuSeparatorViewCell.swift in Sources */, @@ -9221,7 +9225,7 @@ repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 98.0.0; + version = 98.0.1; }; }; C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 0aa8f82ca1..7b794ad4d2 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/DuckDuckGo/BrowserServicesKit", "state" : { - "revision" : "064ed560f19fbfd36eb02decebf944689818ed35", - "version" : "98.0.0" + "revision" : "ea133abe237b6cb57a4237e0373318a40c10afc2", + "version" : "98.0.1" } }, { diff --git a/DuckDuckGo/AppConfigurationFetch.swift b/DuckDuckGo/AppConfigurationFetch.swift index b40b56d92c..fcf1664d94 100644 --- a/DuckDuckGo/AppConfigurationFetch.swift +++ b/DuckDuckGo/AppConfigurationFetch.swift @@ -98,6 +98,7 @@ class AppConfigurationFetch { } func start(isBackgroundFetch: Bool = false, + isDebug: Bool = false, completion: AppConfigurationFetchCompletion?) { guard Self.shouldRefresh else { // Statistics are not sent after a successful background refresh in order to reduce the time spent in the background, so they are checked @@ -113,7 +114,7 @@ class AppConfigurationFetch { type(of: self).fetchQueue.async { let taskID = UIApplication.shared.beginBackgroundTask(withName: Constants.backgroundTaskName) - self.fetchConfigurationFiles(isBackground: isBackgroundFetch) { result in + self.fetchConfigurationFiles(isBackground: isBackgroundFetch, isDebug: isDebug) { result in if !isBackgroundFetch { type(of: self).fetchQueue.async { self.sendStatistics { @@ -165,10 +166,10 @@ class AppConfigurationFetch { #endif } - private func fetchConfigurationFiles(isBackground: Bool, onDidComplete: @escaping AppConfigurationFetchCompletion) { + private func fetchConfigurationFiles(isBackground: Bool, isDebug: Bool = false, onDidComplete: @escaping AppConfigurationFetchCompletion) { Task { self.markFetchStarted(isBackground: isBackground) - let result = await AppDependencyProvider.shared.configurationManager.update() + let result = await AppDependencyProvider.shared.configurationManager.update(isDebug: isDebug) switch result { case .noData: diff --git a/DuckDuckGo/AppDelegate.swift b/DuckDuckGo/AppDelegate.swift index cabfab4df5..036f91edd9 100644 --- a/DuckDuckGo/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate.swift @@ -84,6 +84,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: lifecycle + @UserDefaultsWrapper(key: .privacyConfigCustomURL, defaultValue: nil) + private var privacyConfigCustomURL: String? + // swiftlint:disable:next function_body_length cyclomatic_complexity func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { @@ -105,7 +108,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate { cleanUpIncrementalRolloutPixelTest() APIRequest.Headers.setUserAgent(DefaultUserAgentManager.duckDuckGoUserAgent) - Configuration.setURLProvider(AppConfigurationURLProvider()) + + if isDebugBuild, let privacyConfigCustomURL, let url = URL(string: privacyConfigCustomURL) { + Configuration.setURLProvider(CustomConfigurationURLProvider(customPrivacyConfigurationURL: url)) + } else { + Configuration.setURLProvider(AppConfigurationURLProvider()) + } CrashCollection.start { Pixel.fire(pixel: .dbCrashDetected, withAdditionalParameters: $0, includedParameters: []) diff --git a/DuckDuckGo/Base.lproj/Settings.storyboard b/DuckDuckGo/Base.lproj/Settings.storyboard index 5f66405727..69c60efd61 100644 --- a/DuckDuckGo/Base.lproj/Settings.storyboard +++ b/DuckDuckGo/Base.lproj/Settings.storyboard @@ -101,7 +101,7 @@ - +