mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Update NetworkConfig.swift
This commit is contained in:
parent
4ce4695061
commit
4ddac10171
1 changed files with 58 additions and 54 deletions
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// WiFiConfig.swift
|
||||
// NetworkConfig.swift
|
||||
// Meshtastic
|
||||
//
|
||||
// Copyright (c) Garth Vander Houwen 8/1/2022
|
||||
|
|
@ -55,64 +55,68 @@ struct NetworkConfig: View {
|
|||
.font(.callout)
|
||||
.foregroundColor(.orange)
|
||||
}
|
||||
Section(header: Text("WiFi Options (ESP32 Only)")) {
|
||||
Toggle(isOn: $wifiEnabled) {
|
||||
Label("enabled", systemImage: "wifi")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
HStack {
|
||||
Label("ssid", systemImage: "network")
|
||||
TextField("ssid", text: $wifiSsid)
|
||||
.foregroundColor(.gray)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.onChange(of: wifiSsid, perform: { _ in
|
||||
let totalBytes = wifiSsid.utf8.count
|
||||
// Only mess with the value if it is too big
|
||||
if totalBytes > 32 {
|
||||
let firstNBytes = Data(wifiSsid.utf8.prefix(32))
|
||||
if let maxBytesString = String(data: firstNBytes, encoding: String.Encoding.utf8) {
|
||||
// Set the shortName back to the last place where it was the right size
|
||||
wifiSsid = maxBytesString
|
||||
if (node != nil && node?.metadata?.hasWifi ?? false) {
|
||||
Section(header: Text("WiFi Options")) {
|
||||
Toggle(isOn: $wifiEnabled) {
|
||||
Label("enabled", systemImage: "wifi")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
HStack {
|
||||
Label("ssid", systemImage: "network")
|
||||
TextField("ssid", text: $wifiSsid)
|
||||
.foregroundColor(.gray)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.onChange(of: wifiSsid, perform: { _ in
|
||||
let totalBytes = wifiSsid.utf8.count
|
||||
// Only mess with the value if it is too big
|
||||
if totalBytes > 32 {
|
||||
let firstNBytes = Data(wifiSsid.utf8.prefix(32))
|
||||
if let maxBytesString = String(data: firstNBytes, encoding: String.Encoding.utf8) {
|
||||
// Set the shortName back to the last place where it was the right size
|
||||
wifiSsid = maxBytesString
|
||||
}
|
||||
}
|
||||
}
|
||||
hasChanges = true
|
||||
})
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
.keyboardType(.default)
|
||||
HStack {
|
||||
Label("password", systemImage: "wallet.pass")
|
||||
TextField("password", text: $wifiPsk)
|
||||
.foregroundColor(.gray)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.onChange(of: wifiPsk, perform: { _ in
|
||||
let totalBytes = wifiPsk.utf8.count
|
||||
// Only mess with the value if it is too big
|
||||
if totalBytes > 63 {
|
||||
let firstNBytes = Data(wifiPsk.utf8.prefix(63))
|
||||
if let maxBytesString = String(data: firstNBytes, encoding: String.Encoding.utf8) {
|
||||
// Set the shortName back to the last place where it was the right size
|
||||
wifiPsk = maxBytesString
|
||||
hasChanges = true
|
||||
})
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
.keyboardType(.default)
|
||||
HStack {
|
||||
Label("password", systemImage: "wallet.pass")
|
||||
TextField("password", text: $wifiPsk)
|
||||
.foregroundColor(.gray)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.onChange(of: wifiPsk, perform: { _ in
|
||||
let totalBytes = wifiPsk.utf8.count
|
||||
// Only mess with the value if it is too big
|
||||
if totalBytes > 63 {
|
||||
let firstNBytes = Data(wifiPsk.utf8.prefix(63))
|
||||
if let maxBytesString = String(data: firstNBytes, encoding: String.Encoding.utf8) {
|
||||
// Set the shortName back to the last place where it was the right size
|
||||
wifiPsk = maxBytesString
|
||||
}
|
||||
}
|
||||
}
|
||||
hasChanges = true
|
||||
})
|
||||
.foregroundColor(.gray)
|
||||
hasChanges = true
|
||||
})
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
.keyboardType(.default)
|
||||
Text("Enabling WiFi will disable the bluetooth connection to the app.")
|
||||
.font(.callout)
|
||||
}
|
||||
.keyboardType(.default)
|
||||
Text("Enabling WiFi will disable the bluetooth connection to the app.")
|
||||
.font(.callout)
|
||||
|
||||
}
|
||||
.disabled(!(node != nil && node!.myInfo?.hasWifi ?? false))
|
||||
Section(header: Text("Ethernet Options")) {
|
||||
Toggle(isOn: $ethEnabled) {
|
||||
Label("enabled", systemImage: "network")
|
||||
if (node != nil && node?.metadata?.hasEthernet ?? false) {
|
||||
Section(header: Text("Ethernet Options")) {
|
||||
Toggle(isOn: $ethEnabled) {
|
||||
Label("enabled", systemImage: "network")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
Text("Enabling Ethernet will disable the bluetooth connection to the app.")
|
||||
.font(.callout)
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
Text("Enabling Ethernet will disable the bluetooth connection to the app.")
|
||||
.font(.callout)
|
||||
}
|
||||
}
|
||||
.scrollDismissesKeyboard(.interactively)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue