Skip to content

Commit

Permalink
Prevents VPNSettings from reporting fake changes (#614)
Browse files Browse the repository at this point in the history
Task/Issue URL:  https://app.asana.com/0/0/1206212872939261/f

iOS PR: duckduckgo/iOS#2288
macOS PR: duckduckgo/macos-browser#2004
What kind of version bump will this require?: Patch

## Description

Makes some changes to `VPNSettings` so that it won't publish fake settings updates.
  • Loading branch information
diegoreymendez authored Dec 22, 2023
1 parent 2c1c2bb commit 2dc2db9
Showing 1 changed file with 84 additions and 48 deletions.
132 changes: 84 additions & 48 deletions Sources/NetworkProtection/Settings/VPNSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class VPNSettings {
case setDisableRekeying(_ disableRekeying: Bool)
}

public enum RegistrationKeyValidity: Codable {
public enum RegistrationKeyValidity: Codable, Equatable {
case automatic
case custom(_ timeInterval: TimeInterval)
}
Expand Down Expand Up @@ -91,53 +91,89 @@ public final class VPNSettings {

private(set) public lazy var changePublisher: AnyPublisher<Change, Never> = {

let connectOnLoginPublisher = connectOnLoginPublisher.map { connectOnLogin in
Change.setConnectOnLogin(connectOnLogin)
}.eraseToAnyPublisher()

let includeAllNetworksPublisher = includeAllNetworksPublisher.map { includeAllNetworks in
Change.setIncludeAllNetworks(includeAllNetworks)
}.eraseToAnyPublisher()

let enforceRoutesPublisher = enforceRoutesPublisher.map { enforceRoutes in
Change.setEnforceRoutes(enforceRoutes)
}.eraseToAnyPublisher()

let excludeLocalNetworksPublisher = excludeLocalNetworksPublisher.map { excludeLocalNetworks in
Change.setExcludeLocalNetworks(excludeLocalNetworks)
}.eraseToAnyPublisher()

let notifyStatusChangesPublisher = notifyStatusChangesPublisher.map { notifyStatusChanges in
Change.setNotifyStatusChanges(notifyStatusChanges)
}.eraseToAnyPublisher()

let registrationKeyValidityPublisher = registrationKeyValidityPublisher.map { validity in
Change.setRegistrationKeyValidity(validity)
}.eraseToAnyPublisher()

let serverChangePublisher = selectedServerPublisher.map { server in
Change.setSelectedServer(server)
}.eraseToAnyPublisher()

let locationChangePublisher = selectedLocationPublisher.map { location in
Change.setSelectedLocation(location)
}.eraseToAnyPublisher()

let environmentChangePublisher = selectedEnvironmentPublisher.map { environment in
Change.setSelectedEnvironment(environment)
}.eraseToAnyPublisher()

let showInMenuBarPublisher = showInMenuBarPublisher.map { showInMenuBar in
Change.setShowInMenuBar(showInMenuBar)
}.eraseToAnyPublisher()

let vpnFirstEnabledPublisher = vpnFirstEnabledPublisher.map { vpnFirstEnabled in
Change.setVPNFirstEnabled(vpnFirstEnabled)
}.eraseToAnyPublisher()

let disableRekeyingPublisher = disableRekeyingPublisher.map { disableRekeying in
Change.setDisableRekeying(disableRekeying)
}.eraseToAnyPublisher()
let connectOnLoginPublisher = connectOnLoginPublisher
.dropFirst()
.removeDuplicates()
.map { connectOnLogin in
Change.setConnectOnLogin(connectOnLogin)
}.eraseToAnyPublisher()

let includeAllNetworksPublisher = includeAllNetworksPublisher
.dropFirst()
.removeDuplicates()
.map { includeAllNetworks in
Change.setIncludeAllNetworks(includeAllNetworks)
}.eraseToAnyPublisher()

let enforceRoutesPublisher = enforceRoutesPublisher
.dropFirst()
.removeDuplicates()
.map { enforceRoutes in
Change.setEnforceRoutes(enforceRoutes)
}.eraseToAnyPublisher()

let excludeLocalNetworksPublisher = excludeLocalNetworksPublisher
.dropFirst()
.removeDuplicates()
.map { excludeLocalNetworks in
Change.setExcludeLocalNetworks(excludeLocalNetworks)
}.eraseToAnyPublisher()

let notifyStatusChangesPublisher = notifyStatusChangesPublisher
.dropFirst()
.removeDuplicates()
.map { notifyStatusChanges in
Change.setNotifyStatusChanges(notifyStatusChanges)
}.eraseToAnyPublisher()

let registrationKeyValidityPublisher = registrationKeyValidityPublisher
.dropFirst()
.removeDuplicates()
.map { validity in
Change.setRegistrationKeyValidity(validity)
}.eraseToAnyPublisher()

let serverChangePublisher = selectedServerPublisher
.dropFirst()
.removeDuplicates()
.map { server in
Change.setSelectedServer(server)
}.eraseToAnyPublisher()

let locationChangePublisher = selectedLocationPublisher
.dropFirst()
.removeDuplicates()
.map { location in
Change.setSelectedLocation(location)
}.eraseToAnyPublisher()

let environmentChangePublisher = selectedEnvironmentPublisher
.dropFirst()
.removeDuplicates()
.map { environment in
Change.setSelectedEnvironment(environment)
}.eraseToAnyPublisher()

let showInMenuBarPublisher = showInMenuBarPublisher
.dropFirst()
.removeDuplicates()
.map { showInMenuBar in
Change.setShowInMenuBar(showInMenuBar)
}.eraseToAnyPublisher()

let vpnFirstEnabledPublisher = vpnFirstEnabledPublisher
.dropFirst()
.removeDuplicates()
.map { vpnFirstEnabled in
Change.setVPNFirstEnabled(vpnFirstEnabled)
}.eraseToAnyPublisher()

let disableRekeyingPublisher = disableRekeyingPublisher
.dropFirst()
.removeDuplicates()
.map { disableRekeying in
Change.setDisableRekeying(disableRekeying)
}.eraseToAnyPublisher()

return Publishers.MergeMany(
connectOnLoginPublisher,
Expand Down

0 comments on commit 2dc2db9

Please sign in to comment.