Skip to content

Commit

Permalink
Merge branch 'main' into sam/rmf-survey-updates
Browse files Browse the repository at this point in the history
# By Elle Sullivan (8) and others
# Via Elle Sullivan (3) and GitHub (2)
* main: (26 commits)
  Autofill engagement KPIs for pixel reporting (#2806)
  autofill: don't prefix autofill email pixels with `m.mac.` (#2808)
  Bump BSK (#2807)
  Make profile selector optional (#2811)
  Add History to iOS (updated UI and rollout) (#2770)
  New autofill save & update password prompt pixels for alignment with iOS (#2801)
  Add mylife data broker (#2786)
  Increase test timeout (#2810)
  Subscription refactoring, BSK update (#2809)
  Check for entitlement in DBP agent (#2802)
  move permanent survey card to first position (#2804)
  Subscription refactoring (#2764)
  Bump version to 1.89.0 (191)
  Merge pir stabilization feature branch into main (#2789)
  Update age params for multiple brokers (#2800)
  Fix top level navigation blocks (#2792)
  Adding to the Dock automatically (#2722)
  Fix lint error
  Make activity only call completion once all work has actually finished
  Fix activity scheduler not calling completion
  ...

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
#	DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
  • Loading branch information
samsymons committed May 24, 2024
2 parents 433a568 + 22905cd commit 61655d0
Show file tree
Hide file tree
Showing 173 changed files with 6,652 additions and 3,382 deletions.
2 changes: 1 addition & 1 deletion Configuration/BuildNumber.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 190
CURRENT_PROJECT_VERSION = 191
279 changes: 199 additions & 80 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"branch" : "sam/rmf-survey-updates",
"revision" : "b080d80b2615fbd0c8e146a2d4ba3b10a0e9e325"
"revision" : "e1e436422bc167933baa0f90838958f2ac7119f3",
"version" : "146.2.0"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "bb8e7e62104ed6506c7bfd3ef7aa4aca3686ed4f",
"version" : "5.15.0"
"revision" : "fa861c4eccb21d235e34070b208b78bdc32ece08",
"version" : "5.17.0"
}
},
{
Expand Down Expand Up @@ -131,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
<Test
Identifier = "CoreDataEncryptionTests/testSavingIncorrectValueTypes()">
</Test>
<Test
Identifier = "DownloadsIntegrationTests/testWhenDownloadIsStartedInNewTab_tabIsClosed()">
</Test>
<Test
Identifier = "EncryptionKeyStoreTests">
</Test>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
159 changes: 90 additions & 69 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import ServiceManagement
import SyncDataProviders
import UserNotifications
import Lottie

import NetworkProtection
import Subscription
import NetworkProtectionIPC
import DataBrokerProtection

@MainActor
// @MainActor
final class AppDelegate: NSObject, NSApplicationDelegate {

#if DEBUG
Expand Down Expand Up @@ -76,6 +76,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
let featureFlagger: FeatureFlagger
private var appIconChanger: AppIconChanger!
private var autoClearHandler: AutoClearHandler!
private(set) var autofillPixelReporter: AutofillPixelReporter?

private(set) var syncDataProviders: SyncDataProviders!
private(set) var syncService: DDGSyncing?
Expand All @@ -86,20 +87,21 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
let bookmarksManager = LocalBookmarkManager.shared
var privacyDashboardWindow: NSWindow?

// Needs to be lazy as indirectly depends on AppDelegate
private lazy var networkProtectionSubscriptionEventHandler: NetworkProtectionSubscriptionEventHandler = {

let ipcClient = TunnelControllerIPCClient()
let tunnelController = NetworkProtectionIPCTunnelController(ipcClient: ipcClient)
let vpnUninstaller = VPNUninstaller(ipcClient: ipcClient)
private var accountManager: AccountManaging {
subscriptionManager.accountManager
}
public let subscriptionManager: SubscriptionManaging
public let vpnSettings = VPNSettings(defaults: .netP)

return NetworkProtectionSubscriptionEventHandler(
tunnelController: tunnelController,
vpnUninstaller: vpnUninstaller)
private var networkProtectionSubscriptionEventHandler: NetworkProtectionSubscriptionEventHandler?
#if DBP
private lazy var dataBrokerProtectionSubscriptionEventHandler: DataBrokerProtectionSubscriptionEventHandler = {
let authManager = DataBrokerAuthenticationManagerBuilder.buildAuthenticationManager(subscriptionManager: subscriptionManager)
return DataBrokerProtectionSubscriptionEventHandler(featureDisabler: DataBrokerProtectionFeatureDisabler(),
authenticationManager: authManager,
pixelHandler: DataBrokerProtectionPixelsHandler())
}()

#if DBP
private let dataBrokerProtectionSubscriptionEventHandler = DataBrokerProtectionSubscriptionEventHandler()
#endif

private var didFinishLaunching = false
Expand Down Expand Up @@ -188,19 +190,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
privacyConfigManager: AppPrivacyFeatures.shared.contentBlocking.privacyConfigurationManager
)

#if APPSTORE || !STRIPE
SubscriptionPurchaseEnvironment.current = .appStore
#else
SubscriptionPurchaseEnvironment.current = .stripe
#endif
}
// Configure Subscription
subscriptionManager = SubscriptionManager()

static func configurePixelKit() {
#if DEBUG
Self.setUpPixelKit(dryRun: true)
#else
Self.setUpPixelKit(dryRun: false)
#endif
// Update VPN environment and match the Subscription environment
vpnSettings.alignTo(subscriptionEnvironment: subscriptionManager.currentEnvironment)

// Update DBP environment and match the Subscription environment
DataBrokerProtectionSettings().alignTo(subscriptionEnvironment: subscriptionManager.currentEnvironment)
}

func applicationWillFinishLaunching(_ notification: Notification) {
Expand All @@ -217,6 +214,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
#endif

appIconChanger = AppIconChanger(internalUserDecider: internalUserDecider)

// Configure Event handlers
let ipcClient = TunnelControllerIPCClient()
let tunnelController = NetworkProtectionIPCTunnelController(ipcClient: ipcClient)
let vpnUninstaller = VPNUninstaller(ipcClient: ipcClient)

networkProtectionSubscriptionEventHandler = NetworkProtectionSubscriptionEventHandler(subscriptionManager: subscriptionManager,
tunnelController: tunnelController,
vpnUninstaller: vpnUninstaller)
}

// swiftlint:disable:next function_body_length
Expand Down Expand Up @@ -264,19 +270,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

startupSync()

let defaultEnvironment = SubscriptionPurchaseEnvironment.ServiceEnvironment.default

let currentEnvironment = UserDefaultsWrapper(key: .subscriptionEnvironment,
defaultValue: defaultEnvironment).wrappedValue
SubscriptionPurchaseEnvironment.currentServiceEnvironment = currentEnvironment

Task {
let accountManager = AccountManager(subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs))
if let token = accountManager.accessToken {
_ = await SubscriptionService.getSubscription(accessToken: token, cachePolicy: .reloadIgnoringLocalCacheData)
_ = await accountManager.fetchEntitlements(cachePolicy: .reloadIgnoringLocalCacheData)
}
}
subscriptionManager.loadInitialData()

if [.normal, .uiTests].contains(NSApp.runType) {
stateRestorationManager.applicationDidFinishLaunching()
Expand Down Expand Up @@ -314,9 +308,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

UserDefaultsWrapper<Any>.clearRemovedKeys()

networkProtectionSubscriptionEventHandler.registerForSubscriptionAccountManagerEvents()
networkProtectionSubscriptionEventHandler?.registerForSubscriptionAccountManagerEvents()

NetworkProtectionAppEvents().applicationDidFinishLaunching()
NetworkProtectionAppEvents(featureVisibility: DefaultNetworkProtectionVisibility(subscriptionManager: subscriptionManager)).applicationDidFinishLaunching()
UNUserNotificationCenter.current().delegate = self

#if DBP
Expand All @@ -328,6 +322,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
#endif

setUpAutoClearHandler()

setUpAutofillPixelReporter()
}

func applicationDidBecomeActive(_ notification: Notification) {
Expand All @@ -336,15 +332,18 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
syncService?.initializeIfNeeded()
syncService?.scheduler.notifyAppLifecycleEvent()

NetworkProtectionAppEvents().applicationDidBecomeActive()

NetworkProtectionAppEvents(featureVisibility: DefaultNetworkProtectionVisibility(subscriptionManager: subscriptionManager)).applicationDidBecomeActive()
#if DBP
DataBrokerProtectionAppEvents().applicationDidBecomeActive()
#endif

AppPrivacyFeatures.shared.contentBlocking.privacyConfigurationManager.toggleProtectionsCounter.sendEventsIfNeeded()

updateSubscriptionStatus()
subscriptionManager.updateSubscriptionStatus { isActive in
if isActive {
PixelKit.fire(PrivacyProPixel.privacyProSubscriptionActive, frequency: .daily)
}
}
}

func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
Expand Down Expand Up @@ -386,9 +385,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
urlEventHandler.handleFiles(files)
}

private func applyPreferredTheme() {
let appearancePreferences = AppearancePreferences()
appearancePreferences.updateUserInterfaceStyle()
// MARK: - PixelKit

static func configurePixelKit() {
#if DEBUG
Self.setUpPixelKit(dryRun: true)
#else
Self.setUpPixelKit(dryRun: false)
#endif
}

private static func setUpPixelKit(dryRun: Bool) {
Expand All @@ -415,6 +419,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
}

// MARK: - Theme

private func applyPreferredTheme() {
let appearancePreferences = AppearancePreferences()
appearancePreferences.updateUserInterfaceStyle()
}

// MARK: - Sync

private func startupSync() {
Expand Down Expand Up @@ -490,7 +501,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
switch response {
case .alertSecondButtonReturn:
alert.window.sheetParent?.endSheet(alert.window)
WindowControllersManager.shared.showPreferencesTab(withSelectedPane: .sync)
DispatchQueue.main.async {
WindowControllersManager.shared.showPreferencesTab(withSelectedPane: .sync)
}
default:
break
}
Expand Down Expand Up @@ -567,30 +580,36 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}

private func setUpAutoClearHandler() {
autoClearHandler = AutoClearHandler(preferences: .shared,
fireViewModel: FireCoordinator.fireViewModel,
stateRestorationManager: stateRestorationManager)
autoClearHandler.handleAppLaunch()
autoClearHandler.onAutoClearCompleted = {
NSApplication.shared.reply(toApplicationShouldTerminate: true)
}
}

}

func updateSubscriptionStatus() {
Task {
let accountManager = AccountManager(subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs))

guard let token = accountManager.accessToken else { return }

if case .success(let subscription) = await SubscriptionService.getSubscription(accessToken: token, cachePolicy: .reloadIgnoringLocalCacheData) {
if subscription.isActive {
PixelKit.fire(PrivacyProPixel.privacyProSubscriptionActive, frequency: .daily)
DispatchQueue.main.async {
self.autoClearHandler = AutoClearHandler(preferences: .shared,
fireViewModel: FireCoordinator.fireViewModel,
stateRestorationManager: self.stateRestorationManager)
self.autoClearHandler.handleAppLaunch()
self.autoClearHandler.onAutoClearCompleted = {
NSApplication.shared.reply(toApplicationShouldTerminate: true)
}
}
}

_ = await accountManager.fetchEntitlements(cachePolicy: .reloadIgnoringLocalCacheData)
private func setUpAutofillPixelReporter() {
autofillPixelReporter = AutofillPixelReporter(
userDefaults: .standard,
eventMapping: EventMapping<AutofillPixelEvent> {event, _, params, _ in
switch event {
case .autofillActiveUser:
PixelKit.fire(GeneralPixel.autofillActiveUser)
case .autofillEnabledUser:
PixelKit.fire(GeneralPixel.autofillEnabledUser)
case .autofillOnboardedUser:
PixelKit.fire(GeneralPixel.autofillOnboardedUser)
case .autofillLoginsStacked:
PixelKit.fire(GeneralPixel.autofillLoginsStacked, withAdditionalParameters: params)
case .autofillCreditCardsStacked:
PixelKit.fire(GeneralPixel.autofillCreditCardsStacked, withAdditionalParameters: params)
}
},
passwordManager: PasswordManagerCoordinator.shared,
installDate: AppDelegate.firstLaunchDate)
}
}

Expand All @@ -609,7 +628,9 @@ extension AppDelegate: UNUserNotificationCenterDelegate {

#if DBP
if response.notification.request.identifier == DataBrokerProtectionWaitlist.notificationIdentifier {
DataBrokerProtectionAppEvents().handleWaitlistInvitedNotification(source: .localPush)
DispatchQueue.main.async {
DataBrokerProtectionAppEvents().handleWaitlistInvitedNotification(source: .localPush)
}
}
#endif
}
Expand Down
12 changes: 7 additions & 5 deletions DuckDuckGo/Application/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ import Foundation
final class Application: NSApplication {

private let copyHandler = CopyHandler()
private var _delegate: AppDelegate!
// private var _delegate: AppDelegate!
public static var appDelegate: AppDelegate!

override init() {
super.init()

_delegate = AppDelegate()
self.delegate = _delegate
let delegate = AppDelegate()
self.delegate = delegate
Application.appDelegate = delegate

let mainMenu = MainMenu(featureFlagger: _delegate.featureFlagger,
bookmarkManager: _delegate.bookmarksManager,
let mainMenu = MainMenu(featureFlagger: delegate.featureFlagger,
bookmarkManager: delegate.bookmarksManager,
faviconManager: FaviconManager.shared,
copyHandler: copyHandler)
self.mainMenu = mainMenu
Expand Down
Loading

0 comments on commit 61655d0

Please sign in to comment.