From 3f9d6c3d3684d8c38e39380a16c4a95553e2aa6f Mon Sep 17 00:00:00 2001 From: Volodymyr Date: Tue, 9 Jul 2024 18:37:39 +0300 Subject: [PATCH] feat(connectivity_plus): Return multiple active types on MacOS when available --- .../PathMonitorConnectivityProvider.swift | 37 ++++++++++--------- .../macos/Runner.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- .../lib/connectivity_plus.dart | 5 +-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/connectivity_plus/connectivity_plus/darwin/Classes/PathMonitorConnectivityProvider.swift b/packages/connectivity_plus/connectivity_plus/darwin/Classes/PathMonitorConnectivityProvider.swift index d7a8252b04..33e05cdf44 100644 --- a/packages/connectivity_plus/connectivity_plus/darwin/Classes/PathMonitorConnectivityProvider.swift +++ b/packages/connectivity_plus/connectivity_plus/darwin/Classes/PathMonitorConnectivityProvider.swift @@ -11,24 +11,25 @@ public class PathMonitorConnectivityProvider: NSObject, ConnectivityProvider { private func connectivityFrom(path: NWPath) -> [ConnectivityType] { var types: [ConnectivityType] = [] - - // Check for connectivity and append to types array as necessary - if path.status == .satisfied { - if path.usesInterfaceType(.wifi) { - types.append(.wifi) - } - if path.usesInterfaceType(.cellular) { - types.append(.cellular) - } - if path.usesInterfaceType(.wiredEthernet) { - types.append(.wiredEthernet) - } - if path.usesInterfaceType(.other) { - types.append(.other) - } - } - - return types.isEmpty ? [.none] : types + + for interface in path.availableInterfaces { + switch interface.type { + case .wifi: + types.append(.wifi) + case .wiredEthernet: + types.append(.wiredEthernet) + case .cellular: + types.append(.cellular) + case .loopback: + types.append(.other) + case .other: + types.append(.other) + @unknown default: + types.append(.other) + } + } + + return types.isEmpty ? [.none] : types } public var currentConnectivityTypes: [ConnectivityType] { diff --git a/packages/connectivity_plus/connectivity_plus/example/macos/Runner.xcodeproj/project.pbxproj b/packages/connectivity_plus/connectivity_plus/example/macos/Runner.xcodeproj/project.pbxproj index eab0503a2d..1557a6c220 100644 --- a/packages/connectivity_plus/connectivity_plus/example/macos/Runner.xcodeproj/project.pbxproj +++ b/packages/connectivity_plus/connectivity_plus/example/macos/Runner.xcodeproj/project.pbxproj @@ -259,7 +259,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 331C80D4294CF70F00263BE5 = { diff --git a/packages/connectivity_plus/connectivity_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/connectivity_plus/connectivity_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index fa25347e1b..1c3684b2c8 100644 --- a/packages/connectivity_plus/connectivity_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/connectivity_plus/connectivity_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ > get onConnectivityChanged { return _platform.onConnectivityChanged.distinct((a, b) => a.equals(b)); } @@ -54,8 +54,7 @@ class Connectivity { /// Checks the connection status of the device. /// /// Do not use the result of this function to decide whether you can reliably - /// make a network request, it only gives you the radio status. Instead, listen - /// for connectivity changes via [onConnectivityChanged] stream. + /// make a network request, as it only provides network interfaces status, but not an Internet availability. /// /// The returned list is never empty. In case of no connectivity, the list contains /// a single element of [ConnectivityResult.none]. Note also that this is the only