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

Custom config URL #2278

Merged
merged 18 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 4 additions & 0 deletions Core/UserDefaultsPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public struct UserDefaultsWrapper<T> {
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"
Expand Down Expand Up @@ -113,6 +114,9 @@ public struct UserDefaultsWrapper<T> {

case addressBarPosition = "com.duckduckgo.ios.addressbarposition"
case showFullSiteAddress = "com.duckduckgo.ios.showfullsiteaddress"

case privacyConfigCustomURL = "com.duckduckgo.ios.privacyConfigCustomURL"

}

private let key: Key
Expand Down
6 changes: 5 additions & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -2365,6 +2366,7 @@
CBF14FC227970072001D94D0 /* HomeMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeMessageView.swift; sourceTree = "<group>"; };
CBF14FC427970AB0001D94D0 /* HomeMessageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeMessageViewModel.swift; sourceTree = "<group>"; };
CBF14FC627970C8A001D94D0 /* HomeMessageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeMessageCollectionViewCell.swift; sourceTree = "<group>"; };
CBFCB30D2B2CD47800253E9E /* ConfigurationURLDebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationURLDebugViewController.swift; sourceTree = "<group>"; };
D63657182A7BAE7C001AF19D /* EmailManagerRequestDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmailManagerRequestDelegate.swift; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -3839,6 +3841,7 @@
F46FEC5627987A5F0061D9DF /* KeychainItemsDebugViewController.swift */,
983D71B02A286E810072E26D /* SyncDebugViewController.swift */,
EE72CA842A862D000043B5B3 /* NetworkProtectionDebugViewController.swift */,
CBFCB30D2B2CD47800253E9E /* ConfigurationURLDebugViewController.swift */,
);
name = Debug;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -9221,7 +9225,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 98.0.0;
version = 98.0.1;
};
};
C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
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
7 changes: 4 additions & 3 deletions DuckDuckGo/AppConfigurationFetch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@

// 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 {

Expand All @@ -105,7 +108,12 @@
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: [])
Expand Down Expand Up @@ -190,7 +198,7 @@
errorEvents: preMigrationErrorHandling
)

bookmarksDatabase.loadStore { [weak self] context, error in

Check warning on line 201 in DuckDuckGo/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / Unit Tests

variable 'self' was written to, but never read
guard let context = context else {
if let error = error {
Pixel.fire(pixel: .bookmarksCouldNotLoadDatabase,
Expand Down
Loading
Loading