Skip to content

Commit

Permalink
Remove SUBSCRIPTION checks
Browse files Browse the repository at this point in the history
  • Loading branch information
miasma13 committed Apr 15, 2024
1 parent 54a8efe commit 12feddd
Show file tree
Hide file tree
Showing 30 changed files with 7 additions and 185 deletions.
21 changes: 2 additions & 19 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import UserNotifications
import Lottie

import NetworkProtection

#if SUBSCRIPTION
import Subscription
#endif

@MainActor
final class AppDelegate: NSObject, NSApplicationDelegate {
Expand Down Expand Up @@ -80,12 +77,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
let bookmarksManager = LocalBookmarkManager.shared
var privacyDashboardWindow: NSWindow?

#if SUBSCRIPTION
// Needs to be lazy as indirectly depends on AppDelegate
private lazy var networkProtectionSubscriptionEventHandler = NetworkProtectionSubscriptionEventHandler()
#endif

#if DBP && SUBSCRIPTION
#if DBP
private let dataBrokerProtectionSubscriptionEventHandler = DataBrokerProtectionSubscriptionEventHandler()
#endif

Expand Down Expand Up @@ -184,13 +179,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
privacyConfigManager: AppPrivacyFeatures.shared.contentBlocking.privacyConfigurationManager
)

#if SUBSCRIPTION
#if APPSTORE || !STRIPE
SubscriptionPurchaseEnvironment.current = .appStore
#else
SubscriptionPurchaseEnvironment.current = .stripe
#endif
#endif
}

func applicationWillFinishLaunching(_ notification: Notification) {
Expand Down Expand Up @@ -253,7 +246,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

startupSync()

#if SUBSCRIPTION
let defaultEnvironment = SubscriptionPurchaseEnvironment.ServiceEnvironment.default

let currentEnvironment = UserDefaultsWrapper(key: .subscriptionEnvironment,
Expand All @@ -267,7 +259,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
_ = await accountManager.fetchEntitlements(cachePolicy: .reloadIgnoringLocalCacheData)
}
}
#endif

if [.normal, .uiTests].contains(NSApp.runType) {
stateRestorationManager.applicationDidFinishLaunching()
Expand All @@ -293,23 +284,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

UserDefaultsWrapper<Any>.clearRemovedKeys()

#if SUBSCRIPTION
networkProtectionSubscriptionEventHandler.registerForSubscriptionAccountManagerEvents()
#endif

NetworkProtectionAppEvents().applicationDidFinishLaunching()
UNUserNotificationCenter.current().delegate = self

#if DBP && SUBSCRIPTION
#if DBP
dataBrokerProtectionSubscriptionEventHandler.registerForSubscriptionAccountManagerEvents()
#endif

#if DBP
DataBrokerProtectionAppEvents().applicationDidFinishLaunching()
#endif

#if SUBSCRIPTION

#endif
}

Expand Down Expand Up @@ -551,7 +536,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}

func updateSubscriptionStatus() {
#if SUBSCRIPTION
Task {
let accountManager = AccountManager(subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs))

Expand All @@ -565,7 +549,6 @@ func updateSubscriptionStatus() {

_ = await accountManager.fetchEntitlements(cachePolicy: .reloadIgnoringLocalCacheData)
}
#endif
}

extension AppDelegate: UNUserNotificationCenterDelegate {
Expand Down
2 changes: 0 additions & 2 deletions DuckDuckGo/Application/URLEventHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,9 @@ final class URLEventHandler {
case AppLaunchCommand.showVPNLocations.launchURL:
WindowControllersManager.shared.showPreferencesTab(withSelectedPane: .vpn)
WindowControllersManager.shared.showLocationPickerSheet()
#if SUBSCRIPTION
case AppLaunchCommand.showPrivacyPro.launchURL:
WindowControllersManager.shared.showTab(with: .subscription(.subscriptionPurchase))
Pixel.fire(.privacyProOfferScreenImpression)
#endif
#if !APPSTORE && !DEBUG
case AppLaunchCommand.moveAppToApplications.launchURL:
// this should be run after NSApplication.shared is set
Expand Down
2 changes: 0 additions & 2 deletions DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,6 @@ struct UserText {
}
}

#if SUBSCRIPTION
// Key: "subscription.menu.item"
// Comment: "Title for Subscription item in the options menu"
static let subscriptionOptionsMenuItem = "Privacy Pro"
Expand All @@ -1145,5 +1144,4 @@ struct UserText {
// Key: "subscription.progress.view.completing.purchase"
// Comment: "Progress view title when completing the purchase"
static let completingPurchaseTitle = "Completing purchase..."
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#if DBP && SUBSCRIPTION
#if DBP

import Foundation
import Subscription
Expand Down
5 changes: 0 additions & 5 deletions DuckDuckGo/Menus/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ import SwiftUI
import WebKit
import Configuration
import NetworkProtection

#if SUBSCRIPTION
import Subscription
import SubscriptionUI
#endif

// swiftlint:disable:next type_body_length
@MainActor final class MainMenu: NSMenu {
Expand Down Expand Up @@ -613,7 +610,6 @@ import SubscriptionUI

NSMenuItem(title: "Trigger Fatal Error", action: #selector(MainViewController.triggerFatalError))

#if SUBSCRIPTION
let currentEnvironmentWrapper = UserDefaultsWrapper(key: .subscriptionEnvironment, defaultValue: SubscriptionPurchaseEnvironment.ServiceEnvironment.default)
let isInternalTestingWrapper = UserDefaultsWrapper(key: .subscriptionInternalTesting, defaultValue: false)

Expand All @@ -632,7 +628,6 @@ import SubscriptionUI
},
subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs)
)
#endif

NSMenuItem(title: "Logging").submenu(setupLoggingMenu())
}
Expand Down
2 changes: 0 additions & 2 deletions DuckDuckGo/NavigationBar/View/AddressBarTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,13 @@ final class AddressBarTextField: NSTextField {
}
#endif

