Skip to content

Commit

Permalink
Merge branch 'develop' into fcappelli/breakage_report_improvements
Browse files Browse the repository at this point in the history
# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
#	DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
  • Loading branch information
federicocappelli committed Nov 28, 2023
2 parents f334cf6 + ac1cd2c commit db29e27
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 99 deletions.
2 changes: 0 additions & 2 deletions Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ public struct PixelParameters {
public static let returnUserErrorCode = "error_code"
public static let returnUserOldATB = "old_atb"
public static let returnUserNewATB = "new_atb"

public static let autofillDefaultState = "default_state"
}

public struct PixelValues {
Expand Down
24 changes: 8 additions & 16 deletions DuckDuckGo/AutofillLoginPromptViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ class AutofillLoginPromptViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if trigger == AutofillUserScript.GetTriggerType.autoprompt {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineAutopromptDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineAutopromptDisplayed)
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDisplayed)
}
}

Expand All @@ -97,11 +95,9 @@ class AutofillLoginPromptViewController: UIViewController {
extension AutofillLoginPromptViewController: UISheetPresentationControllerDelegate {
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
if self.trigger == AutofillUserScript.GetTriggerType.autoprompt {
Pixel.fire(pixel: .autofillLoginsAutopromptDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsAutopromptDismissed)
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDismissed)
}
completion?(nil, false)
}
Expand All @@ -111,11 +107,9 @@ extension AutofillLoginPromptViewController: AutofillLoginPromptViewModelDelegat
func autofillLoginPromptViewModel(_ viewModel: AutofillLoginPromptViewModel, didSelectAccount account: SecureVaultModels.WebsiteAccount) {

if trigger == AutofillUserScript.GetTriggerType.autoprompt {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineAutopromptConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineAutopromptConfirmed)
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualConfirmed)
}

if AppDependencyProvider.shared.autofillLoginSession.isValidSession {
Expand Down Expand Up @@ -169,11 +163,9 @@ extension AutofillLoginPromptViewController: AutofillLoginPromptViewModelDelegat
func autofillLoginPromptViewModelDidCancel(_ viewModel: AutofillLoginPromptViewModel) {
dismiss(animated: true) {
if self.trigger == AutofillUserScript.GetTriggerType.autoprompt {
Pixel.fire(pixel: .autofillLoginsAutopromptDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsAutopromptDismissed)
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDismissed)
}

self.completion?(nil, false)
Expand Down
6 changes: 2 additions & 4 deletions DuckDuckGo/AutofillLoginSettingsListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,9 @@ extension AutofillLoginSettingsListViewController: AutofillLoginDetailsViewContr
extension AutofillLoginSettingsListViewController: EnableAutofillSettingsTableViewCellDelegate {
func enableAutofillSettingsTableViewCell(_ cell: EnableAutofillSettingsTableViewCell, didChangeSettings value: Bool) {
if value {
Pixel.fire(pixel: .autofillLoginsSettingsEnabled,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsSettingsEnabled)
} else {
Pixel.fire(pixel: .autofillLoginsSettingsDisabled,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsSettingsDisabled)
}

viewModel.isAutofillEnabledInSettings = value
Expand Down
4 changes: 0 additions & 4 deletions DuckDuckGo/AutofillSettingStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,4 @@ struct AutofillSettingStatus {
let canAuthenticate = context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)
return appSettings.autofillCredentialsEnabled && canAuthenticate
}

static var defaultState: String {
return appSettings.autofillCredentialsHasBeenEnabledAutomaticallyIfNecessary ? "on" : "off"
}
}
17 changes: 7 additions & 10 deletions DuckDuckGo/NetworkProtectionConvenienceInitialisers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ extension NetworkProtectionKeychainTokenStore {

extension NetworkProtectionCodeRedemptionCoordinator {
convenience init() {
let tunnelSettings = TunnelSettings(defaults: .networkProtectionGroupDefaults)
let settings = VPNSettings(defaults: .networkProtectionGroupDefaults)
self.init(
environment: tunnelSettings.selectedEnvironment,
environment: settings.selectedEnvironment,
tokenStore: NetworkProtectionKeychainTokenStore(),
errorEvents: .networkProtectionAppDebugEvents
)
Expand All @@ -65,27 +65,24 @@ extension NetworkProtectionCodeRedemptionCoordinator {

extension NetworkProtectionVPNNotificationsViewModel {
convenience init() {
let notificationsSettingsStore = NetworkProtectionNotificationsSettingsUserDefaultsStore(userDefaults: .networkProtectionGroupDefaults)
self.init(
notificationsAuthorization: NotificationsAuthorizationController(),
notificationsSettingsStore: notificationsSettingsStore
settings: VPNSettings(defaults: .networkProtectionGroupDefaults)
)
}
}

extension NetworkProtectionVPNSettingsViewModel {
convenience init() {
self.init(
tunnelSettings: TunnelSettings(defaults: .networkProtectionGroupDefaults)
)
self.init(settings: VPNSettings(defaults: .networkProtectionGroupDefaults))
}
}

extension NetworkProtectionLocationListCompositeRepository {
convenience init() {
let tunnelSettings = TunnelSettings(defaults: .networkProtectionGroupDefaults)
let settings = VPNSettings(defaults: .networkProtectionGroupDefaults)
self.init(
environment: tunnelSettings.selectedEnvironment,
environment: settings.selectedEnvironment,
tokenStore: NetworkProtectionKeychainTokenStore()
)
}
Expand All @@ -96,7 +93,7 @@ extension NetworkProtectionVPNLocationViewModel {
let locationListRepository = NetworkProtectionLocationListCompositeRepository()
self.init(
locationListRepository: locationListRepository,
tunnelSettings: TunnelSettings(defaults: .networkProtectionGroupDefaults)
settings: VPNSettings(defaults: .networkProtectionGroupDefaults)
)
}
}
Expand Down
14 changes: 7 additions & 7 deletions DuckDuckGo/NetworkProtectionVPNLocationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import NetworkProtection

final class NetworkProtectionVPNLocationViewModel: ObservableObject {
private let locationListRepository: NetworkProtectionLocationListRepository
private let tunnelSettings: TunnelSettings
private let settings: VPNSettings
@Published public var state: LoadingState
@Published public var isNearestSelected: Bool

Expand All @@ -43,32 +43,32 @@ final class NetworkProtectionVPNLocationViewModel: ObservableObject {
}
}

init(locationListRepository: NetworkProtectionLocationListRepository, tunnelSettings: TunnelSettings) {
init(locationListRepository: NetworkProtectionLocationListRepository, settings: VPNSettings) {
self.locationListRepository = locationListRepository
self.tunnelSettings = tunnelSettings
self.settings = settings
state = .loading
self.isNearestSelected = tunnelSettings.selectedLocation == .nearest
self.isNearestSelected = settings.selectedLocation == .nearest
}

func onViewAppeared() async {
await reloadList()
}

func onNearestItemSelection() async {
tunnelSettings.selectedLocation = .nearest
settings.selectedLocation = .nearest
await reloadList()
}

func onCountryItemSelection(id: String, cityId: String? = nil) async {
let location = NetworkProtectionSelectedLocation(country: id, city: cityId)
tunnelSettings.selectedLocation = .location(location)
settings.selectedLocation = .location(location)
await reloadList()
}

@MainActor
private func reloadList() async {
guard let list = try? await locationListRepository.fetchLocationList() else { return }
let selectedLocation = self.tunnelSettings.selectedLocation
let selectedLocation = self.settings.selectedLocation
let isNearestSelected = selectedLocation == .nearest

let countryItems = list.map { currentLocation in
Expand Down
10 changes: 5 additions & 5 deletions DuckDuckGo/NetworkProtectionVPNNotificationsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ enum NetworkProtectionNotificationsViewKind: Equatable {

final class NetworkProtectionVPNNotificationsViewModel: ObservableObject {
private var notificationsAuthorization: NotificationsAuthorizationControlling
private var notificationsSettingsStore: NetworkProtectionNotificationsSettingsStore
private var settings: VPNSettings
@Published var viewKind: NetworkProtectionNotificationsViewKind = .loading
var alertsEnabled: Bool {
self.notificationsSettingsStore.alertsEnabled
self.settings.notifyStatusChanges
}

init(notificationsAuthorization: NotificationsAuthorizationControlling,
notificationsSettingsStore: NetworkProtectionNotificationsSettingsStore) {
settings: VPNSettings) {
self.notificationsAuthorization = notificationsAuthorization
self.notificationsSettingsStore = notificationsSettingsStore
self.settings = settings
self.notificationsAuthorization.delegate = self
}

Expand All @@ -55,7 +55,7 @@ final class NetworkProtectionVPNNotificationsViewModel: ObservableObject {
}

func didToggleAlerts(to enabled: Bool) {
notificationsSettingsStore.alertsEnabled = enabled
settings.notifyStatusChanges = enabled
}

private func updateViewKind(for authorizationStatus: UNAuthorizationStatus) {
Expand Down
8 changes: 4 additions & 4 deletions DuckDuckGo/NetworkProtectionVPNSettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import NetworkProtection
import Combine

final class NetworkProtectionVPNSettingsViewModel: ObservableObject {
private let tunnelSettings: TunnelSettings
private let settings: VPNSettings
private var cancellable: AnyCancellable?

@Published public var preferredLocation: String = UserText.netPPreferredLocationNearest

init(tunnelSettings: TunnelSettings) {
self.tunnelSettings = tunnelSettings
cancellable = tunnelSettings.selectedLocationPublisher.map { selectedLocation in
init(settings: VPNSettings) {
self.settings = settings
cancellable = settings.selectedLocationPublisher.map { selectedLocation in
guard let selectedLocation = selectedLocation.location else {
return UserText.netPPreferredLocationNearest
}
Expand Down
12 changes: 4 additions & 8 deletions DuckDuckGo/PasswordGenerationPromptViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class PasswordGenerationPromptViewController: UIViewController {

setupPasswordGenerationPromptView()

Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDisplayed)
}

private func setupPasswordGenerationPromptView() {
Expand All @@ -68,26 +67,23 @@ class PasswordGenerationPromptViewController: UIViewController {

extension PasswordGenerationPromptViewController: UISheetPresentationControllerDelegate {
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDismissed)

self.completion?(false)
}
}

extension PasswordGenerationPromptViewController: PasswordGenerationPromptViewModelDelegate {
func passwordGenerationPromptViewModelDidSelect(_ viewModel: PasswordGenerationPromptViewModel) {
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptConfirmed)

dismiss(animated: true) {
self.completion?(true)
}
}

func passwordGenerationPromptViewModelDidCancel(_ viewModel: PasswordGenerationPromptViewModel) {
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDismissed)

dismiss(animated: true) {
self.completion?(false)
Expand Down
27 changes: 9 additions & 18 deletions DuckDuckGo/SaveLoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ class SaveLoginViewController: UIViewController {
}
switch viewModel.layoutType {
case .newUser, .saveLogin:
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDismissed)
case .savePassword:
Pixel.fire(pixel: .autofillLoginsSavePasswordModalDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsSavePasswordModalDismissed)
case .updateUsername:
Pixel.fire(pixel: .autofillLoginsUpdateUsernameModalDismissed)
case .updatePassword:
Expand All @@ -98,11 +96,9 @@ class SaveLoginViewController: UIViewController {

switch saveViewModel.layoutType {
case .newUser, .saveLogin:
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDisplayed)
case .savePassword:
Pixel.fire(pixel: .autofillLoginsSavePasswordModalDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsSavePasswordModalDisplayed)
case .updateUsername:
Pixel.fire(pixel: .autofillLoginsUpdateUsernameModalDisplayed)
case .updatePassword:
Expand All @@ -116,11 +112,9 @@ extension SaveLoginViewController: SaveLoginViewModelDelegate {
switch viewModel.layoutType {
case .saveLogin, .savePassword, .newUser:
if viewModel.layoutType == .savePassword {
Pixel.fire(pixel: .autofillLoginsSavePasswordModalConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsSavePasswordModalConfirmed)
} else {
Pixel.fire(pixel: .autofillLoginsSaveLoginModalConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsSaveLoginModalConfirmed)
}
delegate?.saveLoginViewController(self, didSaveCredentials: credentialManager.credentials)
case .updatePassword, .updateUsername:
Expand Down Expand Up @@ -152,17 +146,15 @@ extension SaveLoginViewController: SaveLoginViewModelDelegate {
alertController.overrideUserInterfaceStyle()

let disableAction = UIAlertAction(title: UserText.autofillKeepEnabledAlertDisableAction, style: .cancel) { _ in
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptAutofillDisabled,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptAutofillDisabled)
if isSelfPresentingAlert {
self.delegate?.saveLoginViewControllerDidCancel(self)
}
AppDependencyProvider.shared.appSettings.autofillCredentialsEnabled = false
}

let keepUsingAction = UIAlertAction(title: UserText.autofillKeepEnabledAlertKeepUsingAction, style: .default) { _ in
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptAutofillKept,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptAutofillKept)
if isSelfPresentingAlert {
self.delegate?.saveLoginViewControllerDidCancel(self)
}
Expand All @@ -176,8 +168,7 @@ extension SaveLoginViewController: SaveLoginViewModelDelegate {
if isAlreadyDismissed {
delegate?.saveLoginViewController(self, didRequestPresentConfirmKeepUsingAlertController: alertController)
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptShown,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptShown)
present(alertController, animated: true)
}
}
Expand Down
3 changes: 1 addition & 2 deletions DuckDuckGo/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ class SettingsViewController: UITableViewController {
syncDataProviders: syncDataProviders
)
autofillController.delegate = self
Pixel.fire(pixel: .autofillSettingsOpened,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillSettingsOpened)
navigationController?.pushViewController(autofillController, animated: animated)
}

Expand Down
3 changes: 1 addition & 2 deletions DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2571,8 +2571,7 @@ extension TabViewController: SaveLoginViewControllerDelegate {

func saveLoginViewController(_ viewController: SaveLoginViewController,
didRequestPresentConfirmKeepUsingAlertController alertController: UIAlertController) {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptShown,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptShown)
present(alertController, animated: true)
}
}
Expand Down
3 changes: 1 addition & 2 deletions DuckDuckGo/TabViewControllerBrowsingMenuExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ extension TabViewController {
}

private func onOpenAutofillLoginsAction() {
Pixel.fire(pixel: .browsingMenuAutofill,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
Pixel.fire(pixel: .browsingMenuAutofill)
delegate?.tabDidRequestAutofillLogins(tab: self)
}

Expand Down
Loading

0 comments on commit db29e27

Please sign in to comment.