Skip to content

Commit

Permalink
Merge branch 'main' into dominik/bump-internal-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy authored Mar 4, 2024
2 parents faad4c4 + 039e434 commit d694407
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 32 deletions.
8 changes: 8 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
3184AC6D288F29D800C35E4B /* BadgeNotificationAnimationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3184AC6C288F29D800C35E4B /* BadgeNotificationAnimationModel.swift */; };
3184AC6F288F2A1100C35E4B /* CookieNotificationAnimationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3184AC6E288F2A1100C35E4B /* CookieNotificationAnimationModel.swift */; };
31A3A4E32B0C115F0021063C /* DataBrokerProtection in Frameworks */ = {isa = PBXBuildFile; productRef = 31A3A4E22B0C115F0021063C /* DataBrokerProtection */; };
31AA6B972B960B870025014E /* DataBrokerProtectionLoginItemPixels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31AA6B962B960B870025014E /* DataBrokerProtectionLoginItemPixels.swift */; };
31AA6B982B960BA50025014E /* DataBrokerProtectionLoginItemPixels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31AA6B962B960B870025014E /* DataBrokerProtectionLoginItemPixels.swift */; };
31AA6B992B960BA60025014E /* DataBrokerProtectionLoginItemPixels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31AA6B962B960B870025014E /* DataBrokerProtectionLoginItemPixels.swift */; };
31B4AF532901A4F20013585E /* NSEventExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31B4AF522901A4F20013585E /* NSEventExtension.swift */; };
31C3CE0228EDC1E70002C24A /* CustomRoundedCornersShape.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31C3CE0128EDC1E70002C24A /* CustomRoundedCornersShape.swift */; };
31C9ADE52AF0564500CEF57D /* WaitlistFeatureSetupHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31C9ADE42AF0564500CEF57D /* WaitlistFeatureSetupHandler.swift */; };
Expand Down Expand Up @@ -3376,6 +3379,7 @@
3192EC872A4DCF21001E97A5 /* DBPHomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBPHomeViewController.swift; sourceTree = "<group>"; };
3199C6F82AF94F5B002A7BA1 /* DataBrokerProtectionFeatureDisabler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataBrokerProtectionFeatureDisabler.swift; sourceTree = "<group>"; };
3199C6FC2AF97367002A7BA1 /* DataBrokerProtectionAppEvents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataBrokerProtectionAppEvents.swift; sourceTree = "<group>"; };
31AA6B962B960B870025014E /* DataBrokerProtectionLoginItemPixels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataBrokerProtectionLoginItemPixels.swift; sourceTree = "<group>"; };
31B4AF522901A4F20013585E /* NSEventExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSEventExtension.swift; sourceTree = "<group>"; };
31C3CE0128EDC1E70002C24A /* CustomRoundedCornersShape.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomRoundedCornersShape.swift; sourceTree = "<group>"; };
31C5FFB82AF64D120008A79F /* DataBrokerProtectionFeatureVisibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataBrokerProtectionFeatureVisibility.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4953,6 +4957,7 @@
31C5FFB82AF64D120008A79F /* DataBrokerProtectionFeatureVisibility.swift */,
3199C6F82AF94F5B002A7BA1 /* DataBrokerProtectionFeatureDisabler.swift */,
3199C6FC2AF97367002A7BA1 /* DataBrokerProtectionAppEvents.swift */,
31AA6B962B960B870025014E /* DataBrokerProtectionLoginItemPixels.swift */,
BBDFDC592B2B8A0900F62D90 /* DataBrokerProtectionExternalWaitlistPixels.swift */,
BB5789712B2CA70F0009DFE2 /* DataBrokerProtectionSubscriptionEventHandler.swift */,
4B37EE652B4CFC9500A89A61 /* RemoteMessaging */,
Expand Down Expand Up @@ -9695,6 +9700,7 @@
4B44FEF42B1FEF5A000619D8 /* FocusableTextEditor.swift in Sources */,
3706FAA3293F65D500E42796 /* CrashReportPromptViewController.swift in Sources */,
3706FAA4293F65D500E42796 /* ContextMenuManager.swift in Sources */,
31AA6B982B960BA50025014E /* DataBrokerProtectionLoginItemPixels.swift in Sources */,
3706FAA5293F65D500E42796 /* GradientView.swift in Sources */,
3706FAA6293F65D500E42796 /* PreferencesSidebar.swift in Sources */,
3706FAA7293F65D500E42796 /* NSPointExtension.swift in Sources */,
Expand Down Expand Up @@ -10825,6 +10831,7 @@
4B9579502AC7AE700062CA31 /* ClickToLoadModel.swift in Sources */,
B6F9BDDE2B45B7EE00677B33 /* WebsiteInfo.swift in Sources */,
4B9579512AC7AE700062CA31 /* KeyedCodingExtension.swift in Sources */,
31AA6B992B960BA60025014E /* DataBrokerProtectionLoginItemPixels.swift in Sources */,
4B9579522AC7AE700062CA31 /* PrivacyDashboardTabExtension.swift in Sources */,
4B9579542AC7AE700062CA31 /* DownloadListStore.swift in Sources */,
4B9579552AC7AE700062CA31 /* Logging.swift in Sources */,
Expand Down Expand Up @@ -11605,6 +11612,7 @@
37534CA028113101002621E7 /* LazyLoadable.swift in Sources */,
EAE42800275D47FA00DAC26B /* ClickToLoadModel.swift in Sources */,
0230C0A3272080090018F728 /* KeyedCodingExtension.swift in Sources */,
31AA6B972B960B870025014E /* DataBrokerProtectionLoginItemPixels.swift in Sources */,
B6BF5D852946FFDA006742B1 /* PrivacyDashboardTabExtension.swift in Sources */,
B6C0B23026E61D630031CB7F /* DownloadListStore.swift in Sources */,
85799C1825DEBB3F0007EC87 /* Logging.swift in Sources */,
Expand Down
4 changes: 0 additions & 4 deletions DuckDuckGo/DBP/DBPHomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ public class DataBrokerProtectionPixelsHandler: EventMapping<DataBrokerProtectio
.ipcServerScanAllBrokers,
.ipcServerRunQueuedOperations,
.ipcServerRunAllOperations,
.enableLoginItem,
.restartLoginItem,
.disableLoginItem,
.resetLoginItem,
.scanSuccess,
.scanFailed,
.scanError,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/DBP/DataBrokerProtectionAppEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct DataBrokerProtectionAppEvents {
}

