mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Allow users to enter an existing key when adding a channel
Allow the key field to be edited by a user and validate that the user supplied key is valid base64 encoded and the correct key length.
This commit is contained in:
parent
d63187ecd4
commit
12ee105106
1 changed files with 29 additions and 4 deletions
|
|
@ -25,6 +25,7 @@ struct Channels: View {
|
|||
var node: NodeInfoEntity?
|
||||
|
||||
@State var hasChanges = false
|
||||
@State var hasValidKey = false
|
||||
@State private var isPresentingEditView = false
|
||||
@State private var isPresentingSaveConfirm: Bool = false
|
||||
@State private var channelIndex: Int32 = 0
|
||||
|
|
@ -167,9 +168,33 @@ struct Channels: View {
|
|||
HStack(alignment: .top) {
|
||||
Text("Key")
|
||||
Spacer()
|
||||
Text(channelKey)
|
||||
.foregroundColor(Color.gray)
|
||||
.textSelection(.enabled)
|
||||
TextField(
|
||||
"Key",
|
||||
text: $channelKey
|
||||
)
|
||||
.disableAutocorrection(true)
|
||||
.keyboardType(.alphabet)
|
||||
.foregroundColor(Color.gray)
|
||||
.textSelection(.enabled)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 25.0)
|
||||
.stroke(
|
||||
hasValidKey ?
|
||||
Color.green :
|
||||
Color.red
|
||||
, lineWidth: 2.0)
|
||||
)
|
||||
.onChange(of: channelKey, perform: { _ in
|
||||
let tempKey = Data(base64Encoded: channelKey) ?? Data()
|
||||
if tempKey.count == channelKeySize || channelKeySize == -1{
|
||||
hasValidKey = true
|
||||
}
|
||||
else {
|
||||
hasValidKey = false
|
||||
}
|
||||
hasChanges = true
|
||||
})
|
||||
.disabled(channelKeySize <= 0)
|
||||
// TextField(
|
||||
// "",
|
||||
// text: $channelKey,
|
||||
|
|
@ -256,7 +281,7 @@ struct Channels: View {
|
|||
} label: {
|
||||
Label("save", systemImage: "square.and.arrow.down")
|
||||
}
|
||||
.disabled(bleManager.connectedPeripheral == nil || !hasChanges)
|
||||
.disabled(bleManager.connectedPeripheral == nil || !hasChanges || !hasValidKey)
|
||||
.buttonStyle(.bordered)
|
||||
.buttonBorderShape(.capsule)
|
||||
.controlSize(.large)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue