diff --git a/DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift b/DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift index b4cbd33a49..75089832be 100644 --- a/DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift +++ b/DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift @@ -355,7 +355,7 @@ final class MoreOptionsMenu: NSMenu { isMenuItemEnabled = false } - networkProtectionItem.isHidden = !isMenuItemEnabled + networkProtectionItem.isEnabled = !isMenuItemEnabled } } #endif diff --git a/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/NetworkProtectionSubscriptionEventHandler.swift b/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/NetworkProtectionSubscriptionEventHandler.swift index 961b0db784..b1da9856d1 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/NetworkProtectionSubscriptionEventHandler.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/NetworkProtectionSubscriptionEventHandler.swift @@ -48,32 +48,47 @@ final class NetworkProtectionSubscriptionEventHandler { } private func subscribeToEntitlementChanges() { - NotificationCenter.default - .publisher(for: .entitlementsDidChange) - .receive(on: DispatchQueue.main) - .sink { [weak self] notification in - guard let self else { - return - } + Task { + switch await AccountManager().hasEntitlement(for: .networkProtection) { + case .success(let hasEntitlements): + handleEntitlementsChange(hasEntitlements: hasEntitlements) + case .failure(let error): + break + } - guard let entitlements = notification.userInfo?[UserDefaultsCacheKey.subscriptionEntitlements] as? [Entitlement] else { + NotificationCenter.default + .publisher(for: .entitlementsDidChange) + .receive(on: DispatchQueue.main) + .sink { [weak self] notification in + guard let self else { + return + } - assertionFailure("Missing entitlements are truly unexpected") - return - } + guard let entitlements = notification.userInfo?[UserDefaultsCacheKey.subscriptionEntitlements] as? [Entitlement] else { - let entitlementsExpired = !entitlements.contains { entitlement in - entitlement.product == .networkProtection - } + assertionFailure("Missing entitlements are truly unexpected") + return + } - if entitlementsExpired { - Task { - await self.networkProtectionFeatureDisabler.disable(keepAuthToken: false, uninstallSystemExtension: false) - UserDefaults.netP.networkProtectionEntitlementsExpired = true + let hasEntitlements = entitlements.contains { entitlement in + entitlement.product == .networkProtection } + + handleEntitlementsChange(hasEntitlements: hasEntitlements) } + .store(in: &cancellables) + } + } + + private func handleEntitlementsChange(hasEntitlements: Bool) { + if hasEntitlements { + UserDefaults.netP.networkProtectionEntitlementsExpired = false + } else { + Task { + await self.networkProtectionFeatureDisabler.disable(keepAuthToken: false, uninstallSystemExtension: false) + UserDefaults.netP.networkProtectionEntitlementsExpired = true } - .store(in: &cancellables) + } } func registerForSubscriptionAccountManagerEvents() {