private func restartBackgroundAgent(loginItemsManager: LoginItemsManager) {
pixelHandler.fire(.resetLoginItem)
DataBrokerProtectionLoginItemPixels.fire(pixel: .dataBrokerResetLoginItemDaily, frequency: .dailyOnly)
loginItemsManager.disableLoginItems([LoginItem.dbpBackgroundAgent])
loginItemsManager.enableLoginItems([LoginItem.dbpBackgroundAgent], log: .dbp)

Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/DBP/DataBrokerProtectionFeatureDisabler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import Foundation
import DataBrokerProtection
import Common

public extension Notification.Name {
static let dbpWasDisabled = Notification.Name("com.duckduckgo.DBP.DBPWasDisabled")
Expand Down Expand Up @@ -47,6 +48,7 @@ struct DataBrokerProtectionFeatureDisabler: DataBrokerProtectionFeatureDisabling

dataManager.removeAllData()

DataBrokerProtectionLoginItemPixels.fire(pixel: .dataBrokerDisableAndDeleteDaily, frequency: .dailyOnly)
NotificationCenter.default.post(name: .dbpWasDisabled, object: nil)
}
}
Expand Down
6 changes: 5 additions & 1 deletion DuckDuckGo/DBP/DataBrokerProtectionFeatureVisibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import Foundation
import BrowserServicesKit
import Common
import DataBrokerProtection

