Skip to content

Commit

Permalink
Make sure when we set custom config url, we don't expect etag in retu…
Browse files Browse the repository at this point in the history
…rn (#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)
  • Loading branch information
jaceklyp authored Dec 21, 2023
1 parent 9823186 commit c0523ac
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12976,7 +12976,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 98.0.0;
version = 98.0.1;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public struct UserDefaultsWrapper<T> {
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"
Expand Down
16 changes: 10 additions & 6 deletions DuckDuckGo/Configuration/ConfigurationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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),
Expand Down
10 changes: 8 additions & 2 deletions DuckDuckGo/Menus/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/Menus/MainMenuActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/Account/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/LoginItems/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
],
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/PixelKit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/Purchase/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/Subscription/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SwiftUIExtensions/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SyncUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SystemExtensionManager/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/XPCHelper/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c0523ac

Please sign in to comment.