Skip to content

Commit

Permalink
Merge branch 'sam/vpn-ui-improvements-3-combine-notification-settings…
Browse files Browse the repository at this point in the history
…' into sam/vpn-ui-improvements-4-location-setting-change

# By Mariusz Śpiewak (3) and others
# Via Sam Symons (4) and others
* sam/vpn-ui-improvements-3-combine-notification-settings:
  Subscriptions: 20 - Subscription Caching (#2569)
  Subscriptions: 19. Error handling and minor updates (#2567)
  Use History on iOS (#2539)
  Release 7.112.0-1 (#2573)
  Report on toggle protections off (#2536)
  Release 7.112.0-0 (#2572)
  Update autoconsent to v10.2.0 (#2554)
  update metadata (#2571)
  Subscription pro pixels (#2531)
  Update SwiftSoup and Kingfisher versions (#2566)
  Move vpnFirstEnabled and networkPathChange out of VPNSettings (#2560)
  Fix VPN view model memory leak (#2570)
  Bump submodules/privacy-reference-tests from `40ce868` to `a603ff9` (#2500)
  18. Subscription Entitlements caching (#2556)
  Release 7.111.0-2 (#2563)
  Revert "Report Apple Ad attribution using pixel (#2510)" (#2562)
  Vanilla browser integration (#2550)
  Fix blank space after URL bar hides (#2549)
  Release 7.111.0-1 (#2561)

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
#	DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
  • Loading branch information
samsymons committed Mar 13, 2024
2 parents 515be22 + dce136f commit 934502c
Show file tree
Hide file tree
Showing 160 changed files with 3,501 additions and 2,471 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 = "\"73cfb8d6f397fd1de921f057db1bcc44\""
public static let embeddedDataSHA = "3debb4a1e5c6cc292b3c03d9ea6ce4daa8073ab0c033131f2f8dbe1f752dfaf1"
}

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
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 934502c

Please sign in to comment.