diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index a3acccb424..a7737cf420 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -14510,7 +14510,7 @@ repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 201.0.0; + version = "201.0.0-1"; }; }; 9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 51a522e596..3d5c0df68d 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/BrowserServicesKit", "state" : { - "revision" : "e5946eee6af859690cc1cc5e51daef3c8368981b", - "version" : "201.0.0" + "revision" : "9506581ae99273681073f9993fc6d881d3edaa7f", + "version" : "201.0.0-1" } }, { diff --git a/DuckDuckGo/Application/AppDelegate.swift b/DuckDuckGo/Application/AppDelegate.swift index a3ef983fee..8546ec81b1 100644 --- a/DuckDuckGo/Application/AppDelegate.swift +++ b/DuckDuckGo/Application/AppDelegate.swift @@ -96,7 +96,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate { public let subscriptionManager: SubscriptionManager public let subscriptionUIHandler: SubscriptionUIHandling - public let subscriptionCookieManager: SubscriptionCookieManaging + private let subscriptionCookieManager: SubscriptionCookieManaging + private var subscriptionCookieManagerFeatureFlagCancellable: AnyCancellable? public let vpnSettings = VPNSettings(defaults: .netP) @@ -302,6 +303,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { vpnUninstaller: vpnUninstaller) } + // swiftlint:disable:next cyclomatic_complexity func applicationDidFinishLaunching(_ notification: Notification) { guard NSApp.runType.requiresEnvironment else { return } defer { @@ -344,6 +346,30 @@ final class AppDelegate: NSObject, NSApplicationDelegate { subscriptionManager.loadInitialData() + let privacyConfigurationManager = ContentBlocking.shared.privacyConfigurationManager + + // Enable subscriptionCookieManager if feature flag is present + if privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.setAccessTokenCookieForSubscriptionDomains) { + subscriptionCookieManager.enableSettingSubscriptionCookie() + } + + // Keep track of feature flag changes + subscriptionCookieManagerFeatureFlagCancellable = privacyConfigurationManager.updatesPublisher + .sink { [weak self, weak privacyConfigurationManager] in + guard let self, let privacyConfigurationManager else { return } + + let isEnabled = privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.setAccessTokenCookieForSubscriptionDomains) + + Task { [weak self] in + if isEnabled { + self?.subscriptionCookieManager.enableSettingSubscriptionCookie() + await self?.subscriptionCookieManager.refreshSubscriptionCookie() + } else { + await self?.subscriptionCookieManager.disableSettingSubscriptionCookie() + } + } + } + if [.normal, .uiTests].contains(NSApp.runType) { stateRestorationManager.applicationDidFinishLaunching() } diff --git a/DuckDuckGo/Subscription/SubscriptionCookieManageEventPixelMapping.swift b/DuckDuckGo/Subscription/SubscriptionCookieManageEventPixelMapping.swift index c18cf2e6d4..fc5128756d 100644 --- a/DuckDuckGo/Subscription/SubscriptionCookieManageEventPixelMapping.swift +++ b/DuckDuckGo/Subscription/SubscriptionCookieManageEventPixelMapping.swift @@ -24,21 +24,18 @@ import Subscription enum SubscriptionCookieManagerPixel: PixelKitEventV2 { case missingTokenOnSignIn - case missingCookieOnSignOut - case cookieRefreshedWithUpdate - case cookieRefreshedWithDelete + case cookieRefreshedWithAccessToken + case cookieRefreshedWithEmptyValue case failedToSetSubscriptionCookie var name: String { switch self { case .missingTokenOnSignIn: return "m_mac_privacy-pro_subscription-cookie-missing_token_on_sign_in" - case .missingCookieOnSignOut: - return "m_mac_privacy-pro_subscription-cookie-missing_cookie_on_sign_out" - case .cookieRefreshedWithUpdate: - return "m_mac_privacy-pro_subscription-cookie-refreshed_with_update" - case .cookieRefreshedWithDelete: - return "m_mac_privacy-pro_subscription-cookie-refreshed_with_delete" + case .cookieRefreshedWithAccessToken: + return "m_mac_privacy-pro_subscription-cookie-refreshed_with_access_token" + case .cookieRefreshedWithEmptyValue: + return "m_mac_privacy-pro_subscription-cookie-refreshed_with_empty_value" case .failedToSetSubscriptionCookie: return "m_mac_privacy-pro_subscription-cookie-failed_to_set_subscription_cookie" } @@ -61,12 +58,10 @@ public final class SubscriptionCookieManageEventPixelMapping: EventMapping