From 592a7baac15fd68fa9ee917eab68af1920d3eb20 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Sat, 24 Feb 2024 02:03:17 +0100 Subject: [PATCH] Fix some issues with handling when the adapter is started up (#2496) Task/Issue URL: https://app.asana.com/0/0/1206634919441353/f macOS PR: https://github.com/duckduckgo/macos-browser/pull/2251 BSK PR: https://github.com/duckduckgo/BrowserServicesKit/pull/674 ## Description Fixes how we handle the event of the tunnel adapter started. More broadly, this PR tries to ensure we don't "histerically" start and stop our monitors, since that could result in a lot of noise in our metrics. --- DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 6 +++--- LocalPackages/DuckUI/Package.swift | 2 +- LocalPackages/SyncUI/Package.swift | 2 +- LocalPackages/Waitlist/Package.swift | 2 +- .../NetworkProtectionPacketTunnelProvider.swift | 14 +++++--------- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index a40314bcc0..bf9f519684 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -9908,7 +9908,7 @@ repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 110.0.0; + version = 110.0.1; }; }; C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 47aa0fc996..fc790ff80e 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -12,10 +12,10 @@ { "identity" : "browserserviceskit", "kind" : "remoteSourceControl", - "location" : "https://github.com/duckduckgo/BrowserServicesKit", + "location" : "https://github.com/DuckDuckGo/BrowserServicesKit", "state" : { - "revision" : "d56b90bd229288f681f0a3a6a325ef25e3ce5f3c", - "version" : "110.0.0" + "revision" : "483427db845410f10121cf2200f5a940c9bbf70b", + "version" : "110.0.1" } }, { diff --git a/LocalPackages/DuckUI/Package.swift b/LocalPackages/DuckUI/Package.swift index fb9d911c3d..3833fc5480 100644 --- a/LocalPackages/DuckUI/Package.swift +++ b/LocalPackages/DuckUI/Package.swift @@ -31,7 +31,7 @@ let package = Package( targets: ["DuckUI"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "110.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "110.0.1"), ], targets: [ .target( diff --git a/LocalPackages/SyncUI/Package.swift b/LocalPackages/SyncUI/Package.swift index e94aa1baa5..702ea615d2 100644 --- a/LocalPackages/SyncUI/Package.swift +++ b/LocalPackages/SyncUI/Package.swift @@ -33,7 +33,7 @@ let package = Package( ], dependencies: [ .package(path: "../DuckUI"), - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "110.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "110.0.1"), .package(url: "https://github.com/duckduckgo/DesignResourcesKit", exact: "2.0.0") ], targets: [ diff --git a/LocalPackages/Waitlist/Package.swift b/LocalPackages/Waitlist/Package.swift index 4886b2ffd4..42616e968a 100644 --- a/LocalPackages/Waitlist/Package.swift +++ b/LocalPackages/Waitlist/Package.swift @@ -15,7 +15,7 @@ let package = Package( targets: ["Waitlist", "WaitlistMocks"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "110.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "110.0.1"), .package(url: "https://github.com/duckduckgo/DesignResourcesKit", exact: "2.0.0") ], targets: [ diff --git a/PacketTunnelProvider/NetworkProtection/NetworkProtectionPacketTunnelProvider.swift b/PacketTunnelProvider/NetworkProtection/NetworkProtectionPacketTunnelProvider.swift index f127d65a7d..dc5ddd2d44 100644 --- a/PacketTunnelProvider/NetworkProtection/NetworkProtectionPacketTunnelProvider.swift +++ b/PacketTunnelProvider/NetworkProtection/NetworkProtectionPacketTunnelProvider.swift @@ -221,7 +221,6 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider { settings: settings) startMonitoringMemoryPressureEvents() observeServerChanges() - observeStatusChanges() APIRequest.Headers.setUserAgent(DefaultUserAgentManager.duckDuckGoUserAgent) } @@ -259,14 +258,11 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider { private let activationDateStore = DefaultVPNWaitlistActivationDateStore() - private func observeStatusChanges() { - connectionStatusPublisher.sink { [weak self] status in - if case .connected = status { - self?.activationDateStore.setActivationDateIfNecessary() - self?.activationDateStore.updateLastActiveDate() - } - } - .store(in: &cancellables) + public override func handleConnectionStatusChange(old: ConnectionStatus, new: ConnectionStatus) { + super.handleConnectionStatusChange(old: old, new: new) + + activationDateStore.setActivationDateIfNecessary() + activationDateStore.updateLastActiveDate() } }