From 41a4c6362a1440512a326805ddf8730c932c3b57 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 22 Dec 2018 01:55:42 +0100 Subject: [PATCH] Attempt to strongly recommend things Signed-off-by: Jason A. Donenfeld --- WireGuard/WireGuard/Base.lproj/Localizable.strings | 1 + WireGuard/WireGuard/UI/TunnelViewModel.swift | 10 ++++++---- .../ViewController/TunnelEditTableViewController.swift | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/WireGuard/WireGuard/Base.lproj/Localizable.strings b/WireGuard/WireGuard/Base.lproj/Localizable.strings index 58eb9d4..ac4a730 100644 --- a/WireGuard/WireGuard/Base.lproj/Localizable.strings +++ b/WireGuard/WireGuard/Base.lproj/Localizable.strings @@ -85,6 +85,7 @@ "tunnelEditPlaceholderTextRequired" = "Required"; "tunnelEditPlaceholderTextOptional" = "Optional"; "tunnelEditPlaceholderTextAutomatic" = "Automatic"; +"tunnelEditPlaceholderTextStronglyRecommended" = "Strongly recommended"; "tunnelEditPlaceholderTextOff" = "Off"; // Error alerts while creating / editing a tunnel configuration diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift index 0be3cb8..a981ef0 100644 --- a/WireGuard/WireGuard/UI/TunnelViewModel.swift +++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift @@ -210,6 +210,7 @@ class TunnelViewModel { // For exclude private IPs private(set) var shouldAllowExcludePrivateIPsControl = false + private(set) var shouldStronglyRecommendDNS = false private(set) var excludePrivateIPsValue = false fileprivate var numberOfPeers = 0 @@ -344,15 +345,16 @@ class TunnelViewModel { ] func updateExcludePrivateIPsFieldState() { + if scratchpad.isEmpty { + populateScratchpad() + } + let allowedIPStrings = Set(scratchpad[.allowedIPs].splitToArray(trimmingCharacters: .whitespacesAndNewlines)) + shouldStronglyRecommendDNS = allowedIPStrings.contains(TunnelViewModel.PeerData.ipv4DefaultRouteString) || allowedIPStrings.isSuperset(of: TunnelViewModel.PeerData.ipv4DefaultRouteModRFC1918String) guard numberOfPeers == 1 else { shouldAllowExcludePrivateIPsControl = false excludePrivateIPsValue = false return } - if scratchpad.isEmpty { - populateScratchpad() - } - let allowedIPStrings = Set(scratchpad[.allowedIPs].splitToArray(trimmingCharacters: .whitespacesAndNewlines)) if allowedIPStrings.contains(TunnelViewModel.PeerData.ipv4DefaultRouteString) { shouldAllowExcludePrivateIPsControl = true excludePrivateIPsValue = false diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift index 17e5130..db7db66 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift @@ -232,8 +232,11 @@ extension TunnelEditTableViewController { case .name, .privateKey: cell.placeholderText = tr("tunnelEditPlaceholderTextRequired") cell.keyboardType = .default - case .addresses, .dns: - cell.placeholderText = tr("tunnelEditPlaceholderTextOptional") + case .addresses: + cell.placeholderText = tr("tunnelEditPlaceholderTextStronglyRecommended") + cell.keyboardType = .numbersAndPunctuation + case .dns: + cell.placeholderText = tunnelViewModel.peersData.contains(where: { return $0.shouldStronglyRecommendDNS }) ? tr("tunnelEditPlaceholderTextStronglyRecommended") : tr("tunnelEditPlaceholderTextOptional") cell.keyboardType = .numbersAndPunctuation case .listenPort, .mtu: cell.placeholderText = tr("tunnelEditPlaceholderTextAutomatic")