macOS: Observe private key changes for new tunnels too
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
e1198b6e08
commit
0b2a4c2811
|
@ -105,16 +105,6 @@ class TunnelEditViewController: NSViewController {
|
||||||
textView.string = tunnelConfiguration.asWgQuickConfig()
|
textView.string = tunnelConfiguration.asWgQuickConfig()
|
||||||
publicKeyRow.value = tunnelConfiguration.interface.publicKey.base64EncodedString()
|
publicKeyRow.value = tunnelConfiguration.interface.publicKey.base64EncodedString()
|
||||||
textView.privateKeyString = tunnelConfiguration.interface.privateKey.base64EncodedString()
|
textView.privateKeyString = tunnelConfiguration.interface.privateKey.base64EncodedString()
|
||||||
textViewObservationToken = textView.observe(\.privateKeyString) { [weak publicKeyRow] textView, _ in
|
|
||||||
if let privateKeyString = textView.privateKeyString,
|
|
||||||
let privateKey = Data(base64Encoded: privateKeyString),
|
|
||||||
privateKey.count == TunnelConfiguration.keyLength {
|
|
||||||
let publicKey = Curve25519.generatePublicKey(fromPrivateKey: privateKey)
|
|
||||||
publicKeyRow?.value = publicKey.base64EncodedString()
|
|
||||||
} else {
|
|
||||||
publicKeyRow?.value = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if tunnel.activateOnDemandSetting.isActivateOnDemandEnabled {
|
if tunnel.activateOnDemandSetting.isActivateOnDemandEnabled {
|
||||||
selectedActivateOnDemandOption = tunnel.activateOnDemandSetting.activateOnDemandOption
|
selectedActivateOnDemandOption = tunnel.activateOnDemandSetting.activateOnDemandOption
|
||||||
} else {
|
} else {
|
||||||
|
@ -129,6 +119,16 @@ class TunnelEditViewController: NSViewController {
|
||||||
textView.string = bootstrappingText
|
textView.string = bootstrappingText
|
||||||
selectedActivateOnDemandOption = .none
|
selectedActivateOnDemandOption = .none
|
||||||
}
|
}
|
||||||
|
textViewObservationToken = textView.observe(\.privateKeyString) { [weak publicKeyRow] textView, _ in
|
||||||
|
if let privateKeyString = textView.privateKeyString,
|
||||||
|
let privateKey = Data(base64Encoded: privateKeyString),
|
||||||
|
privateKey.count == TunnelConfiguration.keyLength {
|
||||||
|
let publicKey = Curve25519.generatePublicKey(fromPrivateKey: privateKey)
|
||||||
|
publicKeyRow?.value = publicKey.base64EncodedString()
|
||||||
|
} else {
|
||||||
|
publicKeyRow?.value = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onDemandRow.valueOptions = activateOnDemandOptions.map { TunnelViewModel.activateOnDemandOptionText(for: $0) }
|
onDemandRow.valueOptions = activateOnDemandOptions.map { TunnelViewModel.activateOnDemandOptionText(for: $0) }
|
||||||
onDemandRow.selectedOptionIndex = activateOnDemandOptions.firstIndex(of: selectedActivateOnDemandOption)!
|
onDemandRow.selectedOptionIndex = activateOnDemandOptions.firstIndex(of: selectedActivateOnDemandOption)!
|
||||||
|
|
Loading…
Reference in New Issue