Skip to content

Commit

Permalink
Rework subscription feature availability to avodi refering appDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
miasma13 committed Mar 22, 2024
1 parent c7cf61d commit c7ff61e
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 20 deletions.
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
12 changes: 8 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 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
2 changes: 1 addition & 1 deletion DuckDuckGo/Preferences/Model/PreferencesSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct PreferencesSection: Hashable, Identifiable {
]

#if SUBSCRIPTION
if NSApp.delegateTyped.subscriptionFeatureAvailability.isFeatureAvailable {
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable {
let subscriptionPanes: [PreferencePaneIdentifier] = [.subscription]
sections.insert(.init(id: .privacyPro, panes: subscriptionPanes), at: 1)
}
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

0 comments on commit c7ff61e

Please sign in to comment.