Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure when we set custom config url, we don't expect etag in return #1994

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12719,8 +12719,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 94.0.2;
branch = "jacek/custom-config-url";
kind = branch;
};
};
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" : "861b8a72930f138cd18b6a7722502a8a40375827",
"version" : "94.0.2"
"branch" : "jacek/custom-config-url",
"revision" : "b5f88da52ccd6b679db674b507be8efde4e89541"
}
},
{
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 @@ -635,8 +635,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 @@ -733,7 +733,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 @@ -744,7 +744,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
Loading