Better os() directives

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-01-22 04:06:27 +05:30
parent e2b068af1a
commit 273ee04450
4 changed files with 21 additions and 7 deletions

View File

@ -8,8 +8,10 @@ extension FileManager {
private static var sharedFolderURL: URL? {
#if os(iOS)
let appGroupIdInfoDictionaryKey = "com.wireguard.ios.app_group_id"
#elseif os(OSX)
#elseif os(macOS)
let appGroupIdInfoDictionaryKey = "com.wireguard.macos.app_group_id"
#else
#error("Unimplemented")
#endif
guard let appGroupId = Bundle.main.object(forInfoDictionaryKey: appGroupIdInfoDictionaryKey) as? String else {
os_log("Cannot obtain app group ID from bundle", log: OSLog.default, type: .error)

View File

@ -14,9 +14,11 @@ enum ActivateOnDemandOption {
#if os(iOS)
case useOnDemandOverWiFiOrCellular
case useOnDemandOverCellularOnly
#elseif os(OSX)
#elseif os(macOS)
case useOnDemandOverWiFiOrEthernet
case useOnDemandOverEthernetOnly
#else
#error("Unimplemented")
#endif
}
@ -40,7 +42,7 @@ extension ActivateOnDemandSetting {
connectRule.interfaceTypeMatch = .cellular
disconnectRule.interfaceTypeMatch = .wiFi
rules = [connectRule, disconnectRule]
#elseif os(OSX)
#elseif os(macOS)
case .useOnDemandOverWiFiOrEthernet:
rules = [connectRule]
case .useOnDemandOverWiFiOnly:
@ -51,6 +53,8 @@ extension ActivateOnDemandSetting {
connectRule.interfaceTypeMatch = .ethernet
disconnectRule.interfaceTypeMatch = .wiFi
rules = [connectRule, disconnectRule]
#else
#error("Unimplemented")
#endif
}
tunnelProviderManager.onDemandRules = rules
@ -62,10 +66,12 @@ extension ActivateOnDemandSetting {
let otherInterfaceType: NEOnDemandRuleInterfaceType = .cellular
let useWiFiOrOtherOption: ActivateOnDemandOption = .useOnDemandOverWiFiOrCellular
let useOtherOnlyOption: ActivateOnDemandOption = .useOnDemandOverCellularOnly
#elseif os(OSX)
#elseif os(macOS)
let otherInterfaceType: NEOnDemandRuleInterfaceType = .ethernet
let useWiFiOrOtherOption: ActivateOnDemandOption = .useOnDemandOverWiFiOrEthernet
let useOtherOnlyOption: ActivateOnDemandOption = .useOnDemandOverEthernetOnly
#else
#error("Unimplemented")
#endif
let activateOnDemandOption: ActivateOnDemandOption
switch rules.count {

View File

@ -461,11 +461,13 @@ extension TunnelViewModel {
return tr("tunnelOnDemandOptionWiFiOrCellular")
case .useOnDemandOverCellularOnly:
return tr("tunnelOnDemandOptionCellularOnly")
#elseif os(OSX)
#elseif os(macOS)
case .useOnDemandOverWiFiOrEthernet:
return tr("tunnelOnDemandOptionWiFiOrEthernet")
case .useOnDemandOverEthernetOnly:
return tr("tunnelOnDemandOptionEthernetOnly")
#else
#error("Unimplemented")
#endif
}
}
@ -485,8 +487,10 @@ extension TunnelViewModel {
static func defaultActivateOnDemandOption() -> ActivateOnDemandOption {
#if os(iOS)
return .useOnDemandOverWiFiOrCellular
#elseif os(OSX)
#elseif os(macOS)
return .useOnDemandOverWiFiOrEthernet
#else
#error("Unimplemented")
#endif
}
}

View File

@ -81,8 +81,10 @@ class PacketTunnelSettingsGenerator {
if mtu == 0 {
#if os(iOS)
networkSettings.mtu = NSNumber(value: 1280)
#elseif os(OSX)
#elseif os(macOS)
networkSettings.tunnelOverheadBytes = 80
#else
#error("Unimplemented")
#endif
} else {
networkSettings.mtu = NSNumber(value: mtu)