From c0523ac8e1c15652199828d17ff1a06d03f42226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Thu, 21 Dec 2023 19:20:13 +0100 Subject: [PATCH] Make sure when we set custom config url, we don't expect etag in return (#1994) Task/Issue URL: https://app.asana.com/0/72649045549333/1205661297103826/f **Description**: Enable custom configuration url debugging (no need to get etags in response) --- DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 6 +++--- .../Common/Utilities/UserDefaultsWrapper.swift | 2 ++ .../Configuration/ConfigurationManager.swift | 16 ++++++++++------ DuckDuckGo/Menus/MainMenu.swift | 10 ++++++++-- DuckDuckGo/Menus/MainMenuActions.swift | 4 ++-- LocalPackages/Account/Package.swift | 2 +- LocalPackages/DataBrokerProtection/Package.swift | 2 +- LocalPackages/LoginItems/Package.swift | 2 +- LocalPackages/NetworkProtectionMac/Package.swift | 2 +- LocalPackages/PixelKit/Package.swift | 2 +- LocalPackages/Purchase/Package.swift | 2 +- LocalPackages/Subscription/Package.swift | 2 +- LocalPackages/SwiftUIExtensions/Package.swift | 2 +- LocalPackages/SyncUI/Package.swift | 2 +- .../SystemExtensionManager/Package.swift | 2 +- LocalPackages/XPCHelper/Package.swift | 2 +- 17 files changed, 37 insertions(+), 25 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 3eacedf348..6f8a942aaf 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -12976,7 +12976,7 @@ repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 98.0.0; + version = 98.0.1; }; }; AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 805101ac61..13547f23d7 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" } }, { @@ -147,7 +147,7 @@ { "identity" : "trackerradarkit", "kind" : "remoteSourceControl", - "location" : "https://github.com/duckduckgo/TrackerRadarKit.git", + "location" : "https://github.com/duckduckgo/TrackerRadarKit", "state" : { "revision" : "a6b7ba151d9dc6684484f3785293875ec01cc1ff", "version" : "1.2.2" diff --git a/DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift b/DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift index 9ce0d13a89..3204cde614 100644 --- a/DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift +++ b/DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift @@ -41,6 +41,8 @@ public struct UserDefaultsWrapper { case configStoragePrivacyConfigurationEtag = "config.storage.privacyconfiguration.etag" case configFBConfigEtag = "config.storage.fbconfig.etag" + case configLastInstalled = "config.last.installed" + case fireproofDomains = "com.duckduckgo.fireproofing.allowedDomains" case areDomainsMigratedToETLDPlus1 = "com.duckduckgo.are-domains-migrated-to-etldplus1" case unprotectedDomains = "com.duckduckgo.contentblocker.unprotectedDomains" diff --git a/DuckDuckGo/Configuration/ConfigurationManager.swift b/DuckDuckGo/Configuration/ConfigurationManager.swift index a486bb4365..a64673dfc0 100644 --- a/DuckDuckGo/Configuration/ConfigurationManager.swift +++ b/DuckDuckGo/Configuration/ConfigurationManager.swift @@ -61,6 +61,9 @@ final class ConfigurationManager { @UserDefaultsWrapper(key: .configLastUpdated, defaultValue: .distantPast) private(set) var lastUpdateTime: Date + @UserDefaultsWrapper(key: .configLastInstalled, defaultValue: nil) + private(set) var lastConfigurationInstallDate: Date? + private var timerCancellable: AnyCancellable? private var lastRefreshCheckTime: Date = Date() @@ -97,9 +100,9 @@ final class ConfigurationManager { os_log("last refresh check %{public}s", log: .config, type: .default, String(describing: lastRefreshCheckTime)) } - private func refreshNow() async { + private func refreshNow(isDebug: Bool = false) async { let updateTrackerBlockingDependenciesTask = Task { - let didFetchAnyTrackerBlockingDependencies = await fetchTrackerBlockingDependencies() + let didFetchAnyTrackerBlockingDependencies = await fetchTrackerBlockingDependencies(isDebug: isDebug) if didFetchAnyTrackerBlockingDependencies { updateTrackerBlockingDependencies() tryAgainLater() @@ -134,13 +137,13 @@ final class ConfigurationManager { log() } - private func fetchTrackerBlockingDependencies() async -> Bool { + private func fetchTrackerBlockingDependencies(isDebug: Bool) async -> Bool { var didFetchAnyTrackerBlockingDependencies = false var tasks = [Configuration: Task<(), Swift.Error>]() tasks[.trackerDataSet] = Task { try await fetcher.fetch(.trackerDataSet) } tasks[.surrogates] = Task { try await fetcher.fetch(.surrogates) } - tasks[.privacyConfiguration] = Task { try await fetcher.fetch(.privacyConfiguration) } + tasks[.privacyConfiguration] = Task { try await fetcher.fetch(.privacyConfiguration, isDebug: isDebug) } for (configuration, task) in tasks { do { @@ -184,9 +187,9 @@ final class ConfigurationManager { private var isReadyToRefresh: Bool { Date().timeIntervalSince(lastUpdateTime) > Constants.refreshPeriodSeconds } - public func forceRefresh() { + public func forceRefresh(isDebug: Bool = false) { Task { - await refreshNow() + await refreshNow(isDebug: isDebug) } } @@ -200,6 +203,7 @@ final class ConfigurationManager { } private func updateTrackerBlockingDependencies() { + lastConfigurationInstallDate = Date() ContentBlocking.shared.trackerDataManager.reload(etag: ConfigurationStore.shared.loadEtag(for: .trackerDataSet), data: ConfigurationStore.shared.loadData(for: .trackerDataSet)) ContentBlocking.shared.privacyConfigurationManager.reload(etag: ConfigurationStore.shared.loadEtag(for: .privacyConfiguration), diff --git a/DuckDuckGo/Menus/MainMenu.swift b/DuckDuckGo/Menus/MainMenu.swift index dc532e19f3..9c3fdd9ac3 100644 --- a/DuckDuckGo/Menus/MainMenu.swift +++ b/DuckDuckGo/Menus/MainMenu.swift @@ -643,8 +643,14 @@ import Subscription } private func updateRemoteConfigurationInfo() { - let dateString = DateFormatter.localizedString(from: ConfigurationManager.shared.lastUpdateTime, dateStyle: .short, timeStyle: .medium) - configurationDateAndTimeMenuItem.title = "Last Update Time: \(dateString)" + var dateString: String + if let date = ConfigurationManager.shared.lastConfigurationInstallDate { + dateString = DateFormatter.localizedString(from: date, dateStyle: .short, timeStyle: .medium) + configurationDateAndTimeMenuItem.title = "Last Update Time: \(dateString)" + } else { + dateString = "Last Update Time: -" + } + configurationDateAndTimeMenuItem.title = dateString customConfigurationUrlMenuItem.title = "Configuration URL: \(AppConfigurationURLProvider().url(for: .privacyConfiguration).absoluteString)" } diff --git a/DuckDuckGo/Menus/MainMenuActions.swift b/DuckDuckGo/Menus/MainMenuActions.swift index 8a30695b31..4a4c4e1f7d 100644 --- a/DuckDuckGo/Menus/MainMenuActions.swift +++ b/DuckDuckGo/Menus/MainMenuActions.swift @@ -739,7 +739,7 @@ extension MainViewController { @objc func reloadConfigurationNow(_ sender: Any?) { OSLog.loggingCategories.insert(OSLog.AppCategories.config.rawValue) - ConfigurationManager.shared.forceRefresh() + ConfigurationManager.shared.forceRefresh(isDebug: true) } private func setConfigurationUrl(_ configurationUrl: URL?) { @@ -750,7 +750,7 @@ extension MainViewController { configurationProvider.resetToDefaultConfigurationUrl() } Configuration.setURLProvider(configurationProvider) - ConfigurationManager.shared.forceRefresh() + ConfigurationManager.shared.forceRefresh(isDebug: true) if let configurationUrl { os_log("New configuration URL set to \(configurationUrl.absoluteString)", type: .info) } else { diff --git a/LocalPackages/Account/Package.swift b/LocalPackages/Account/Package.swift index 54ad9d3e9b..49f48da084 100644 --- a/LocalPackages/Account/Package.swift +++ b/LocalPackages/Account/Package.swift @@ -12,7 +12,7 @@ let package = Package( targets: ["Account"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), .package(path: "../Purchase") ], targets: [ diff --git a/LocalPackages/DataBrokerProtection/Package.swift b/LocalPackages/DataBrokerProtection/Package.swift index 3852ed9842..435391c9df 100644 --- a/LocalPackages/DataBrokerProtection/Package.swift +++ b/LocalPackages/DataBrokerProtection/Package.swift @@ -29,7 +29,7 @@ let package = Package( targets: ["DataBrokerProtection"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), .package(path: "../PixelKit"), .package(path: "../SwiftUIExtensions"), .package(path: "../XPCHelper") diff --git a/LocalPackages/LoginItems/Package.swift b/LocalPackages/LoginItems/Package.swift index df220e7be9..53da2ff762 100644 --- a/LocalPackages/LoginItems/Package.swift +++ b/LocalPackages/LoginItems/Package.swift @@ -13,7 +13,7 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), ], targets: [ .target( diff --git a/LocalPackages/NetworkProtectionMac/Package.swift b/LocalPackages/NetworkProtectionMac/Package.swift index 55b684a01e..cd031f9386 100644 --- a/LocalPackages/NetworkProtectionMac/Package.swift +++ b/LocalPackages/NetworkProtectionMac/Package.swift @@ -30,7 +30,7 @@ let package = Package( .library(name: "NetworkProtectionUI", targets: ["NetworkProtectionUI"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), .package(path: "../XPCHelper"), .package(path: "../SwiftUIExtensions") ], diff --git a/LocalPackages/PixelKit/Package.swift b/LocalPackages/PixelKit/Package.swift index 93cfe4bf75..f4230052ea 100644 --- a/LocalPackages/PixelKit/Package.swift +++ b/LocalPackages/PixelKit/Package.swift @@ -20,7 +20,7 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), ], targets: [ .target( diff --git a/LocalPackages/Purchase/Package.swift b/LocalPackages/Purchase/Package.swift index 1bca7b0dd1..a61123f147 100644 --- a/LocalPackages/Purchase/Package.swift +++ b/LocalPackages/Purchase/Package.swift @@ -13,7 +13,7 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), ], targets: [ .target( diff --git a/LocalPackages/Subscription/Package.swift b/LocalPackages/Subscription/Package.swift index 77a66800a4..02148554e7 100644 --- a/LocalPackages/Subscription/Package.swift +++ b/LocalPackages/Subscription/Package.swift @@ -15,7 +15,7 @@ let package = Package( .package(path: "../Account"), .package(path: "../Purchase"), .package(path: "../SwiftUIExtensions"), - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), ], targets: [ .target( diff --git a/LocalPackages/SwiftUIExtensions/Package.swift b/LocalPackages/SwiftUIExtensions/Package.swift index 90a50b4864..7ca05a42ec 100644 --- a/LocalPackages/SwiftUIExtensions/Package.swift +++ b/LocalPackages/SwiftUIExtensions/Package.swift @@ -13,7 +13,7 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), ], targets: [ .target( diff --git a/LocalPackages/SyncUI/Package.swift b/LocalPackages/SyncUI/Package.swift index 7ecccd197d..6f485526ca 100644 --- a/LocalPackages/SyncUI/Package.swift +++ b/LocalPackages/SyncUI/Package.swift @@ -13,7 +13,7 @@ let package = Package( ], dependencies: [ .package(path: "../SwiftUIExtensions"), - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), ], targets: [ .target( diff --git a/LocalPackages/SystemExtensionManager/Package.swift b/LocalPackages/SystemExtensionManager/Package.swift index 58e8ba4070..722d4ae0a1 100644 --- a/LocalPackages/SystemExtensionManager/Package.swift +++ b/LocalPackages/SystemExtensionManager/Package.swift @@ -16,7 +16,7 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. diff --git a/LocalPackages/XPCHelper/Package.swift b/LocalPackages/XPCHelper/Package.swift index dfdef8911f..74bc880ffe 100644 --- a/LocalPackages/XPCHelper/Package.swift +++ b/LocalPackages/XPCHelper/Package.swift @@ -30,7 +30,7 @@ let package = Package( .library(name: "XPCHelper", targets: ["XPCHelper"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "98.0.1"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite.