Skip to content

Commit

Permalink
Make sure we send correct pixel in broken site report
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Nov 6, 2024
1 parent a98dedb commit 845d4cc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
3 changes: 2 additions & 1 deletion DuckDuckGo/BrokenSitePrompt/BrokenSitePromptLimiter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import BrokenSitePrompt

extension BrokenSitePromptLimiter {

static let shared: BrokenSitePromptLimiter = BrokenSitePromptLimiter(privacyConfigManager: ContentBlocking.shared.privacyConfigurationManager, store: BrokenSitePromptLimiterStore())
static let shared: BrokenSitePromptLimiter = BrokenSitePromptLimiter(privacyConfigManager: ContentBlocking.shared.privacyConfigurationManager,
store: BrokenSitePromptLimiterStore())

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Combine
import Common
import Lottie
import os.log
import PrivacyDashboard

protocol AddressBarButtonsViewControllerDelegate: AnyObject {

Expand Down Expand Up @@ -267,13 +268,13 @@ final class AddressBarButtonsViewController: NSViewController {
openPrivacyDashboardPopover()
}

func openPrivacyDashboardPopover() {
func openPrivacyDashboardPopover(entryPoint: PrivacyDashboardEntryPoint = .dashboard) {
if let permissionAuthorizationPopover, permissionAuthorizationPopover.isShown {
permissionAuthorizationPopover.close()
}
popupBlockedPopover?.close()

popovers?.togglePrivacyDashboardPopover(for: tabViewModel, from: privacyEntryPointButton)
popovers?.togglePrivacyDashboardPopover(for: tabViewModel, from: privacyEntryPointButton, entryPoint: entryPoint)
onboardingPixelReporter.trackPrivacyDashboardOpened()
}

Expand Down Expand Up @@ -385,7 +386,7 @@ final class AddressBarButtonsViewController: NSViewController {

func openPrivacyDashboard() {
guard let tabViewModel else { return }
popovers?.openPrivacyDashboard(for: tabViewModel, from: privacyEntryPointButton)
popovers?.openPrivacyDashboard(for: tabViewModel, from: privacyEntryPointButton, entryPoint: .dashboard)
}

func updateButtons() {
Expand Down
9 changes: 5 additions & 4 deletions DuckDuckGo/NavigationBar/View/NavigationBarPopovers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import NetworkProtection
import NetworkProtectionUI
import NetworkProtectionIPC
import PixelKit
import PrivacyDashboard

protocol PopoverPresenter {
func show(_ popover: NSPopover, positionedBelow view: NSView)
Expand Down Expand Up @@ -162,11 +163,11 @@ final class NavigationBarPopovers: NSObject, PopoverPresenter {
show(popover, positionedBelow: button)
}

func togglePrivacyDashboardPopover(for tabViewModel: TabViewModel?, from button: MouseOverButton) {
func togglePrivacyDashboardPopover(for tabViewModel: TabViewModel?, from button: MouseOverButton, entryPoint: PrivacyDashboardEntryPoint) {
if privacyDashboardPopover?.isShown == true {
closePrivacyDashboard()
} else if let tabViewModel {
openPrivacyDashboard(for: tabViewModel, from: button)
openPrivacyDashboard(for: tabViewModel, from: button, entryPoint: entryPoint)
}
}

Expand Down Expand Up @@ -314,10 +315,10 @@ final class NavigationBarPopovers: NSObject, PopoverPresenter {
autofillOnboardingPopover?.close()
}

func openPrivacyDashboard(for tabViewModel: TabViewModel, from button: MouseOverButton) {
func openPrivacyDashboard(for tabViewModel: TabViewModel, from button: MouseOverButton, entryPoint: PrivacyDashboardEntryPoint) {
guard closeTransientPopovers() else { return }

let popover = PrivacyDashboardPopover()
let popover = PrivacyDashboardPopover(entryPoint: entryPoint)
popover.delegate = self
self.privacyDashboardPopover = popover
self.subscribePrivacyDashboardPendingUpdates(for: popover)
Expand Down
11 changes: 7 additions & 4 deletions DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,16 @@ final class NavigationBarViewController: NSViewController {
guard brokenSitePromptLimiter.shouldShowToast(),
let event = sender.userInfo?[PageRefreshEvent.key] as? PageRefreshEvent,
let url = tabCollectionViewModel.selectedTabViewModel?.tab.url, !url.isDuckDuckGo,
OnboardingActionsManager.isOnboardingFinished,
Application.appDelegate.onboardingStateMachine.state == .onboardingCompleted
isOnboardingFinished
else { return }
showBrokenSitePrompt(after: event)
}

private func showBrokenSitePrompt(after: PageRefreshEvent) {
private var isOnboardingFinished: Bool {
OnboardingActionsManager.isOnboardingFinished && Application.appDelegate.onboardingStateMachine.state == .onboardingCompleted
}

private func showBrokenSitePrompt(after event: PageRefreshEvent) {
guard view.window?.isKeyWindow == true,
let privacyButton = addressBarViewController?.addressBarButtonsViewController?.privacyEntryPointButton else { return }
brokenSitePromptLimiter.didShowToast()
Expand All @@ -568,7 +571,7 @@ final class NavigationBarViewController: NSViewController {
buttonText: UserText.BrokenSitePrompt.buttonTitle,
buttonAction: {
self.brokenSitePromptLimiter.didOpenReport()
self.addressBarViewController?.addressBarButtonsViewController?.openPrivacyDashboardPopover()
self.addressBarViewController?.addressBarButtonsViewController?.openPrivacyDashboardPopover(entryPoint: .prompt(event.rawValue))
PixelKit.fire(GeneralPixel.siteNotWorkingWebsiteIsBroken)
},
shouldShowCloseButton: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//

import Cocoa
import PrivacyDashboard

final class PrivacyDashboardPopover: NSPopover {

Expand All @@ -35,22 +36,22 @@ final class PrivacyDashboardPopover: NSPopover {
(contentViewController as? PrivacyDashboardViewController)!
}

override init() {
init(entryPoint: PrivacyDashboardEntryPoint = .dashboard) {
super.init()
#if DEBUG
self.behavior = .semitransient
#else
self.behavior = .transient
#endif
setupContentController()
setupContentController(entryPoint: entryPoint)
}

required init?(coder: NSCoder) {
fatalError("\(Self.self): Bad initializer")
}

private func setupContentController() {
let controller = PrivacyDashboardViewController()
private func setupContentController(entryPoint: PrivacyDashboardEntryPoint) {
let controller = PrivacyDashboardViewController(entryPoint: entryPoint)
controller.sizeDelegate = self
contentViewController = controller
}
Expand Down

0 comments on commit 845d4cc

Please sign in to comment.