diff --git a/PassepartoutCore/Sources/PassepartoutCore/Extensions/OnDemand+Rules.swift b/PassepartoutCore/Sources/PassepartoutCore/Extensions/OnDemand+Rules.swift index 2b329fb0..eb9a4b2d 100644 --- a/PassepartoutCore/Sources/PassepartoutCore/Extensions/OnDemand+Rules.swift +++ b/PassepartoutCore/Sources/PassepartoutCore/Extensions/OnDemand+Rules.swift @@ -26,6 +26,20 @@ import Foundation import NetworkExtension +extension NEOnDemandRuleInterfaceType { + static var compatibleEthernet: NEOnDemandRuleInterfaceType? { + #if targetEnvironment(macCatalyst) + // FIXME: Catalyst, missing enum case, try hardcoding + // https://developer.apple.com/documentation/networkextension/neondemandruleinterfacetype/ethernet + NEOnDemandRuleInterfaceType(rawValue: 1) + #elseif os(macOS) + .ethernet + #else + nil + #endif + } +} + extension Profile.OnDemand { func rules(withCustomRules: Bool) -> [NEOnDemandRule] { @@ -36,19 +50,20 @@ extension Profile.OnDemand { var rules: [NEOnDemandRule] = [] if withCustomRules { - #if os(iOS) if withMobileNetwork { let rule = policyRule rule.interfaceTypeMatch = .cellular rules.append(rule) } - #else if withEthernetNetwork { - let rule = policyRule - rule.interfaceTypeMatch = .ethernet - rules.append(rule) + if let compatibleEthernet = NEOnDemandRuleInterfaceType.compatibleEthernet { + let rule = policyRule + rule.interfaceTypeMatch = compatibleEthernet + rules.append(rule) + } else { + pp_log.warning("Unable to add rule for NEOnDemandRuleInterfaceType.ethernet (not compatible)") + } } - #endif let SSIDs = Array(withSSIDs.filter { $1 }.keys) if !SSIDs.isEmpty { let rule = policyRule diff --git a/PassepartoutCore/Sources/PassepartoutProfiles/DataModels/Profile+OnDemand.swift b/PassepartoutCore/Sources/PassepartoutProfiles/DataModels/Profile+OnDemand.swift index abe1c6db..70e6c371 100644 --- a/PassepartoutCore/Sources/PassepartoutProfiles/DataModels/Profile+OnDemand.swift +++ b/PassepartoutCore/Sources/PassepartoutProfiles/DataModels/Profile+OnDemand.swift @@ -36,11 +36,8 @@ extension Profile { } public enum OtherNetwork: String, Codable { - - @available(iOS 14, *) case mobile - @available(macOS 11, *) case ethernet } diff --git a/PassepartoutCore/Sources/PassepartoutProfiles/Extensions/OnDemand+Extensions.swift b/PassepartoutCore/Sources/PassepartoutProfiles/Extensions/OnDemand+Extensions.swift index 2392ac4c..24f933c0 100644 --- a/PassepartoutCore/Sources/PassepartoutProfiles/Extensions/OnDemand+Extensions.swift +++ b/PassepartoutCore/Sources/PassepartoutProfiles/Extensions/OnDemand+Extensions.swift @@ -24,12 +24,9 @@ // import Foundation -import NetworkExtension import PassepartoutUtils extension Profile.OnDemand { - - @available(iOS 14, *) public var withMobileNetwork: Bool { get { withOtherNetworks.contains(.mobile) @@ -43,7 +40,6 @@ extension Profile.OnDemand { } } - @available(macOS 11, *) public var withEthernetNetwork: Bool { get { withOtherNetworks.contains(.ethernet)