#if SUBSCRIPTION
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)
return
}
}
#endif

self.window?.makeFirstResponder(nil)
selectedTabViewModel.tab.setUrl(providedUrl, source: .userEntered(userEnteredValue, downloadRequested: downloadRequested))
Expand Down
22 changes: 1 addition & 21 deletions DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import Combine
import Common
import BrowserServicesKit
import NetworkProtection

#if SUBSCRIPTION
import Subscription
#endif

protocol OptionsButtonMenuDelegate: AnyObject {

Expand All @@ -43,10 +40,8 @@ protocol OptionsButtonMenuDelegate: AnyObject {
#if DBP
func optionsButtonMenuRequestedDataBrokerProtection(_ menu: NSMenu)
#endif
#if SUBSCRIPTION
func optionsButtonMenuRequestedSubscriptionPurchasePage(_ menu: NSMenu)
func optionsButtonMenuRequestedIdentityTheftRestoration(_ menu: NSMenu)
#endif
}

@MainActor
Expand Down Expand Up @@ -222,15 +217,13 @@ final class MoreOptionsMenu: NSMenu {
actionDelegate?.optionsButtonMenuRequestedAppearancePreferences(self)
}

#if SUBSCRIPTION
@objc func openSubscriptionPurchasePage(_ sender: NSMenuItem) {
actionDelegate?.optionsButtonMenuRequestedSubscriptionPurchasePage(self)
}

@objc func openIdentityTheftRestoration(_ sender: NSMenuItem) {
actionDelegate?.optionsButtonMenuRequestedIdentityTheftRestoration(self)
}
#endif

@objc func findInPage(_ sender: NSMenuItem) {
tabCollectionViewModel.selectedTabViewModel?.showFindInPage()
Expand Down Expand Up @@ -289,15 +282,11 @@ final class MoreOptionsMenu: NSMenu {
private func addSubscriptionItems() {
var items: [NSMenuItem] = []

#if SUBSCRIPTION
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable && !accountManager.isUserAuthenticated {
items.append(contentsOf: makeInactiveSubscriptionItems())
} else {
items.append(contentsOf: makeActiveSubscriptionItems()) // this adds NETP and DBP only if conditionally enabled
}
#else
items.append(contentsOf: makeActiveSubscriptionItems()) // this adds NETP and DBP only if conditionally enabled
#endif

if !items.isEmpty {
items.forEach { addItem($0) }
Expand All @@ -309,17 +298,15 @@ final class MoreOptionsMenu: NSMenu {
private func makeActiveSubscriptionItems() -> [NSMenuItem] {
var items: [NSMenuItem] = []

#if SUBSCRIPTION
let subscriptionFeatureAvailability = DefaultSubscriptionFeatureAvailability()
#endif

if networkProtectionFeatureVisibility.isNetworkProtectionBetaVisible() {
let networkProtectionItem: NSMenuItem

networkProtectionItem = makeNetworkProtectionItem()

items.append(networkProtectionItem)
#if SUBSCRIPTION

if subscriptionFeatureAvailability.isFeatureAvailable && accountManager.isUserAuthenticated {
Task {
let isMenuItemEnabled: Bool
Expand All @@ -334,7 +321,6 @@ final class MoreOptionsMenu: NSMenu {
networkProtectionItem.isEnabled = isMenuItemEnabled
}
}
#endif
} else {
networkProtectionFeatureVisibility.disableForWaitlistUsers()
}
Expand All @@ -349,7 +335,6 @@ final class MoreOptionsMenu: NSMenu {
.withImage(.dbpIcon)
items.append(dataBrokerProtectionItem)

#if SUBSCRIPTION
if subscriptionFeatureAvailability.isFeatureAvailable && accountManager.isUserAuthenticated {
Task {
let isMenuItemEnabled: Bool
Expand All @@ -364,7 +349,6 @@ final class MoreOptionsMenu: NSMenu {
dataBrokerProtectionItem.isEnabled = isMenuItemEnabled
}
}
#endif

DataBrokerProtectionExternalWaitlistPixels.fire(pixel: .dataBrokerProtectionWaitlistEntryPointMenuItemDisplayed, frequency: .dailyAndCount)

Expand All @@ -373,7 +357,6 @@ final class MoreOptionsMenu: NSMenu {
}
#endif // DBP

#if SUBSCRIPTION
if accountManager.isUserAuthenticated {
let identityTheftRestorationItem = NSMenuItem(title: UserText.identityTheftRestorationOptionsMenuItem,
action: #selector(openIdentityTheftRestoration),
Expand All @@ -397,12 +380,10 @@ final class MoreOptionsMenu: NSMenu {
}
}
}
#endif

return items
}

#if SUBSCRIPTION
private func makeInactiveSubscriptionItems() -> [NSMenuItem] {
let shouldHidePrivacyProDueToNoProducts = SubscriptionPurchaseEnvironment.current == .appStore && SubscriptionPurchaseEnvironment.canPurchase == false
if shouldHidePrivacyProDueToNoProducts {
Expand All @@ -417,7 +398,6 @@ final class MoreOptionsMenu: NSMenu {

return [privacyProItem]
}
#endif

private func addPageItems() {
guard let url = tabCollectionViewModel.selectedTabViewModel?.tab.content.url else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ import BrowserServicesKit
import NetworkProtection
import NetworkProtectionIPC
import NetworkProtectionUI

#if SUBSCRIPTION
import Subscription
import SubscriptionUI
#endif

// swiftlint:disable:next type_body_length
final class NavigationBarViewController: NSViewController {
Expand Down Expand Up @@ -297,7 +294,6 @@ final class NavigationBarViewController: NSViewController {
return
}

#if SUBSCRIPTION
if DefaultSubscriptionFeatureAvailability().isFeatureAvailable {
let accountManager = AccountManager(subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs))
let networkProtectionTokenStorage = NetworkProtectionKeychainTokenStore()
Expand All @@ -307,7 +303,6 @@ final class NavigationBarViewController: NSViewController {
return
}
}
#endif

// Note: the following code is quite contrived but we're aiming to hotfix issues without mixing subscription and
// waitlist logic. This should be cleaned up once waitlist can safely be removed.
Expand Down Expand Up @@ -1051,7 +1046,6 @@ extension NavigationBarViewController: OptionsButtonMenuDelegate {
WindowControllersManager.shared.showPreferencesTab(withSelectedPane: .appearance)
}

#if SUBSCRIPTION
func optionsButtonMenuRequestedSubscriptionPurchasePage(_ menu: NSMenu) {
WindowControllersManager.shared.showTab(with: .subscription(.subscriptionPurchase))
Pixel.fire(.privacyProOfferScreenImpression)
Expand All @@ -1060,8 +1054,6 @@ extension NavigationBarViewController: OptionsButtonMenuDelegate {
func optionsButtonMenuRequestedIdentityTheftRestoration(_ menu: NSMenu) {
WindowControllersManager.shared.showTab(with: .identityTheftRestoration(.identityTheftRestoration))
}
#endif

}

// MARK: - NSPopoverDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import Foundation
import NetworkProtection
import NetworkProtectionIPC
import Common

#if SUBSCRIPTION
import Subscription
#endif

extension NetworkProtectionDeviceManager {

Expand Down Expand Up @@ -56,11 +53,7 @@ extension NetworkProtectionKeychainTokenStore {
}

convenience init(isSubscriptionEnabled: Bool) {
#if SUBSCRIPTION
let accessTokenProvider: () -> String? = { AccountManager(subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs)).accessToken }
#else
let accessTokenProvider: () -> String? = { return nil }
#endif
self.init(keychainType: .default,
errorEvents: .networkProtectionAppDebugEvents,
isSubscriptionEnabled: isSubscriptionEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import LoginItems
import NetworkProtection
import NetworkProtectionIPC
import NetworkProtectionUI

#if SUBSCRIPTION
import Subscription
#endif

protocol NetworkProtectionIPCClient {
var ipcStatusObserver: ConnectionStatusObserver { get }
Expand Down
Loading

0 comments on commit 12feddd

Please sign in to comment.