Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how subscriptionFeatureAvailability.isFeatureAvailable is used #2489

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
let bookmarksManager = LocalBookmarkManager.shared
var privacyDashboardWindow: NSWindow?

#if SUBSCRIPTION
let subscriptionFeatureAvailability: SubscriptionFeatureAvailability
#endif

#if NETWORK_PROTECTION && SUBSCRIPTION
// Needs to be lazy as indirectly depends on AppDelegate
private lazy var networkProtectionSubscriptionEventHandler = NetworkProtectionSubscriptionEventHandler()
Expand Down Expand Up @@ -193,7 +189,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
#else
SubscriptionPurchaseEnvironment.current = .stripe
#endif
subscriptionFeatureAvailability = DefaultSubscriptionFeatureAvailability()
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/DBP/DataBrokerProtectionFeatureVisibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Foundation
import BrowserServicesKit
import Common
import DataBrokerProtection
import Subscription

protocol DataBrokerProtectionFeatureVisibility {
func isFeatureVisible() -> Bool
Expand Down Expand Up @@ -98,7 +99,7 @@ struct DefaultDataBrokerProtectionFeatureVisibility: DataBrokerProtectionFeature

func isPrivacyProEnabled() -> Bool {
#if SUBSCRIPTION
return NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable
return DefaultSubscriptionFeatureAvailability().isFeatureAvailable
#else
return false
#endif
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/NavigationBar/View/AddressBarTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Carbon.HIToolbox
import Combine
import Common
import Suggestions
import Subscription

final class AddressBarTextField: NSTextField {

Expand Down Expand Up @@ -347,7 +348,7 @@ final class AddressBarTextField: NSTextField {
#endif

#if SUBSCRIPTION
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable {
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable {
if providedUrl.isChild(of: URL.subscriptionBaseURL) || providedUrl.isChild(of: URL.identityTheftRestoration) {
self.updateValue(selectedTabViewModel: nil, addressBarString: nil) // reset
self.window?.makeFirstResponder(nil)
Expand Down
17 changes: 13 additions & 4 deletions DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ final class MoreOptionsMenu: NSMenu {
var items: [NSMenuItem] = []

#if SUBSCRIPTION
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable && !AccountManager().isUserAuthenticated {
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable && !AccountManager().isUserAuthenticated {
items.append(contentsOf: makeInactiveSubscriptionItems())
} else {
items.append(contentsOf: makeActiveSubscriptionItems()) // this adds NETP and DBP only if conditionally enabled
Expand All @@ -336,6 +336,10 @@ final class MoreOptionsMenu: NSMenu {
private func makeActiveSubscriptionItems() -> [NSMenuItem] {
var items: [NSMenuItem] = []

#if SUBSCRIPTION
let subscriptionFeatureAvailability = DefaultSubscriptionFeatureAvailability()
#endif

#if NETWORK_PROTECTION
if networkProtectionFeatureVisibility.isNetworkProtectionVisible() {
let networkProtectionItem: NSMenuItem
Expand All @@ -344,7 +348,7 @@ final class MoreOptionsMenu: NSMenu {

items.append(networkProtectionItem)
#if SUBSCRIPTION
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable && AccountManager().isUserAuthenticated {
if subscriptionFeatureAvailability.isFeatureAvailable && AccountManager().isUserAuthenticated {
Task {
let isMenuItemEnabled: Bool

Expand Down Expand Up @@ -377,7 +381,7 @@ final class MoreOptionsMenu: NSMenu {
items.append(dataBrokerProtectionItem)

#if SUBSCRIPTION
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable && AccountManager().isUserAuthenticated {
if subscriptionFeatureAvailability.isFeatureAvailable && AccountManager().isUserAuthenticated {
Task {
let isMenuItemEnabled: Bool

Expand Down Expand Up @@ -409,7 +413,7 @@ final class MoreOptionsMenu: NSMenu {
.withImage(.itrIcon)
items.append(identityTheftRestorationItem)

if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable && AccountManager().isUserAuthenticated {
if subscriptionFeatureAvailability.isFeatureAvailable && AccountManager().isUserAuthenticated {
Task {
let isMenuItemEnabled: Bool

Expand All @@ -431,6 +435,11 @@ final class MoreOptionsMenu: NSMenu {

#if SUBSCRIPTION
private func makeInactiveSubscriptionItems() -> [NSMenuItem] {
switch (SubscriptionPurchaseEnvironment.current, SubscriptionPurchaseEnvironment.canPurchase) {
case (.appStore, false): return []
default: break
}

let privacyProItem = NSMenuItem(title: UserText.subscriptionOptionsMenuItem,
action: #selector(openSubscriptionPurchasePage(_:)),
keyEquivalent: "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ final class NavigationBarViewController: NSViewController {
}

#if SUBSCRIPTION
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable {
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable {
let accountManager = AccountManager()
let networkProtectionTokenStorage = NetworkProtectionKeychainTokenStore()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extension NetworkProtectionDeviceManager {
tokenStore: tokenStore,
keyStore: keyStore,
errorEvents: .networkProtectionAppDebugEvents,
isSubscriptionEnabled: NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable)
isSubscriptionEnabled: DefaultSubscriptionFeatureAvailability().isFeatureAvailable)
}
}

Expand All @@ -47,13 +47,13 @@ extension NetworkProtectionCodeRedemptionCoordinator {
self.init(environment: settings.selectedEnvironment,
tokenStore: NetworkProtectionKeychainTokenStore(),
errorEvents: .networkProtectionAppDebugEvents,
isSubscriptionEnabled: NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable)
isSubscriptionEnabled: DefaultSubscriptionFeatureAvailability().isFeatureAvailable)
}
}

extension NetworkProtectionKeychainTokenStore {
convenience init() {
self.init(isSubscriptionEnabled: NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable)
self.init(isSubscriptionEnabled: DefaultSubscriptionFeatureAvailability().isFeatureAvailable)
}

convenience init(isSubscriptionEnabled: Bool) {
Expand Down Expand Up @@ -83,7 +83,7 @@ extension NetworkProtectionLocationListCompositeRepository {
environment: settings.selectedEnvironment,
tokenStore: NetworkProtectionKeychainTokenStore(),
errorEvents: .networkProtectionAppDebugEvents,
isSubscriptionEnabled: NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable
isSubscriptionEnabled: DefaultSubscriptionFeatureAvailability().isFeatureAvailable
)
}
}
Expand Down
10 changes: 7 additions & 3 deletions DuckDuckGo/Preferences/Model/PreferencesSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ struct PreferencesSection: Hashable, Identifiable {
]

#if SUBSCRIPTION
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable {
let subscriptionPanes: [PreferencePaneIdentifier] = [.subscription]
sections.insert(.init(id: .privacyPro, panes: subscriptionPanes), at: 1)
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable {
switch (SubscriptionPurchaseEnvironment.current, SubscriptionPurchaseEnvironment.canPurchase) {
case (.appStore, false): break
default:
let subscriptionPanes: [PreferencePaneIdentifier] = [.subscription]
sections.insert(.init(id: .privacyPro, panes: subscriptionPanes), at: 1)
}
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature {
}

func getSubscriptionOptions(params: Any, original: WKScriptMessage) async throws -> Encodable? {
guard await NSApp.delegateTyped.subscriptionFeatureAvailability.isSubscriptionPurchaseAllowed else { return SubscriptionOptions.empty }
guard DefaultSubscriptionFeatureAvailability().isSubscriptionPurchaseAllowed else { return SubscriptionOptions.empty }

if SubscriptionPurchaseEnvironment.current == .appStore {
if #available(macOS 12.0, *) {
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/Tab/UserScripts/UserScripts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Foundation
import BrowserServicesKit
import UserScript
import WebKit
import Subscription

@MainActor
final class UserScripts: UserScriptsProvider {
Expand Down Expand Up @@ -87,7 +88,7 @@ final class UserScripts: UserScriptsProvider {
}

#if SUBSCRIPTION
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable {
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable {
subscriptionPagesUserScript.registerSubfeature(delegate: SubscriptionPagesUseSubscriptionFeature())
userScripts.append(subscriptionPagesUserScript)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import AppKit
import Foundation
import Subscription

final class WaitlistThankYouPromptPresenter {

Expand Down Expand Up @@ -53,7 +54,7 @@ final class WaitlistThankYouPromptPresenter {
func presentThankYouPromptIfNecessary(in window: NSWindow) {
// Wiring this here since it's mostly useful for rolling out PrivacyPro, and should
// go away once PPro is fully rolled out.
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable {
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable {
DailyPixel.fire(pixel: .privacyProFeatureEnabled, frequency: .dailyOnly)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import Foundation
import UserNotifications
import Subscription

#if NETWORK_PROTECTION || DBP

Expand Down Expand Up @@ -82,7 +83,7 @@ struct DataBrokerProtectionWaitlistViewControllerPresenter: WaitlistViewControll

static func shouldPresentWaitlist() -> Bool {
#if SUBSCRIPTION
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable {
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable {
return false
}
#endif
Expand Down
Loading