diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtection+ConvenienceInitializers.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtection+ConvenienceInitializers.swift index 2d57ecb38d..124e34cb37 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtection+ConvenienceInitializers.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtection+ConvenienceInitializers.swift @@ -38,16 +38,6 @@ extension NetworkProtectionDeviceManager { } } -extension NetworkProtectionCodeRedemptionCoordinator { - convenience init() { - let settings = Application.appDelegate.vpnSettings - self.init(environment: settings.selectedEnvironment, - tokenStore: NetworkProtectionKeychainTokenStore(), - errorEvents: .networkProtectionAppDebugEvents, - isSubscriptionEnabled: DefaultSubscriptionFeatureAvailability().isFeatureAvailable) - } -} - extension NetworkProtectionKeychainTokenStore { convenience init() { self.init(isSubscriptionEnabled: DefaultSubscriptionFeatureAvailability().isFeatureAvailable) diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionDebugMenu.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionDebugMenu.swift index 46710a6d96..47ac1acf82 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionDebugMenu.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionDebugMenu.swift @@ -322,9 +322,11 @@ final class NetworkProtectionDebugMenu: NSMenu { private func populateNetworkProtectionEnvironmentListMenuItems() { environmentMenu.items = [ - NSMenuItem(title: "⚠️ The environment can be set in the Subscription > Environment menu", action: nil, target: nil), - NSMenuItem(title: "Production", action: nil, target: nil, keyEquivalent: ""), - NSMenuItem(title: "Staging", action: nil, target: nil, keyEquivalent: ""), + NSMenuItem(title: "⚠️ A staging subscription can be used for the staging VPN environment, a production subscription can be used for both", action: nil, target: nil), + NSMenuItem(title: "⚠️ Please restart the browser after changing environment", action: nil, target: nil), + NSMenuItem.separator(), + NSMenuItem(title: "Production", action: #selector(setSelectedEnvironment(_:)), target: self, keyEquivalent: ""), + NSMenuItem(title: "Staging", action: #selector(setSelectedEnvironment(_:)), target: self, keyEquivalent: ""), ] } @@ -407,10 +409,10 @@ final class NetworkProtectionDebugMenu: NSMenu { private func updateEnvironmentMenu() { let selectedEnvironment = settings.selectedEnvironment - guard environmentMenu.items.count == 3 else { return } + guard environmentMenu.items.count == 5 else { return } - environmentMenu.items[1].state = selectedEnvironment == .production ? .on: .off - environmentMenu.items[2].state = selectedEnvironment == .staging ? .on: .off + environmentMenu.items[3].state = selectedEnvironment == .production ? .on : .off + environmentMenu.items[4].state = selectedEnvironment == .staging ? .on : .off } private func updatePreferredServerMenu() { @@ -481,6 +483,28 @@ final class NetworkProtectionDebugMenu: NSMenu { @objc private func toggleExcludeDDGBrowser() { transparentProxySettings.toggleExclusion(for: ddgBrowserAppIdentifier) } + + // MARK: Environment + + @objc func setSelectedEnvironment(_ menuItem: NSMenuItem) { + let title = menuItem.title + let selectedEnvironment: VPNSettings.SelectedEnvironment + + if title == "Staging" { + selectedEnvironment = .staging + } else { + selectedEnvironment = .production + } + + settings.selectedEnvironment = selectedEnvironment + + Task { + _ = try await NetworkProtectionDeviceManager.create().refreshServerList() + try? await populateNetworkProtectionServerListMenuItems() + + settings.selectedServer = .automatic + } + } } #if DEBUG diff --git a/DuckDuckGo/Subscription/VPNSettings+Environment.swift b/DuckDuckGo/Subscription/VPNSettings+Environment.swift index 4e046637ed..cffa7251a6 100644 --- a/DuckDuckGo/Subscription/VPNSettings+Environment.swift +++ b/DuckDuckGo/Subscription/VPNSettings+Environment.swift @@ -26,8 +26,10 @@ public extension VPNSettings { func alignTo(subscriptionEnvironment: SubscriptionEnvironment) { switch subscriptionEnvironment.serviceEnvironment { case .production: - self.selectedEnvironment = .production + // Do nothing for a production subscription, as it can be used for both VPN environments. + break case .staging: + // If using a staging subscription, force the staging VPN environment as it is not compatible with anything else. self.selectedEnvironment = .staging } }