Skip to content

Commit

Permalink
Merge branch 'main' into sam/improve-vpn-metadata
Browse files Browse the repository at this point in the history
* main: (31 commits)
  Use History in Suggestions on iOS (#2552)
  Update wireguard-apple to 1.1.3 (#2598)
  Updates BSK to include latest changes (#2604)
  Fix VPN feedback form description (#2606)
  Fixes the name of a pixel (#2575)
  22. Subscription- Cleanup and minor updates (#2596)
  Release 7.112.0-3 (#2602)
  update embedded file
  Bump autoconsent to 10.3.0 (#2601)
  Roll back CPM post-rollout cleanup (#2599)
  Stub objects for Bookmarks DB (#2593)
  Subscriptions - 21. Manage Billing options to third parties (#2574)
  17. Subscription Review Fixes (#2547)
  bump bsk to fix retain cycle (#2595)
  New log for SKAd 4 integration (#2594)
  NetP x Subscription Clean-up (#2565)
  Update BSK to include latest macOS changes (#2588)
  rollback #URL macro (#2585)
  Release 7.112.0-2 (#2579)
  Updates BSK (#2577)
  ...
  • Loading branch information
samsymons committed Mar 18, 2024
2 parents b11d103 + 9820385 commit df32fcd
Show file tree
Hide file tree
Showing 218 changed files with 5,290 additions and 3,143 deletions.
2 changes: 1 addition & 1 deletion Configuration/Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MARKETING_VERSION = 7.111.0
MARKETING_VERSION = 7.112.0
20 changes: 10 additions & 10 deletions Core/AppLastCompiledRulesStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import BrowserServicesKit
import TrackerRadarKit

struct AppLastCompiledRules: LastCompiledRules, Codable {

var name: String
var trackerData: TrackerData
var etag: String
var identifier: ContentBlockerRulesIdentifier

}

protocol Storage {
Expand All @@ -36,15 +36,15 @@ protocol Storage {
}

struct LastCompiledRulesStorage: Storage {

private enum Const {
static let filename = "LastCompiledRules"
static let path = FileManager
.default
.containerURL(forSecurityApplicationGroupIdentifier: ContentBlockerStoreConstants.groupName)!
.appendingPathComponent(filename)
}

func persist(_ data: Data) -> Bool {
do {
try data.write(to: Const.path, options: .atomic)
Expand All @@ -53,25 +53,25 @@ struct LastCompiledRulesStorage: Storage {
return false
}
}

var data: Data? {
do {
return try Data(contentsOf: Const.path)
} catch {
return nil
}
}

}

final class AppLastCompiledRulesStore: LastCompiledRulesStore {

private var storage: Storage

init(with storage: Storage = LastCompiledRulesStorage()) {
self.storage = storage
}

var rules: [LastCompiledRules] {
guard
let data = storage.data,
Expand All @@ -88,10 +88,10 @@ final class AppLastCompiledRulesStore: LastCompiledRulesStore {
etag: rules.etag,
identifier: rules.identifier)
}

if !rules.isEmpty, let encodedRules = try? JSONEncoder().encode(rules) {
_ = storage.persist(encodedRules)
}
}

}
6 changes: 3 additions & 3 deletions Core/AppPrivacyConfigurationDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import BrowserServicesKit
final public class AppPrivacyConfigurationDataProvider: EmbeddedDataProvider {

public struct Constants {
public static let embeddedDataETag = "\"a427a69043b2baa27604bc10edb13de1\""
public static let embeddedDataSHA = "1d5c2e4113713fbf02bc617fc689981604ea53be172569a9fd744054b7355c39"
public static let embeddedDataETag = "\"c595f46fe54bfa96bbff4f30fc3940d8\""
public static let embeddedDataSHA = "911e6616b6869c0940c492240d43c0cf60274755dd45a50cc635c8b7c792cb87"
}

public var embeddedDataEtag: String {
Expand All @@ -39,7 +39,7 @@ final public class AppPrivacyConfigurationDataProvider: EmbeddedDataProvider {
if let url = Bundle.main.url(forResource: "ios-config", withExtension: "json") {
return url
}

return Bundle(for: self).url(forResource: "ios-config", withExtension: "json")!
}

Expand Down
6 changes: 3 additions & 3 deletions Core/AppTrackerDataSetProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import BrowserServicesKit
final public class AppTrackerDataSetProvider: EmbeddedDataProvider {

public struct Constants {
public static let embeddedDataETag = "\"0b6a7a2629abc170a505b92aebd67017\""
public static let embeddedDataSHA = "32cd805f6be415e77affdf51929494c7add6363234cef58ea8b53ca3a08c86d4"
public static let embeddedDataETag = "\"07bd7f610e3fa234856abcc2b56ab10e\""
public static let embeddedDataSHA = "1d7ef8f4c5a717a5d82f43383e33290021358d6255db12b6fdd0928e28d123ee"
}

public var embeddedDataEtag: String {
Expand All @@ -39,7 +39,7 @@ final public class AppTrackerDataSetProvider: EmbeddedDataProvider {
if let url = Bundle.main.url(forResource: "trackerData", withExtension: "json") {
return url
}

return Bundle(for: Self.self).url(forResource: "trackerData", withExtension: "json")!
}

Expand Down
30 changes: 15 additions & 15 deletions Core/AppTrackingProtectionAllowlistModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ public class AppTrackingProtectionAllowlistModel {
public static let groupID = "\(Global.groupIdPrefix).apptp"
public static let fileName = "appTPallowlist"
}

private let filename: String

lazy private var allowlistUrl: URL? = {
let groupContainerUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: Constants.groupID)
return groupContainerUrl?.appendingPathComponent(self.filename, conformingTo: .text)
}()

var allowedDomains: Set<String>

public init(filename: String = Constants.fileName) {
self.allowedDomains = Set<String>()
self.filename = filename

readFromFile()
}

func writeToFile() {
guard let allowlistUrl = allowlistUrl else {
fatalError("Unable to get file location")
}

// Write the allowlist as a textfile with one domain per line
do {
let string = allowedDomains.joined(separator: "\n")
Expand All @@ -59,15 +59,15 @@ public class AppTrackingProtectionAllowlistModel {
print(error.localizedDescription)
}
}

public func readFromFile() {
guard let allowlistUrl = allowlistUrl else {
fatalError("Unable to get file location")
}
guard FileManager.default.fileExists(atPath: allowlistUrl.path) else {
return
}

// Read allowlist from file. Break the string into array then cast to a set.
do {
let strData = try String(contentsOf: allowlistUrl)
Expand All @@ -77,30 +77,30 @@ public class AppTrackingProtectionAllowlistModel {
print(error.localizedDescription)
}
}

public func allow(domain: String) {
allowedDomains.insert(domain)
writeToFile()
}

public func contains(domain: String) -> Bool {
var check = domain
while check.contains(".") {
if allowedDomains.contains(check) {
return true
}

check = String(check.components(separatedBy: ".").dropFirst().joined(separator: "."))
}

return false
}

public func remove(domain: String) {
allowedDomains.remove(domain)
writeToFile()
}

public func clearList() {
allowedDomains.removeAll()
writeToFile()
Expand Down
6 changes: 3 additions & 3 deletions Core/AppTrackingProtectionFeedbackModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ public class AppTrackingProtectionFeedbackModel: ObservableObject {
return []
}
}

public func sendReport(appName: String, category: String, description: String) {
let date = Calendar.current.date(byAdding: .minute, value: -10, to: Date())!
let trackers = trackers(moreRecentThan: date)
let trackersString = trackers.map { $0.domain }.joined(separator: ",")

let parameters = [
"appName": appName,
"category": category,
"description": description,
"blockedTrackers": trackersString
]

Pixel.fire(pixel: .appTPBreakageReport, withAdditionalParameters: parameters)
}

Expand Down
22 changes: 11 additions & 11 deletions Core/AppTrackingProtectionListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AppTrackingProtectionListViewModel: NSObject, ObservableObject, NSF

@Published public var debugModeEnabled = false
@Published public var isOnboarding = false

// We only want to show "Manage Trackers" and "Report an issue" if the user has enabled AppTP at least once
@UserDefaultsWrapper(key: .appTPUsed, defaultValue: false)
public var appTPUsed {
Expand All @@ -49,21 +49,21 @@ public class AppTrackingProtectionListViewModel: NSObject, ObservableObject, NSF
queue.maxConcurrentOperationCount = 1
return queue
}()

private let relativeFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.timeStyle = .none
formatter.dateStyle = .medium
formatter.doesRelativeDateFormatting = true
return formatter
}()

private let relativeTimeFormatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .short
return formatter
}()

private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "MMMM dd"
Expand All @@ -76,26 +76,26 @@ public class AppTrackingProtectionListViewModel: NSObject, ObservableObject, NSF
formatter.timeStyle = .medium
return formatter
}()

private let inputFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
return formatter
}()

public func formattedDate(_ sectionName: String) -> String {
guard let date = inputFormatter.date(from: sectionName) else {
return "Invalid Date"
}

let relativeDate = relativeFormatter.string(from: date)
if relativeDate.rangeOfCharacter(from: .decimalDigits) != nil {
return dateFormatter.string(from: date)
}

return relativeDate
}

/// Returns a relative datestring for the given timestamp. e.g. "5 min. ago"
/// If the timestamp is within 1 second of the current time this function will return `nil`
/// A `nil` return value should be considered "just now".
Expand All @@ -108,7 +108,7 @@ public class AppTrackingProtectionListViewModel: NSObject, ObservableObject, NSF
// return nil here and replace it with UserText on the view side.
return nil
}

return relativeTimeFormatter.localizedString(for: timestamp, relativeTo: Date())
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public class AppTrackingProtectionListViewModel: NSObject, ObservableObject, NSF
self.context.stalenessInterval = 0

super.init()

self.isOnboarding = !appTPUsed

setupFetchedResultsController()
Expand Down
3 changes: 1 addition & 2 deletions Core/AppURLs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import BrowserServicesKit
import Foundation
import Macros

public extension URL {

Expand Down Expand Up @@ -49,7 +48,7 @@ public extension URL {
static let exti = URL(string: "\(base)/exti/\(devMode)")!
static let feedback = URL(string: "\(base)/feedback.js?type=app-feedback")!

static let appStore = #URL("https://apps.apple.com/app/duckduckgo-privacy-browser/id663592361")
static let appStore = URL(string: "https://apps.apple.com/app/duckduckgo-privacy-browser/id663592361")!

static let mac = URL(string: "\(base)/mac")!
static let windows = URL(string: "\(base)/windows")!
Expand Down
4 changes: 2 additions & 2 deletions Core/AtbAndVariantCleanup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class AtbAndVariantCleanup {

static func cleanup(statisticsStorage: StatisticsStore = StatisticsUserDefaults(),
variantManager: VariantManager = DefaultVariantManager()) {

guard let variant = statisticsStorage.variant else { return }

// clean up ATB
if let atb = statisticsStorage.atb, atb.hasSuffix(variant) {
statisticsStorage.atb = String(atb.dropLast(variant.count))
}

// remove existing variant if not in an active experiment
if variantManager.currentVariant == nil {
statisticsStorage.variant = nil
Expand Down
12 changes: 6 additions & 6 deletions Core/BookmarkObjects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ private struct Constants {

public protocol Bookmark: BookmarkItem {
var url: URL? { get set }

var displayTitle: String? { get }
}

public extension Bookmark {

var displayTitle: String? {
let host = url?.host?.droppingWwwPrefix() ?? url?.absoluteString

var displayTitle = (title?.isEmpty ?? true) ? host : title

if let url = url, url.isDuckDuckGo,
let title = displayTitle, title.hasSuffix(Constants.ddgSuffix) {
displayTitle = String(title.dropLast(Constants.ddgSuffix.count))
}

return displayTitle
}
}
Expand All @@ -58,7 +58,7 @@ public protocol BookmarkFolder: BookmarkItem {
}

public extension BookmarkFolder {

var numberOfChildrenDeep: Int {
guard let children = children else { return 0 }
return children.reduce(children.count) { $0 + (($1 as? BookmarkFolder)?.numberOfChildrenDeep ?? 0) }
Expand Down
Loading

0 comments on commit df32fcd

Please sign in to comment.