aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-22 15:52:39 +0530
committerRoopesh Chander <roop@roopc.net>2019-03-22 16:00:45 +0530
commit0fcaf6debb610c65502ded55cde6edd90633b842 (patch)
tree552231bda2d0feb2d6b9b8f7e406c0adfddaf3bd /WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift
parentmacOS: Syntax highlighter: Swift can bridge c strings automatically (diff)
downloadwireguard-apple-0fcaf6debb610c65502ded55cde6edd90633b842.tar.xz
wireguard-apple-0fcaf6debb610c65502ded55cde6edd90633b842.zip
macOS: Hide exclude private IPs when PrivateKey / PublicKey is missing
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift27
1 files changed, 17 insertions, 10 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift b/WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift
index 2ea8f84..6016e08 100644
--- a/WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift
+++ b/WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift
@@ -14,6 +14,7 @@ class ConfTextView: NSTextView {
override var string: String {
didSet {
confTextStorage.highlightSyntax()
+ updateConfigData()
}
}
@@ -53,6 +54,21 @@ class ConfTextView: NSTextView {
}
}
+ private func updateConfigData() {
+ if hasError != confTextStorage.hasError {
+ hasError = confTextStorage.hasError
+ }
+ if privateKeyString != confTextStorage.privateKeyString {
+ privateKeyString = confTextStorage.privateKeyString
+ }
+ let hasSyntaxError = confTextStorage.hasError
+ let hasSemanticError = confTextStorage.privateKeyString == nil || !confTextStorage.lastOnePeerHasPublicKey
+ let updatedSinglePeerAllowedIPs = confTextStorage.hasOnePeer && !hasSyntaxError && !hasSemanticError ? confTextStorage.lastOnePeerAllowedIPs : nil
+ if singlePeerAllowedIPs != updatedSinglePeerAllowedIPs {
+ singlePeerAllowedIPs = updatedSinglePeerAllowedIPs
+ }
+ }
+
func setConfText(_ text: String) {
let fullTextRange = NSRange(location: 0, length: (string as NSString).length)
if shouldChangeText(in: fullTextRange, replacementString: text) {
@@ -66,16 +82,7 @@ extension ConfTextView: NSTextViewDelegate {
func textDidChange(_ notification: Notification) {
confTextStorage.highlightSyntax()
- if hasError != confTextStorage.hasError {
- hasError = confTextStorage.hasError
- }
- if privateKeyString != confTextStorage.privateKeyString {
- privateKeyString = confTextStorage.privateKeyString
- }
- let updatedSinglePeerAllowedIPs = confTextStorage.hasOnePeer && !confTextStorage.hasError ? confTextStorage.lastOnePeerAllowedIPs : nil
- if singlePeerAllowedIPs != updatedSinglePeerAllowedIPs {
- singlePeerAllowedIPs = updatedSinglePeerAllowedIPs
- }
+ updateConfigData()
needsDisplay = true
}