macOS: Hide exclude private IPs when PrivateKey / PublicKey is missing
This commit is contained in:
parent
ae4a728428
commit
4629414981
|
@ -19,6 +19,7 @@ class ConfTextStorage: NSTextStorage {
|
||||||
private(set) var hasOnePeer: Bool = false
|
private(set) var hasOnePeer: Bool = false
|
||||||
private(set) var lastOnePeerAllowedIPs = [String]()
|
private(set) var lastOnePeerAllowedIPs = [String]()
|
||||||
private(set) var lastOnePeerDNSServers = [String]()
|
private(set) var lastOnePeerDNSServers = [String]()
|
||||||
|
private(set) var lastOnePeerHasPublicKey = false
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
backingStore = NSMutableAttributedString(string: "")
|
backingStore = NSMutableAttributedString(string: "")
|
||||||
|
@ -88,6 +89,7 @@ class ConfTextStorage: NSTextStorage {
|
||||||
hasOnePeer = false
|
hasOnePeer = false
|
||||||
lastOnePeerAllowedIPs = []
|
lastOnePeerAllowedIPs = []
|
||||||
lastOnePeerDNSServers = []
|
lastOnePeerDNSServers = []
|
||||||
|
lastOnePeerHasPublicKey = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func evaluateExcludePrivateIPs(highlightSpans: UnsafePointer<highlight_span>) {
|
func evaluateExcludePrivateIPs(highlightSpans: UnsafePointer<highlight_span>) {
|
||||||
|
@ -125,6 +127,8 @@ class ConfTextStorage: NSTextStorage {
|
||||||
backingStore.attributedSubstring(from: NSRange(location: nextnext.pointee.start, length: nextnext.pointee.len)).string
|
backingStore.attributedSubstring(from: NSRange(location: nextnext.pointee.start, length: nextnext.pointee.len)).string
|
||||||
}
|
}
|
||||||
lastOnePeerAllowedIPs.append(substring)
|
lastOnePeerAllowedIPs.append(substring)
|
||||||
|
} else if span.type == HighlightPublicKey {
|
||||||
|
lastOnePeerHasPublicKey = true
|
||||||
}
|
}
|
||||||
spans = spans.successor()
|
spans = spans.successor()
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ class ConfTextView: NSTextView {
|
||||||
override var string: String {
|
override var string: String {
|
||||||
didSet {
|
didSet {
|
||||||
confTextStorage.highlightSyntax()
|
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) {
|
func setConfText(_ text: String) {
|
||||||
let fullTextRange = NSRange(location: 0, length: (string as NSString).length)
|
let fullTextRange = NSRange(location: 0, length: (string as NSString).length)
|
||||||
if shouldChangeText(in: fullTextRange, replacementString: text) {
|
if shouldChangeText(in: fullTextRange, replacementString: text) {
|
||||||
|
@ -66,16 +82,7 @@ extension ConfTextView: NSTextViewDelegate {
|
||||||
|
|
||||||
func textDidChange(_ notification: Notification) {
|
func textDidChange(_ notification: Notification) {
|
||||||
confTextStorage.highlightSyntax()
|
confTextStorage.highlightSyntax()
|
||||||
if hasError != confTextStorage.hasError {
|
updateConfigData()
|
||||||
hasError = confTextStorage.hasError
|
|
||||||
}
|
|
||||||
if privateKeyString != confTextStorage.privateKeyString {
|
|
||||||
privateKeyString = confTextStorage.privateKeyString
|
|
||||||
}
|
|
||||||
let updatedSinglePeerAllowedIPs = confTextStorage.hasOnePeer && !confTextStorage.hasError ? confTextStorage.lastOnePeerAllowedIPs : nil
|
|
||||||
if singlePeerAllowedIPs != updatedSinglePeerAllowedIPs {
|
|
||||||
singlePeerAllowedIPs = updatedSinglePeerAllowedIPs
|
|
||||||
}
|
|
||||||
needsDisplay = true
|
needsDisplay = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue