Skip to content

Commit

Permalink
Add desktop-specific RMF matching attributes (#2954)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/72649045549333/1207774753650441/f

Description:
This change adds support for 5 new desktop-specific matching attributes:
installedMacAppStore, pinnedTabs, customHomePage, duckPlayerOnboarded and duckPlayerEnabled.
  • Loading branch information
ayoy authored Jul 12, 2024
1 parent c2ad42a commit c88f5d3
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 48 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ jobs:
run: |
# Extract failed tests from the junit report
# Only keep failures unique by classname and name (column 1 and 2 of the yq output)
yq < ${{ matrix.flavor }}.xml -p xml -o json -r \
$'[.testsuites.testsuite[].testcase] | flatten | map(select(.failure) | .+@classname + " " + .+@name + " \'" + .failure.+@message + "\' ${{ env.WORKFLOW_URL }}") | .[]' \
| sort -u -k 1,2 \
| xargs -L 1 ./scripts/report-failed-unit-test.sh
for file in "${{ matrix.flavor }}-unittests.xml" "${{ matrix.flavor }}-integrationtests.xml"; do
yq < "$file" -p xml -o json -r \
$'[.testsuites.testsuite[].testcase] | flatten | map(select(.failure) | .+@classname + " " + .+@name + " \'" + .failure.+@message + "\' ${{ env.WORKFLOW_URL }}") | .[]' \
| sort -u -k 1,2 \
| xargs -L 1 ./scripts/report-failed-unit-test.sh
done
- name: Upload failed unit tests log
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13310,7 +13310,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 170.0.0;
version = 171.0.0;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "33ceded0295158678da10d8ed685e64d3ad1a0d6",
"version" : "170.0.0"
"revision" : "9ee9b378060b94aeafba65c62e629953fec91093",
"version" : "171.0.0"
}
},
{
Expand Down Expand Up @@ -75,7 +75,7 @@
{
"identity" : "lottie-spm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/airbnb/lottie-spm.git",
"location" : "https://github.com/airbnb/lottie-spm",
"state" : {
"revision" : "1d29eccc24cc8b75bff9f6804155112c0ffc9605",
"version" : "4.4.3"
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.7">
version = "1.8">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
private let crashReporter = CrashReporter()
#endif

let pinnedTabsManager = PinnedTabsManager()
private(set) var stateRestorationManager: AppStateRestorationManager!
private var grammarFeaturesManager = GrammarFeaturesManager()
let internalUserDecider: InternalUserDecider
Expand Down Expand Up @@ -232,6 +233,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
database: RemoteMessagingDatabase().db,
bookmarksDatabase: BookmarkDatabase.shared.db,
appearancePreferences: .shared,
pinnedTabsManager: pinnedTabsManager,
internalUserDecider: internalUserDecider,
configurationStore: ConfigurationStore.shared,
remoteMessagingAvailabilityProvider: PrivacyConfigurationRemoteMessagingAvailabilityProvider(
Expand Down
16 changes: 3 additions & 13 deletions DuckDuckGo/HomePage/View/HomePageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ extension HomePage.Views {
VStack(spacing: 0) {
Group {
remoteMessage()
.padding(.top, 64)

if includingContinueSetUpCards {
ContinueSetUpView()
.padding(.top, 64)
.padding(.top, activeRemoteMessageModel.shouldShowRemoteMessage ? 18 : 64)
.visibility(model.isContinueSetUpVisible ? .visible : .gone)
}
Favorites()
Expand Down Expand Up @@ -214,15 +216,3 @@ extension HomePage.Views {
}
}
}

private extension RemoteMessageModelType {

var isSupported: Bool {
switch self {
case .promoSingleAction:
return false
default:
return true
}
}
}
1 change: 0 additions & 1 deletion DuckDuckGo/HomePage/View/RemoteMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ struct RemoteMessageView: View {
.padding(.horizontal, 16)
.padding(.vertical, 14)
}
.padding(.top, 64)
.padding(.bottom, 32)
}

Expand Down
16 changes: 8 additions & 8 deletions DuckDuckGo/Preferences/Model/StartupPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ import Foundation
import Combine

protocol StartupPreferencesPersistor {
var appearancePrefs: AppearancePreferences { get set }
var restorePreviousSession: Bool { get set }
var launchToCustomHomePage: Bool { get set }
var customHomePageURL: String { get set }
}

struct StartupPreferencesUserDefaultsPersistor: StartupPreferencesPersistor {
var appearancePrefs: AppearancePreferences

@UserDefaultsWrapper(key: .restorePreviousSession, defaultValue: false)
var restorePreviousSession: Bool

Expand All @@ -44,15 +41,18 @@ final class StartupPreferences: ObservableObject, PreferencesTabOpening {

static let shared = StartupPreferences()
private let pinningManager: LocalPinningManager
private var appearancePreferences: AppearancePreferences
private var persistor: StartupPreferencesPersistor
private var pinnedViewsNotificationCancellable: AnyCancellable?
private var dataClearingPreferences: DataClearingPreferences
private var dataClearingPreferencesNotificationCancellable: AnyCancellable?

init(pinningManager: LocalPinningManager = LocalPinningManager.shared,
persistor: StartupPreferencesPersistor = StartupPreferencesUserDefaultsPersistor(appearancePrefs: AppearancePreferences.shared),
dataClearingPreferences: DataClearingPreferences = DataClearingPreferences.shared) {
init(pinningManager: LocalPinningManager = .shared,
appearancePreferences: AppearancePreferences = .shared,
persistor: StartupPreferencesPersistor = StartupPreferencesUserDefaultsPersistor(),
dataClearingPreferences: DataClearingPreferences = .shared) {
self.pinningManager = pinningManager
self.appearancePreferences = appearancePreferences
self.persistor = persistor
self.dataClearingPreferences = dataClearingPreferences
restorePreviousSession = persistor.restorePreviousSession
Expand Down Expand Up @@ -117,7 +117,7 @@ final class StartupPreferences: ObservableObject, PreferencesTabOpening {
}

func updateHomeButton() {
persistor.appearancePrefs.homeButtonPosition = homeButtonPosition
appearancePreferences.homeButtonPosition = homeButtonPosition
if homeButtonPosition != .hidden {
pinningManager.unpin(.homeButton)
pinningManager.pin(.homeButton)
Expand All @@ -127,7 +127,7 @@ final class StartupPreferences: ObservableObject, PreferencesTabOpening {
}

private func updateHomeButtonState() {
homeButtonPosition = pinningManager.isPinned(.homeButton) ? persistor.appearancePrefs.homeButtonPosition : .hidden
homeButtonPosition = pinningManager.isPinned(.homeButton) ? appearancePreferences.homeButtonPosition : .hidden
}

private func listenToPinningManagerNotifications() {
Expand Down
16 changes: 16 additions & 0 deletions DuckDuckGo/RemoteMessaging/ActiveRemoteMessageModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,25 @@ final class ActiveRemoteMessageModel: ObservableObject {
}
}

var shouldShowRemoteMessage: Bool {
remoteMessage?.content?.isSupported == true
}

private func updateRemoteMessage() {
remoteMessage = store()?.fetchScheduledRemoteMessage()
}

private var cancellables = Set<AnyCancellable>()
}

extension RemoteMessageModelType {

var isSupported: Bool {
switch self {
case .promoSingleAction:
return false
default:
return true
}
}
}
2 changes: 2 additions & 0 deletions DuckDuckGo/RemoteMessaging/RemoteMessagingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ final class RemoteMessagingClient: RemoteMessagingProcessing {
database: CoreDataDatabase,
bookmarksDatabase: CoreDataDatabase,
appearancePreferences: AppearancePreferences,
pinnedTabsManager: PinnedTabsManager,
internalUserDecider: InternalUserDecider,
configurationStore: ConfigurationStoring,
remoteMessagingAvailabilityProvider: RemoteMessagingAvailabilityProviding,
Expand All @@ -73,6 +74,7 @@ final class RemoteMessagingClient: RemoteMessagingProcessing {
let provider = RemoteMessagingConfigMatcherProvider(
bookmarksDatabase: bookmarksDatabase,
appearancePreferences: appearancePreferences,
pinnedTabsManager: pinnedTabsManager,
internalUserDecider: internalUserDecider
)
self.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,28 @@ final class RemoteMessagingConfigMatcherProvider: RemoteMessagingConfigMatcherPr
init(
bookmarksDatabase: CoreDataDatabase,
appearancePreferences: AppearancePreferences,
startupPreferencesPersistor: @escaping @autoclosure () -> StartupPreferencesPersistor = StartupPreferencesUserDefaultsPersistor(),
duckPlayerPreferencesPersistor: @escaping @autoclosure () -> DuckPlayerPreferencesPersistor = DuckPlayerPreferencesUserDefaultsPersistor(),
pinnedTabsManager: PinnedTabsManager,
internalUserDecider: InternalUserDecider,
statisticsStore: StatisticsStore = LocalStatisticsStore(),
variantManager: VariantManager = DefaultVariantManager()
) {
self.bookmarksDatabase = bookmarksDatabase
self.appearancePreferences = appearancePreferences
self.startupPreferencesPersistor = startupPreferencesPersistor
self.duckPlayerPreferencesPersistor = duckPlayerPreferencesPersistor
self.pinnedTabsManager = pinnedTabsManager
self.internalUserDecider = internalUserDecider
self.statisticsStore = statisticsStore
self.variantManager = variantManager
}

let bookmarksDatabase: CoreDataDatabase
let appearancePreferences: AppearancePreferences
let startupPreferencesPersistor: () -> StartupPreferencesPersistor
let duckPlayerPreferencesPersistor: () -> DuckPlayerPreferencesPersistor
let pinnedTabsManager: PinnedTabsManager
let internalUserDecider: InternalUserDecider
let statisticsStore: StatisticsStore
let variantManager: VariantManager
Expand Down Expand Up @@ -116,10 +125,19 @@ final class RemoteMessagingConfigMatcherProvider: RemoteMessagingConfigMatcherPr

let dismissedMessageIds = store.fetchDismissedRemoteMessageIDs()

#if APPSTORE
let isInstalledMacAppStore = true
#else
let isInstalledMacAppStore = false
#endif

let duckPlayerPreferencesPersistor = duckPlayerPreferencesPersistor()

return RemoteMessagingConfigMatcher(
appAttributeMatcher: AppAttributeMatcher(statisticsStore: statisticsStore,
variantManager: variantManager,
isInternalUser: internalUserDecider.isInternalUser),
isInternalUser: internalUserDecider.isInternalUser,
isInstalledMacAppStore: isInstalledMacAppStore),
userAttributeMatcher: UserAttributeMatcher(statisticsStore: statisticsStore,
variantManager: variantManager,
bookmarksCount: bookmarksCount,
Expand All @@ -134,7 +152,12 @@ final class RemoteMessagingConfigMatcherProvider: RemoteMessagingConfigMatcherPr
isPrivacyProSubscriptionActive: isPrivacyProSubscriptionActive,
isPrivacyProSubscriptionExpiring: isPrivacyProSubscriptionExpiring,
isPrivacyProSubscriptionExpired: isPrivacyProSubscriptionExpired,
dismissedMessageIds: dismissedMessageIds),
dismissedMessageIds: dismissedMessageIds,
pinnedTabsCount: pinnedTabsManager.tabCollection.tabs.count,
hasCustomHomePage: startupPreferencesPersistor().launchToCustomHomePage,
isDuckPlayerOnboarded: duckPlayerPreferencesPersistor.youtubeOverlayAnyButtonPressed,
isDuckPlayerEnabled: duckPlayerPreferencesPersistor.duckPlayerModeBool != false
),
percentileStore: RemoteMessagingPercentileUserDefaultsStore(keyValueStore: UserDefaults.standard),
surveyActionMapper: surveyActionMapper,
dismissedMessageIds: dismissedMessageIds
Expand Down
8 changes: 6 additions & 2 deletions DuckDuckGo/Windows/View/WindowControllersManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ protocol WindowControllersManagerProtocol {
@MainActor
final class WindowControllersManager: WindowControllersManagerProtocol {

static let shared = WindowControllersManager()
static let shared = WindowControllersManager(pinnedTabsManager: Application.appDelegate.pinnedTabsManager)

init(pinnedTabsManager: PinnedTabsManager) {
self.pinnedTabsManager = pinnedTabsManager
}

/**
* _Initial_ meaning a single window with a single home page tab.
*/
@Published private(set) var isInInitialState: Bool = true
@Published private(set) var mainWindowControllers = [MainWindowController]()
private(set) var pinnedTabsManager = PinnedTabsManager()
private(set) var pinnedTabsManager: PinnedTabsManager

weak var lastKeyMainWindowController: MainWindowController? {
didSet {
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
targets: ["DataBrokerProtection"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "170.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "171.0.0"),
.package(path: "../SwiftUIExtensions"),
.package(path: "../XPCHelper"),
],
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let package = Package(
.library(name: "VPNAppLauncher", targets: ["VPNAppLauncher"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "170.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "171.0.0"),
.package(url: "https://github.com/airbnb/lottie-spm", exact: "4.4.3"),
.package(path: "../AppLauncher"),
.package(path: "../UDSHelper"),
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SubscriptionUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: ["SubscriptionUI"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "170.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "171.0.0"),
.package(path: "../SwiftUIExtensions")
],
targets: [
Expand Down
14 changes: 7 additions & 7 deletions UnitTests/Onboarding/OnboardingManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OnboardingManagerTests: XCTestCase {
var navigationDelegate: CapturingOnboardingNavigation!
var dockCustomization: CapturingDockCustomizer!
var defaultBrowserProvider: CapturingDefaultBrowserProvider!
var apperancePreferences: AppearancePreferences!
var appearancePreferences: AppearancePreferences!
var startupPreferences: StartupPreferences!
var appearancePersistor: MockAppearancePreferencesPersistor!
var startupPersistor: StartupPreferencesUserDefaultsPersistor!
Expand All @@ -37,18 +37,18 @@ class OnboardingManagerTests: XCTestCase {
dockCustomization = CapturingDockCustomizer()
defaultBrowserProvider = CapturingDefaultBrowserProvider()
appearancePersistor = MockAppearancePreferencesPersistor()
apperancePreferences = AppearancePreferences(persistor: appearancePersistor)
startupPersistor = StartupPreferencesUserDefaultsPersistor(appearancePrefs: apperancePreferences)
startupPreferences = StartupPreferences(persistor: startupPersistor)
manager = OnboardingActionsManager(navigationDelegate: navigationDelegate, dockCustomization: dockCustomization, defaultBrowserProvider: defaultBrowserProvider, appearancePreferences: apperancePreferences, startupPreferences: startupPreferences)
appearancePreferences = AppearancePreferences(persistor: appearancePersistor)
startupPersistor = StartupPreferencesUserDefaultsPersistor()
startupPreferences = StartupPreferences(appearancePreferences: appearancePreferences, persistor: startupPersistor)
manager = OnboardingActionsManager(navigationDelegate: navigationDelegate, dockCustomization: dockCustomization, defaultBrowserProvider: defaultBrowserProvider, appearancePreferences: appearancePreferences, startupPreferences: startupPreferences)
}

override func tearDown() {
manager = nil
navigationDelegate = nil
dockCustomization = nil
defaultBrowserProvider = nil
apperancePreferences = nil
appearancePreferences = nil
startupPreferences = nil
super.tearDown()
}
Expand Down Expand Up @@ -162,7 +162,7 @@ class OnboardingManagerTests: XCTestCase {

func testOnSetBookmarksBar_andBarIsShown_ThenBarIsShown() {
// Given
apperancePreferences.showBookmarksBar = true
appearancePreferences.showBookmarksBar = true

// When
manager.setBookmarkBar(enabled: false)
Expand Down
4 changes: 1 addition & 3 deletions UnitTests/Preferences/StartupPreferencesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ import XCTest
@testable import DuckDuckGo_Privacy_Browser

struct StartupPreferencesPersistorMock: StartupPreferencesPersistor {
var appearancePrefs: AppearancePreferences
var launchToCustomHomePage: Bool
var customHomePageURL: String
var restorePreviousSession: Bool

init(launchToCustomHomePage: Bool, customHomePageURL: String, restorePreviousSession: Bool = false, appearancePrefs: AppearancePreferences = AppearancePreferences(persistor: AppearancePreferencesPersistorMock())) {
init(launchToCustomHomePage: Bool, customHomePageURL: String, restorePreviousSession: Bool = false) {
self.customHomePageURL = customHomePageURL
self.launchToCustomHomePage = launchToCustomHomePage
self.restorePreviousSession = restorePreviousSession
self.appearancePrefs = appearancePrefs
}
}

Expand Down
1 change: 1 addition & 0 deletions UnitTests/RemoteMessaging/RemoteMessagingClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ final class RemoteMessagingClientTests: XCTestCase {
configMatcherProvider: RemoteMessagingConfigMatcherProvider(
bookmarksDatabase: bookmarksDatabase,
appearancePreferences: AppearancePreferences(persistor: AppearancePreferencesPersistorMock()),
pinnedTabsManager: PinnedTabsManager(),
internalUserDecider: InternalUserDeciderMock(),
statisticsStore: MockStatisticsStore(),
variantManager: MockVariantManager()
Expand Down

0 comments on commit c88f5d3

Please sign in to comment.