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

Unify Configuration Management #990

Merged
merged 18 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
86 changes: 34 additions & 52 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

72 changes: 0 additions & 72 deletions DuckDuckGo/API/APIHeaders.swift

This file was deleted.

138 changes: 0 additions & 138 deletions DuckDuckGo/API/APIRequest.swift

This file was deleted.

23 changes: 0 additions & 23 deletions DuckDuckGo/API/ApiRequestError.swift

This file was deleted.

37 changes: 37 additions & 0 deletions DuckDuckGo/App Delegate/AppConfigurationURLProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// AppConfigurationURLProvider.swift
//
// Copyright © 2023 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import Configuration

struct AppConfigurationURLProvider: ConfigurationURLProvider {

func url(for configuration: Configuration) -> URL {
switch configuration {
case .bloomFilterBinary: return URL(string: "https://staticcdn.duckduckgo.com/https/https-mobile-v2-bloom.bin")!
case .bloomFilterSpec: return URL(string: "https://staticcdn.duckduckgo.com/https/https-mobile-v2-bloom-spec.json")!
case .bloomFilterExcludedDomains: return URL(string: "https://staticcdn.duckduckgo.com/https/https-mobile-v2-false-positives.json")!
case .privacyConfiguration: return URL(string: "https://staticcdn.duckduckgo.com/trackerblocking/config/v2/macos-config.json")!
case .surrogates: return URL(string: "https://duckduckgo.com/contentblocking.js?l=surrogates")!
case .trackerDataSet: return URL(string: "https://staticcdn.duckduckgo.com/trackerblocking/v3/apple-tds.json")!
// In archived repo, to be refactored shortly (https://staticcdn.duckduckgo.com/useragents/social_ctp_configuration.json)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still relevant? If so, can you make it more clear? (I have no idea what is it about)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea either - it's a one year old comment, and the original author is @ladamski. @ladamski do you know anything about that?

case .FBConfig: return URL(string: "https://staticcdn.duckduckgo.com/useragents/")!
}
}

}
5 changes: 5 additions & 0 deletions DuckDuckGo/App Delegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Combine
import os.log
import BrowserServicesKit
import Persistence
import Configuration
import API

@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {
Expand Down Expand Up @@ -61,6 +63,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
var appUsageActivityMonitor: AppUsageActivityMonitor?

func applicationWillFinishLaunching(_ notification: Notification) {
APIHeaders.setUserAgent(UserAgent.duckDuckGoUserAgent())
Configuration.setURLProvider(AppConfigurationURLProvider())

if !Self.isRunningTests {
#if DEBUG
Pixel.setUp(dryRun: true)
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Browser Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ extension Tab: WKNavigationDelegate {
decidePolicyFor navigationResponse: WKNavigationResponse) async -> WKNavigationResponsePolicy {
userEnteredUrl = false // subsequent requests will be navigations

let isSuccessfulResponse = (navigationResponse.response as? HTTPURLResponse)?.validateStatusCode(statusCode: 200..<300) == nil
let isSuccessfulResponse = (navigationResponse.response as? HTTPURLResponse)?.isSuccessfulResponse ?? false

internalUserDecider?.markUserAsInternalIfNeeded(forUrl: webView.url,
response: navigationResponse.response as? HTTPURLResponse)
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Browser Tab/Model/UserContentUpdating.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Combine
import Common
import BrowserServicesKit
import UserScript
import Configuration

final class UserContentUpdating {

Expand Down
51 changes: 0 additions & 51 deletions DuckDuckGo/Common/AppVersion.swift

This file was deleted.

2 changes: 1 addition & 1 deletion DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct UserDefaultsWrapper<T> {
public enum Key: String, CaseIterable {

case configLastUpdated = "config.last.updated"
case configStorageTrackerRadarEtag = "config.storage.trackerradar.etag"
case configStorageTrackerRadarEtag = "config.storage.trackerDataSet.etag"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't we need some migration code to recognize an etag stored under the old name?

case configStorageBloomFilterSpecEtag = "config.storage.bloomfilter.spec.etag"
case configStorageBloomFilterBinaryEtag = "config.storage.bloomfilter.binary.etag"
case configStorageBloomFilterExclusionsEtag = "config.storage.bloomfilter.exclusions.etag"
Expand Down
Loading