Skip to content

Commit

Permalink
Adapt to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Nov 6, 2024
1 parent 8e4aa02 commit 12c1e27
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 99 deletions.
14 changes: 8 additions & 6 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2913,12 +2913,12 @@
C1F142DC2CB93AED003DA518 /* FreemiumDBPPromotionViewCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1F142DA2CB93AED003DA518 /* FreemiumDBPPromotionViewCoordinatorTests.swift */; };
CB24F70C29A3D9CB006DCC58 /* AppConfigurationURLProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB24F70B29A3D9CB006DCC58 /* AppConfigurationURLProvider.swift */; };
CB24F70D29A3D9CB006DCC58 /* AppConfigurationURLProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB24F70B29A3D9CB006DCC58 /* AppConfigurationURLProvider.swift */; };
CB63DECB2CDC0BBE0097986A /* PageRefreshMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB63DECA2CDC0BB80097986A /* PageRefreshMonitor.swift */; };
CB63DECC2CDC0BBE0097986A /* PageRefreshMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB63DECA2CDC0BB80097986A /* PageRefreshMonitor.swift */; };
CB6BCDF927C6BEFF00CC76DC /* PrivacyFeatures.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB6BCDF827C6BEFF00CC76DC /* PrivacyFeatures.swift */; };
CBC83E3629B63D380008E19C /* Configuration in Frameworks */ = {isa = PBXBuildFile; productRef = CBC83E3529B63D380008E19C /* Configuration */; };
CBDD5DE329A67F2700832877 /* MockConfigurationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBDD5DE229A67F2700832877 /* MockConfigurationStore.swift */; };
CBDD5DE429A6800300832877 /* MockConfigurationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBDD5DE229A67F2700832877 /* MockConfigurationStore.swift */; };
CBECDB7D2CD98274005B8B87 /* PageRefreshEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBECDB7C2CD9826E005B8B87 /* PageRefreshEvent.swift */; };
CBECDB7E2CD98274005B8B87 /* PageRefreshEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBECDB7C2CD9826E005B8B87 /* PageRefreshEvent.swift */; };
CBECDB802CD9829A005B8B87 /* PageRefreshStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBECDB7F2CD98296005B8B87 /* PageRefreshStore.swift */; };
CBECDB812CD9829A005B8B87 /* PageRefreshStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBECDB7F2CD98296005B8B87 /* PageRefreshStore.swift */; };
CBECDB842CDA813C005B8B87 /* BrokenSitePromptLimiterStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBECDB832CDA8137005B8B87 /* BrokenSitePromptLimiterStore.swift */; };
Expand Down Expand Up @@ -4766,9 +4766,10 @@
C1E961EE2B87AA29001760E1 /* AutofillActionBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutofillActionBuilder.swift; sourceTree = "<group>"; };
C1F142DA2CB93AED003DA518 /* FreemiumDBPPromotionViewCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FreemiumDBPPromotionViewCoordinatorTests.swift; sourceTree = "<group>"; };
CB24F70B29A3D9CB006DCC58 /* AppConfigurationURLProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppConfigurationURLProvider.swift; sourceTree = "<group>"; };
CB63DEC92CDBEF0A0097986A /* BrowserServicesKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = BrowserServicesKit; path = ../BrowserServicesKit; sourceTree = SOURCE_ROOT; };
CB63DECA2CDC0BB80097986A /* PageRefreshMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageRefreshMonitor.swift; sourceTree = "<group>"; };
CB6BCDF827C6BEFF00CC76DC /* PrivacyFeatures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyFeatures.swift; sourceTree = "<group>"; };
CBDD5DE229A67F2700832877 /* MockConfigurationStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockConfigurationStore.swift; sourceTree = "<group>"; };
CBECDB7C2CD9826E005B8B87 /* PageRefreshEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageRefreshEvent.swift; sourceTree = "<group>"; };
CBECDB7F2CD98296005B8B87 /* PageRefreshStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageRefreshStore.swift; sourceTree = "<group>"; };
CBECDB832CDA8137005B8B87 /* BrokenSitePromptLimiterStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrokenSitePromptLimiterStore.swift; sourceTree = "<group>"; };
CBECDB862CDACE29005B8B87 /* BrokenSitePromptLimiter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrokenSitePromptLimiter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7611,6 +7612,7 @@
AA585D75248FD31100E9A3E2 = {
isa = PBXGroup;
children = (
CB63DEC92CDBEF0A0097986A /* BrowserServicesKit */,
378B5886295CF2A4002C0CC0 /* Configuration */,
378E279C2970217400FCADA2 /* LocalPackages */,
7BB108552A43375D000AB95F /* LocalThirdParty */,
Expand Down Expand Up @@ -9457,8 +9459,8 @@
CBECDB7B2CD9824B005B8B87 /* PageRefreshMonitor */ = {
isa = PBXGroup;
children = (
CB63DECA2CDC0BB80097986A /* PageRefreshMonitor.swift */,
CBECDB7F2CD98296005B8B87 /* PageRefreshStore.swift */,
CBECDB7C2CD9826E005B8B87 /* PageRefreshEvent.swift */,
);
path = PageRefreshMonitor;
sourceTree = "<group>";
Expand Down Expand Up @@ -11202,7 +11204,6 @@
3706FB32293F65D500E42796 /* FirefoxBookmarksReader.swift in Sources */,
EE098E782C8EDE2C009EBA7F /* AutofillCredentialsImportManager.swift in Sources */,
3199AF7E2C80734A003AEBDC /* TabModal.swift in Sources */,
CBECDB7D2CD98274005B8B87 /* PageRefreshEvent.swift in Sources */,
1D39E57B2C2C0F3700757339 /* ReleaseNotesUserScript.swift in Sources */,
3706FB33293F65D500E42796 /* DeviceIdleStateDetector.swift in Sources */,
1DB67F2A2B6FEB17003DF243 /* WebViewSnapshotRenderer.swift in Sources */,
Expand Down Expand Up @@ -11767,6 +11768,7 @@
B69A14FB2B4D705D00B9417D /* BookmarkFolderPicker.swift in Sources */,
3706FC6C293F65D500E42796 /* BookmarkViewModel.swift in Sources */,
3706FC6D293F65D500E42796 /* DaxSpeech.swift in Sources */,
CB63DECC2CDC0BBE0097986A /* PageRefreshMonitor.swift in Sources */,
3706FC6E293F65D500E42796 /* DuckURLSchemeHandler.swift in Sources */,
37445F9A2A1566420029F789 /* SyncDataProviders.swift in Sources */,
3706FC6F293F65D500E42796 /* FirePopoverViewModel.swift in Sources */,
Expand Down Expand Up @@ -12598,7 +12600,6 @@
841BE93E2C6F236000E9C2B5 /* BookmarkDragDropManager.swift in Sources */,
1D39E5772C2BFD5700757339 /* ReleaseNotesTabExtension.swift in Sources */,
987799F12999993C005D8EB6 /* LegacyBookmarkStore.swift in Sources */,
CBECDB7E2CD98274005B8B87 /* PageRefreshEvent.swift in Sources */,
1D220BF82B86192200F8BBC6 /* PreferencesEmailProtectionView.swift in Sources */,
4B8AC93526B3B2FD00879451 /* NSAlert+DataImport.swift in Sources */,
AA7412BD24D2BEEE00D22FE0 /* MainWindow.swift in Sources */,
Expand Down Expand Up @@ -13226,6 +13227,7 @@
4B37EE5F2B4CFC3C00A89A61 /* HomePageRemoteMessagingStorage.swift in Sources */,
31F28C5128C8EEC500119F70 /* YoutubeOverlayUserScript.swift in Sources */,
B6ABD0CA2BC03F610000EB69 /* SecurityScopedFileURLController.swift in Sources */,
CB63DECB2CDC0BBE0097986A /* PageRefreshMonitor.swift in Sources */,
B6040856274B830F00680351 /* DictionaryExtension.swift in Sources */,
3199AF772C80734A003AEBDC /* DuckPlayerOnboardingViewController.swift in Sources */,
B684592725C93C0500DC17B6 /* Publishers.NestedObjectChanges.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
"version" : "3.0.0"
}
},
{
"identity" : "browserserviceskit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"branch" : "jacek/behavioral-toast-udpates",
"revision" : "fb48d9089083e72e44a57c53e5b5ee2b3d113cbb"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
Expand Down
4 changes: 1 addition & 3 deletions DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ public struct UserDefaultsWrapper<T> {

// PageRefreshMonitor

case didRefreshTimestamp = "pageRefreshMonitor.did-refresh-timestamp"
case didDoubleRefreshTimestamp = "pageRefreshMonitor.did-double-refresh-timestamp"
case didRefreshCounter = "pageRefreshMonitor.did-refresh-counter"
case refreshTimestamps = "pageRefreshMonitor.refresh-timestamps"

// BrokenSitePrompt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ final class NavigationBarViewController: NSViewController {

NotificationCenter.default.addObserver(self,
selector: #selector(attemptToShowBrokenSitePrompt(_:)),
name: .pageRefreshDidMatchBrokenSiteCriteria,
name: .pageRefreshMonitorDidDetectRefreshPattern,
object: nil)

UserDefaults.netP
Expand Down Expand Up @@ -551,18 +551,17 @@ final class NavigationBarViewController: NSViewController {

@objc private func attemptToShowBrokenSitePrompt(_ sender: Notification) {
guard brokenSitePromptLimiter.shouldShowToast(),
let event = sender.userInfo?[PageRefreshEvent.key] as? PageRefreshEvent,
let url = tabCollectionViewModel.selectedTabViewModel?.tab.url, !url.isDuckDuckGo,
isOnboardingFinished
else { return }
showBrokenSitePrompt(after: event)
showBrokenSitePrompt()
}

private var isOnboardingFinished: Bool {
OnboardingActionsManager.isOnboardingFinished && Application.appDelegate.onboardingStateMachine.state == .onboardingCompleted
}

private func showBrokenSitePrompt(after event: PageRefreshEvent) {
private func showBrokenSitePrompt() {
guard view.window?.isKeyWindow == true,
let privacyButton = addressBarViewController?.addressBarButtonsViewController?.privacyEntryPointButton else { return }
brokenSitePromptLimiter.didShowToast()
Expand All @@ -571,7 +570,7 @@ final class NavigationBarViewController: NSViewController {
buttonText: UserText.BrokenSitePrompt.buttonTitle,
buttonAction: {
self.brokenSitePromptLimiter.didOpenReport()
self.addressBarViewController?.addressBarButtonsViewController?.openPrivacyDashboardPopover(entryPoint: .prompt(event.rawValue))
self.addressBarViewController?.addressBarButtonsViewController?.openPrivacyDashboardPopover(entryPoint: .prompt)
PixelKit.fire(GeneralPixel.siteNotWorkingWebsiteIsBroken)
},
shouldShowCloseButton: true,
Expand Down
67 changes: 0 additions & 67 deletions DuckDuckGo/PageRefreshMonitor/PageRefreshEvent.swift

This file was deleted.

28 changes: 28 additions & 0 deletions DuckDuckGo/PageRefreshMonitor/PageRefreshMonitor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// AppPageRefreshMonitor.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 PageRefreshMonitor
import PixelKit

extension PageRefreshMonitor {

static let onDidDetectRefreshPattern: () -> Void = {
PixelKit.fire(GeneralPixel.pageRefreshThreeTimesWithin20Seconds)
}

}
10 changes: 2 additions & 8 deletions DuckDuckGo/PageRefreshMonitor/PageRefreshStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ import PageRefreshMonitor

final class PageRefreshStore: PageRefreshStoring {

@UserDefaultsWrapper(key: .didRefreshTimestamp, defaultValue: .distantPast)
var didRefreshTimestamp: Date?

@UserDefaultsWrapper(key: .didDoubleRefreshTimestamp, defaultValue: .distantPast)
var didDoubleRefreshTimestamp: Date?

@UserDefaultsWrapper(key: .didRefreshCounter, defaultValue: 0)
var didRefreshCounter: Int
@UserDefaultsWrapper(key: .refreshTimestamps, defaultValue: [])
var refreshTimestamps: [Date]

}
2 changes: 2 additions & 0 deletions DuckDuckGo/Statistics/GeneralPixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ enum GeneralPixel: PixelKitEventV2 {

// Broken site prompt

case pageRefreshThreeTimesWithin20Seconds
case siteNotWorkingShown
case siteNotWorkingWebsiteIsBroken

Expand Down Expand Up @@ -1079,6 +1080,7 @@ enum GeneralPixel: PixelKitEventV2 {
case .errorPageShownWebkitTermination: return "m_mac_errorpageshown_webkittermination"

// Broken site prompt
case .pageRefreshThreeTimesWithin20Seconds: return "m_mac_reload-three-times-within-20-seconds"
case .siteNotWorkingShown: return "m_mac_site-not-working_shown"
case .siteNotWorkingWebsiteIsBroken: return "m_mac_site-not-working_website-is-broken"
}
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protocol NewWindowPolicyDecisionMaker {
phishingState: PhishingTabStateManaging = PhishingTabStateManager(),
tabsPreferences: TabsPreferences = TabsPreferences.shared,
onboardingPixelReporter: OnboardingAddressBarReporting = OnboardingPixelReporter(),
pageRefreshMonitor: PageRefreshMonitoring = PageRefreshMonitor(eventMapping: PageRefreshEventPixelMapping(),
pageRefreshMonitor: PageRefreshMonitoring = PageRefreshMonitor(onDidDetectRefreshPattern: PageRefreshMonitor.onDidDetectRefreshPattern,
store: PageRefreshStore())
) {

Expand Down

0 comments on commit 12c1e27

Please sign in to comment.