Skip to content

Commit

Permalink
Move vpnFirstEnabled and networkPathChange out of VPNSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
quanganhdo committed Mar 7, 2024
1 parent 4504b14 commit 403fc9d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 66 deletions.
2 changes: 0 additions & 2 deletions Sources/NetworkProtection/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,6 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
.setRegistrationKeyValidity,
.setSelectedEnvironment,
.setShowInMenuBar,
.setVPNFirstEnabled,
.setNetworkPathChange,
.setDisableRekeying:
// Intentional no-op, as some setting changes don't require any further operation
completionHandler?(nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension UserDefaults {
}

@objc
dynamic var networkPathChange: NetworkPathChange? {
private(set) dynamic var networkPathChange: NetworkPathChange? {
get {
guard let data = data(forKey: networkPathChangeKey) else { return nil }
return try? JSONDecoder().decode(NetworkPathChange.self, from: data)
Expand All @@ -53,7 +53,8 @@ extension UserDefaults {
}
}

var networkPathChangePublisher: AnyPublisher<NetworkPathChange?, Never> {
publisher(for: \.networkPathChange).eraseToAnyPublisher()
public func updateNetworkPath(with newPath: String?) {
networkPathChange = NetworkPathChange(oldPath: networkPathChange?.newPath ?? "unknown",
newPath: newPath ?? "unknown")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension UserDefaults {
}

@objc
dynamic var vpnFirstEnabled: Date? {
public dynamic var vpnFirstEnabled: Date? {
get {
value(forKey: vpnFirstEnabledKey) as? Date
}
Expand All @@ -34,8 +34,4 @@ extension UserDefaults {
set(newValue, forKey: vpnFirstEnabledKey)
}
}

var vpnFirstEnabledPublisher: AnyPublisher<Date?, Never> {
publisher(for: \.vpnFirstEnabled).eraseToAnyPublisher()
}
}
56 changes: 0 additions & 56 deletions Sources/NetworkProtection/Settings/VPNSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public final class VPNSettings {
case setSelectedLocation(_ selectedLocation: SelectedLocation)
case setSelectedEnvironment(_ selectedEnvironment: SelectedEnvironment)
case setShowInMenuBar(_ showInMenuBar: Bool)
case setVPNFirstEnabled(_ vpnFirstEnabled: Date?)
case setNetworkPathChange(_ newPath: String?)
case setDisableRekeying(_ disableRekeying: Bool)
}

Expand Down Expand Up @@ -163,20 +161,6 @@ public final class VPNSettings {
Change.setShowInMenuBar(showInMenuBar)
}.eraseToAnyPublisher()

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

let networkPathChangePublisher = networkPathChangePublisher
.dropFirst()
.removeDuplicates()
.map { networkPathChange in
Change.setNetworkPathChange(networkPathChange?.newPath)
}.eraseToAnyPublisher()

let disableRekeyingPublisher = disableRekeyingPublisher
.dropFirst()
.removeDuplicates()
Expand All @@ -194,8 +178,6 @@ public final class VPNSettings {
locationChangePublisher,
environmentChangePublisher,
showInMenuBarPublisher,
vpnFirstEnabledPublisher,
networkPathChangePublisher,
disableRekeyingPublisher).eraseToAnyPublisher()
}()

Expand Down Expand Up @@ -242,12 +224,6 @@ public final class VPNSettings {
self.selectedEnvironment = selectedEnvironment
case .setShowInMenuBar(let showInMenuBar):
self.showInMenuBar = showInMenuBar
case .setVPNFirstEnabled(let vpnFirstEnabled):
self.vpnFirstEnabled = vpnFirstEnabled
case .setNetworkPathChange(let newPath):
self.networkPathChange = UserDefaults.NetworkPathChange(
oldPath: networkPathChange?.newPath ?? "unknown",
newPath: newPath ?? "unknown")
case .setDisableRekeying(let disableRekeying):
self.disableRekeying = disableRekeying
}
Expand Down Expand Up @@ -442,38 +418,6 @@ public final class VPNSettings {
}
}

// MARK: - First time VPN is enabled

public var vpnFirstEnabledPublisher: AnyPublisher<Date?, Never> {
defaults.vpnFirstEnabledPublisher
}

public var vpnFirstEnabled: Date? {
get {
defaults.vpnFirstEnabled
}

set {
defaults.vpnFirstEnabled = newValue
}
}

// MARK: - Network path change info

public var networkPathChangePublisher: AnyPublisher<UserDefaults.NetworkPathChange?, Never> {
defaults.networkPathChangePublisher
}

public var networkPathChange: UserDefaults.NetworkPathChange? {
get {
defaults.networkPathChange
}

set {
defaults.networkPathChange = newValue
}
}

// MARK: - Disable Rekeying

public var disableRekeyingPublisher: AnyPublisher<Bool, Never> {
Expand Down

0 comments on commit 403fc9d

Please sign in to comment.