protocol DataBrokerProtectionFeatureVisibility {
func isFeatureVisible() -> Bool
Expand All @@ -31,14 +32,17 @@ protocol DataBrokerProtectionFeatureVisibility {
struct DefaultDataBrokerProtectionFeatureVisibility: DataBrokerProtectionFeatureVisibility {
private let privacyConfigurationManager: PrivacyConfigurationManaging
private let featureDisabler: DataBrokerProtectionFeatureDisabling
private let pixelHandler: EventMapping<DataBrokerProtectionPixels>

/// Temporary code to use while we have both redeem flow for diary study users. Should be removed later
static var bypassWaitlist = false

init(privacyConfigurationManager: PrivacyConfigurationManaging = ContentBlocking.shared.privacyConfigurationManager,
featureDisabler: DataBrokerProtectionFeatureDisabling = DataBrokerProtectionFeatureDisabler()) {
featureDisabler: DataBrokerProtectionFeatureDisabling = DataBrokerProtectionFeatureDisabler(),
pixelHandler: EventMapping<DataBrokerProtectionPixels> = DataBrokerProtectionPixelsHandler()) {
self.privacyConfigurationManager = privacyConfigurationManager
self.featureDisabler = featureDisabler
self.pixelHandler = pixelHandler
}

var waitlistIsOngoing: Bool {
Expand Down
36 changes: 36 additions & 0 deletions DuckDuckGo/DBP/DataBrokerProtectionLoginItemPixels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// DataBrokerProtectionLoginItemPixels.swift
//
// Copyright © 2024 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

struct DataBrokerProtectionLoginItemPixels {

static func fire(pixel: Pixel.Event, frequency: DailyPixel.PixelFrequency) {

DispatchQueue.main.async { // delegateTyped needs to be called in the main thread
let isInternalUser = NSApp.delegateTyped.internalUserDecider.isInternalUser
DailyPixel.fire(pixel: pixel,
frequency: frequency,
includeAppVersionParameter: true,
withAdditionalParameters: [
"isInternalUser": isInternalUser.description
]
)
}
}
}
8 changes: 3 additions & 5 deletions DuckDuckGo/DBP/DataBrokerProtectionLoginItemScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@ import Common
final class DataBrokerProtectionLoginItemScheduler {
private let ipcScheduler: DataBrokerProtectionIPCScheduler
private let loginItemsManager: LoginItemsManager
private let pixelHandler: EventMapping<DataBrokerProtectionPixels>

init(ipcScheduler: DataBrokerProtectionIPCScheduler, loginItemsManager: LoginItemsManager = .init(), pixelHandler: EventMapping<DataBrokerProtectionPixels>) {
init(ipcScheduler: DataBrokerProtectionIPCScheduler, loginItemsManager: LoginItemsManager = .init()) {
self.ipcScheduler = ipcScheduler
self.loginItemsManager = loginItemsManager
self.pixelHandler = pixelHandler
}

// MARK: - Login Item Management

func disableLoginItem() {
pixelHandler.fire(.disableLoginItem)
DataBrokerProtectionLoginItemPixels.fire(pixel: .dataBrokerDisableLoginItemDaily, frequency: .dailyOnly)
loginItemsManager.disableLoginItems([.dbpBackgroundAgent])
}

func enableLoginItem() {
pixelHandler.fire(.enableLoginItem)
DataBrokerProtectionLoginItemPixels.fire(pixel: .dataBrokerEnableLoginItemDaily, frequency: .dailyOnly)
loginItemsManager.enableLoginItems([.dbpBackgroundAgent], log: .dbp)
}
}
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/DBP/DataBrokerProtectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class DataBrokerProtectionManager {

let ipcScheduler = DataBrokerProtectionIPCScheduler(ipcClient: ipcClient)

return DataBrokerProtectionLoginItemScheduler(ipcScheduler: ipcScheduler, pixelHandler: pixelHandler)
return DataBrokerProtectionLoginItemScheduler(ipcScheduler: ipcScheduler)
}()

private init() {
Expand Down
11 changes: 11 additions & 0 deletions DuckDuckGo/Statistics/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ extension Pixel {
case dataBrokerProtectionRemoteMessageDismissed(messageID: String)
case dataBrokerProtectionRemoteMessageOpened(messageID: String)

// Login Item events
case dataBrokerEnableLoginItemDaily
case dataBrokerDisableLoginItemDaily
case dataBrokerResetLoginItemDaily
case dataBrokerDisableAndDeleteDaily

// DataBrokerProtection Other
case dataBrokerProtectionErrorWhenFetchingSubscriptionAuthTokenAfterSignIn

Expand Down Expand Up @@ -574,6 +580,11 @@ extension Pixel.Event {
case .dataBrokerProtectionRemoteMessageOpened(let messageID):
return "m_mac_dbp_remote_message_opened_\(messageID)"

case .dataBrokerEnableLoginItemDaily: return "m_mac_dbp_daily_login-item_enable"
case .dataBrokerDisableLoginItemDaily: return "m_mac_dbp_daily_login-item_disable"
case .dataBrokerResetLoginItemDaily: return "m_mac_dbp_daily_login-item_reset"
case .dataBrokerDisableAndDeleteDaily: return "m_mac_dbp_daily_disable-and-delete"

case .dailyPixel(let pixel, isFirst: let isFirst):
return pixel.name + (isFirst ? "_d" : "_c")
case .networkProtectionGeoswitchingOpened:
Expand Down
6 changes: 5 additions & 1 deletion DuckDuckGo/Statistics/PixelParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ extension Pixel.Event {
.dataBrokerProtectionErrorWhenFetchingSubscriptionAuthTokenAfterSignIn,
.dataBrokerProtectionRemoteMessageOpened,
.dataBrokerProtectionRemoteMessageDisplayed,
.dataBrokerProtectionRemoteMessageDismissed:
.dataBrokerProtectionRemoteMessageDismissed,
.dataBrokerDisableAndDeleteDaily,
.dataBrokerEnableLoginItemDaily,
.dataBrokerDisableLoginItemDaily,
.dataBrokerResetLoginItemDaily:
return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ public enum DataBrokerProtectionPixels {
case ipcServerRunQueuedOperationsCompletion(error: Error?)
case ipcServerRunAllOperations

// Login Item events
case enableLoginItem
case restartLoginItem
case disableLoginItem
case resetLoginItem

// DataBrokerProtection User Notifications
case dataBrokerProtectionNotificationSentFirstScanComplete
case dataBrokerProtectionNotificationOpenedFirstScanComplete
Expand Down Expand Up @@ -169,11 +163,6 @@ extension DataBrokerProtectionPixels: PixelKitEvent {
case .ipcServerRunQueuedOperationsCompletion: return "m_mac_dbp_ipc-server_run-queued-operations_completion"
case .ipcServerRunAllOperations: return "m_mac_dbp_ipc-server_run-all-operations"

case .enableLoginItem: return "m_mac_dbp_login-item_enable"
case .restartLoginItem: return "m_mac_dbp_login-item_restart"
case .disableLoginItem: return "m_mac_dbp_login-item_disable"
case .resetLoginItem: return "m_mac_dbp_login-item_reset"

// User Notifications
case .dataBrokerProtectionNotificationSentFirstScanComplete:
return "m_mac_dbp_notification_sent_first_scan_complete"
Expand Down Expand Up @@ -247,10 +236,6 @@ extension DataBrokerProtectionPixels: PixelKitEvent {
.backgroundAgentRunOperationsAndStartSchedulerIfPossibleNoSavedProfile,
.backgroundAgentRunOperationsAndStartSchedulerIfPossibleRunQueuedOperationsCallbackStartScheduler,
.backgroundAgentStartedStoppingDueToAnotherInstanceRunning,
.enableLoginItem,
.restartLoginItem,
.disableLoginItem,
.resetLoginItem,
.dataBrokerProtectionNotificationSentFirstScanComplete,
.dataBrokerProtectionNotificationOpenedFirstScanComplete,
.dataBrokerProtectionNotificationSentFirstRemoval,
Expand Down Expand Up @@ -322,10 +307,6 @@ public class DataBrokerProtectionPixelsHandler: EventMapping<DataBrokerProtectio
.ipcServerScanAllBrokers,
.ipcServerRunQueuedOperations,
.ipcServerRunAllOperations,
.enableLoginItem,
.restartLoginItem,
.disableLoginItem,
.resetLoginItem,
.scanSuccess,
.scanFailed,
.scanError,
Expand Down

0 comments on commit d694407

Please sign in to comment.