From 8e65a7452b5d6f1de09213a93d8cd9ef69aa9976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Tue, 28 Nov 2023 17:09:21 +0100 Subject: [PATCH] Fix privacy config fetch in debug mode --- DuckDuckGo/AppConfigurationFetch.swift | 7 ++++--- DuckDuckGo/Configuration/ConfigurationManager.swift | 12 ++++++------ DuckDuckGo/ConfigurationDebugViewController.swift | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) 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/Configuration/ConfigurationManager.swift b/DuckDuckGo/Configuration/ConfigurationManager.swift index db9ab83618..f0a148adcd 100644 --- a/DuckDuckGo/Configuration/ConfigurationManager.swift +++ b/DuckDuckGo/Configuration/ConfigurationManager.swift @@ -66,8 +66,8 @@ struct ConfigurationManager { } } - func update() async -> UpdateResult { - async let didFetchAnyTrackerBlockingDependencies = fetchAndUpdateTrackerBlockingDependencies() + func update(isDebug: Bool = false) async -> UpdateResult { + async let didFetchAnyTrackerBlockingDependencies = fetchAndUpdateTrackerBlockingDependencies(isDebug: isDebug) async let didFetchExcludedDomains = fetchAndUpdateBloomFilterExcludedDomains() async let didFetchBloomFilter = fetchAndUpdateBloomFilter() @@ -80,21 +80,21 @@ struct ConfigurationManager { } @discardableResult - func fetchAndUpdateTrackerBlockingDependencies() async -> Bool { - let didFetchAnyTrackerBlockingDependencies = await fetchTrackerBlockingDependencies() + func fetchAndUpdateTrackerBlockingDependencies(isDebug: Bool = false) async -> Bool { + let didFetchAnyTrackerBlockingDependencies = await fetchTrackerBlockingDependencies(isDebug: isDebug) if didFetchAnyTrackerBlockingDependencies { updateTrackerBlockingDependencies() } return didFetchAnyTrackerBlockingDependencies } - private func fetchTrackerBlockingDependencies() async -> Bool { + private func fetchTrackerBlockingDependencies(isDebug: Bool = false) 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 { diff --git a/DuckDuckGo/ConfigurationDebugViewController.swift b/DuckDuckGo/ConfigurationDebugViewController.swift index 0d15804b86..fdb2a73840 100644 --- a/DuckDuckGo/ConfigurationDebugViewController.swift +++ b/DuckDuckGo/ConfigurationDebugViewController.swift @@ -90,7 +90,7 @@ class ConfigurationDebugViewController: UITableViewController { } private func fetchAssets() { - AppConfigurationFetch().start { [weak tableView] result in + AppConfigurationFetch().start(isDebug: true) { [weak tableView] result in switch result { case .assetsUpdated(let protectionsUpdated): if protectionsUpdated {