Skip to content

Commit

Permalink
Renames TunnelSettings to VPNSettings. Cross platform improvements to…
Browse files Browse the repository at this point in the history
… NetP
  • Loading branch information
diegoreymendez committed Nov 16, 2023
1 parent 83988d6 commit b1a9ea6
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 36 deletions.
4 changes: 3 additions & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@
6AC6DAB228804F97002723C0 /* BarsAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarsAnimator.swift; sourceTree = "<group>"; };
6AC98418288055C1005FA9CA /* BarsAnimatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarsAnimatorTests.swift; sourceTree = "<group>"; };
6FB030C7234331B400A10DB9 /* Configuration.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Configuration.xcconfig; path = Configuration/Configuration.xcconfig; sourceTree = "<group>"; };
7BD952552B061D5E00BCCB7A /* BrowserServicesKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = BrowserServicesKit; path = ../../BrowserServicesKit; sourceTree = "<group>"; };
83004E7F2193BB8200DA013C /* WKNavigationExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKNavigationExtension.swift; sourceTree = "<group>"; };
83004E832193E14C00DA013C /* UIAlertControllerExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UIAlertControllerExtension.swift; path = ../Core/UIAlertControllerExtension.swift; sourceTree = "<group>"; };
83004E852193E5ED00DA013C /* TabViewControllerBrowsingMenuExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewControllerBrowsingMenuExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3342,6 +3343,7 @@
31E69A60280F4BAD00478327 /* LocalPackages */ = {
isa = PBXGroup;
children = (
7BD952552B061D5E00BCCB7A /* BrowserServicesKit */,
85875B5F29912A2D00115F05 /* SyncUI */,
37FCAACB2993149A000E420A /* Waitlist */,
31794BFF2821DFB600F18633 /* DuckUI */,
Expand Down Expand Up @@ -9131,7 +9133,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = revision;
revision = d1784c9240204ece3349e8cd65b621876653c4d0;
revision = 299e73ed6c9dc83f2b3935c4ba5d230cbb4e5489;
};
};
C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@
"version": "3.0.0"
}
},
{
"package": "BrowserServicesKit",
"repositoryURL": "https://github.com/DuckDuckGo/BrowserServicesKit",
"state": {
"branch": null,
"revision": "d1784c9240204ece3349e8cd65b621876653c4d0",
"version": null
}
},
{
"package": "CocoaAsyncSocket",
"repositoryURL": "https://github.com/robbiehanson/CocoaAsyncSocket",
Expand Down
16 changes: 7 additions & 9 deletions DuckDuckGo/NetworkProtectionConvenienceInitialisers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ extension NetworkProtectionKeychainTokenStore {

extension NetworkProtectionCodeRedemptionCoordinator {
convenience init() {
let tunnelSettings = TunnelSettings(defaults: .networkProtectionGroupDefaults)
let settings = VPNSettings(defaults: .networkProtectionGroupDefaults)
self.init(
environment: tunnelSettings.selectedEnvironment,
environment: settings.selectedEnvironment,
tokenStore: NetworkProtectionKeychainTokenStore(),
errorEvents: .networkProtectionAppDebugEvents
)
Expand All @@ -65,32 +65,30 @@ extension NetworkProtectionCodeRedemptionCoordinator {

extension NetworkProtectionVPNNotificationsViewModel {
convenience init() {
let notificationsSettingsStore = NetworkProtectionNotificationsSettingsUserDefaultsStore(userDefaults: .networkProtectionGroupDefaults)
self.init(
notificationsAuthorization: NotificationsAuthorizationController(),
notificationsSettingsStore: notificationsSettingsStore
)
settings: VPNSettings(defaults: .networkProtectionGroupDefaults))
}
}

extension NetworkProtectionVPNSettingsViewModel {
convenience init() {
self.init(
tunnelSettings: TunnelSettings(defaults: .networkProtectionGroupDefaults)
settings: VPNSettings(defaults: .networkProtectionGroupDefaults)
)
}
}

extension NetworkProtectionVPNLocationViewModel {
convenience init() {
let tunnelSettings = TunnelSettings(defaults: .networkProtectionGroupDefaults)
let settings = VPNSettings(defaults: .networkProtectionGroupDefaults)
let locationListRepository = NetworkProtectionLocationListCompositeRepository(
environment: tunnelSettings.selectedEnvironment,
environment: settings.selectedEnvironment,
tokenStore: NetworkProtectionKeychainTokenStore()
)
self.init(
locationListRepository: locationListRepository,
tunnelSettings: TunnelSettings(defaults: .networkProtectionGroupDefaults)
settings: VPNSettings(defaults: .networkProtectionGroupDefaults)
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions DuckDuckGo/NetworkProtectionVPNLocationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ import NetworkProtection

final class NetworkProtectionVPNLocationViewModel: ObservableObject {
private let locationListRepository: NetworkProtectionLocationListRepository
private let tunnelSettings: TunnelSettings
private let settings: VPNSettings
@Published public var countryItems: [NetworkProtectionVPNCountryItemModel] = []

init(locationListRepository: NetworkProtectionLocationListRepository, tunnelSettings: TunnelSettings) {
init(locationListRepository: NetworkProtectionLocationListRepository, settings: VPNSettings) {
self.locationListRepository = locationListRepository
self.tunnelSettings = tunnelSettings
self.settings = settings
}

@MainActor
Expand All @@ -73,12 +73,12 @@ final class NetworkProtectionVPNLocationViewModel: ObservableObject {
}

func onNearestItemSelection() {
tunnelSettings.selectedLocation = .nearest
settings.selectedLocation = .nearest
}

func onCountryItemSelection(countryID: String) {
let location = NetworkProtectionSelectedLocation(country: countryID)
tunnelSettings.selectedLocation = .location(location)
settings.selectedLocation = .location(location)
}
}

Expand Down
10 changes: 5 additions & 5 deletions DuckDuckGo/NetworkProtectionVPNNotificationsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ enum NetworkProtectionNotificationsViewKind: Equatable {

final class NetworkProtectionVPNNotificationsViewModel: ObservableObject {
private var notificationsAuthorization: NotificationsAuthorizationControlling
private var notificationsSettingsStore: NetworkProtectionNotificationsSettingsStore
private var settings: VPNSettings
@Published var viewKind: NetworkProtectionNotificationsViewKind = .loading
var alertsEnabled: Bool {
self.notificationsSettingsStore.alertsEnabled
self.settings.notifyStatusChanges
}

init(notificationsAuthorization: NotificationsAuthorizationControlling,
notificationsSettingsStore: NetworkProtectionNotificationsSettingsStore) {
settings: VPNSettings) {
self.notificationsAuthorization = notificationsAuthorization
self.notificationsSettingsStore = notificationsSettingsStore
self.settings = settings
self.notificationsAuthorization.delegate = self
}

Expand All @@ -55,7 +55,7 @@ final class NetworkProtectionVPNNotificationsViewModel: ObservableObject {
}

func didToggleAlerts(to enabled: Bool) {
notificationsSettingsStore.alertsEnabled = enabled
settings.notifyStatusChanges = enabled
}

private func updateViewKind(for authorizationStatus: UNAuthorizationStatus) {
Expand Down
8 changes: 4 additions & 4 deletions DuckDuckGo/NetworkProtectionVPNSettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import NetworkProtection
import Combine

final class NetworkProtectionVPNSettingsViewModel: ObservableObject {
private let tunnelSettings: TunnelSettings
private let settings: VPNSettings
private var cancellable: AnyCancellable?

@Published public var preferredLocation: String = UserText.netPPreferredLocationNearest

init(tunnelSettings: TunnelSettings) {
self.tunnelSettings = tunnelSettings
cancellable = tunnelSettings.selectedLocationPublisher.map { selectedLocation in
init(settings: VPNSettings) {
self.settings = settings
cancellable = settings.selectedLocationPublisher.map { selectedLocation in
guard let selectedLocation = selectedLocation.location else {
return UserText.netPPreferredLocationNearest
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
errorEvents: nil)
let errorStore = NetworkProtectionTunnelErrorStore()
let notificationsPresenter = NetworkProtectionUNNotificationPresenter()
let notificationsSettingsStore = NetworkProtectionNotificationsSettingsUserDefaultsStore(userDefaults: .networkProtectionGroupDefaults)
let settings = VPNSettings(defaults: .networkProtectionGroupDefaults)
let nofificationsPresenterDecorator = NetworkProtectionNotificationsPresenterTogglableDecorator(
notificationSettingsStore: notificationsSettingsStore,
settings: settings,
wrappee: notificationsPresenter
)
notificationsPresenter.requestAuthorization()
Expand All @@ -189,7 +189,7 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
tokenStore: tokenStore,
debugEvents: Self.networkProtectionDebugEvents(controllerErrorStore: errorStore),
providerEvents: Self.packetTunnelProviderEvents,
tunnelSettings: TunnelSettings(defaults: .networkProtectionGroupDefaults))
settings: settings)
startMonitoringMemoryPressureEvents()
observeServerChanges()
APIRequest.Headers.setUserAgent(DefaultUserAgentManager.duckDuckGoUserAgent)
Expand Down

0 comments on commit b1a9ea6

Please sign in to comment.