@@ -24,8 +24,8 @@ struct MQTTConfig: View {
2424 @State var username = " "
2525 @State var password = " "
2626 @State var encryptionEnabled = true
27- @State var jsonEnabled = false
2827 @State var tlsEnabled = false
28+ @State private var showPassword = false
2929 @State var root = " msh "
3030 @State var selectedTopic = " "
3131 @State var mqttConnected : Bool = false
@@ -83,14 +83,6 @@ struct MQTTConfig: View {
8383 Label ( " Encryption Enabled " , systemImage: " lock.icloud " )
8484 }
8585 . tint ( . accentColor)
86-
87- if !proxyToClientEnabled {
88- Toggle ( isOn: $jsonEnabled) {
89- Label ( " JSON Enabled " , systemImage: " ellipsis.curlybraces " )
90- Text ( " JSON mode is a limited, unencrypted MQTT output for locally integrating with home assistant " )
91- }
92- . tint ( . accentColor)
93- }
9486 }
9587
9688 Section ( header: Text ( " Map Report " ) ) {
@@ -213,19 +205,30 @@ struct MQTTConfig: View {
213205 . keyboardType ( . default)
214206 HStack {
215207 Label ( " Password " , systemImage: " wallet.pass " )
216- TextField ( " Password " , text: $password)
217- . foregroundColor ( . gray)
218- . autocapitalization ( . none)
219- . disableAutocorrection ( true )
220- . onChange ( of: password) {
221- var totalBytes = password. utf8. count
222- // Only mess with the value if it is too big
223- while totalBytes > 31 {
224- password = String ( password. dropLast ( ) )
225- totalBytes = password. utf8. count
226- }
208+ Group {
209+ if showPassword {
210+ TextField ( " Password " , text: $password)
211+ } else {
212+ SecureField ( " Password " , text: $password)
227213 }
228- . foregroundColor ( . gray)
214+ }
215+ . foregroundColor ( . gray)
216+ . autocapitalization ( . none)
217+ . disableAutocorrection ( true )
218+ . onChange ( of: password) {
219+ var totalBytes = password. utf8. count
220+ while totalBytes > 31 {
221+ password = String ( password. dropLast ( ) )
222+ totalBytes = password. utf8. count
223+ }
224+ }
225+ Button {
226+ showPassword. toggle ( )
227+ } label: {
228+ Image ( systemName: showPassword ? " eye.slash " : " eye " )
229+ . foregroundColor ( . secondary)
230+ }
231+ . buttonStyle ( . plain)
229232 }
230233 . keyboardType ( . default)
231234 . listRowSeparator ( /*@START_MENU_TOKEN@*/. visible/*@END_MENU_TOKEN@*/)
@@ -270,7 +273,6 @@ struct MQTTConfig: View {
270273 mqtt. password = self . password
271274 mqtt. root = self . root
272275 mqtt. encryptionEnabled = self . encryptionEnabled
273- mqtt. jsonEnabled = self . jsonEnabled
274276 mqtt. tlsEnabled = self . tlsEnabled
275277 mqtt. mapReportingEnabled = self . mapReportingEnabled
276278 mqtt. mapReportSettings. shouldReportLocation = UserDefaults . mapReportingOptIn
@@ -284,9 +286,6 @@ struct MQTTConfig: View {
284286 if oldEnabled != newEnabled && newEnabled != node? . mqttConfig? . enabled { hasChanges = true }
285287 }
286288 . onChange ( of: proxyToClientEnabled) { oldProxy, newProxyToClientEnabled in
287- if newProxyToClientEnabled {
288- jsonEnabled = false
289- }
290289 if oldProxy != newProxyToClientEnabled && newProxyToClientEnabled != node? . mqttConfig? . proxyToClientEnabled { hasChanges = true }
291290 }
292291 . onChange ( of: address) { oldAddress, newAddress in
@@ -317,12 +316,6 @@ struct MQTTConfig: View {
317316 . onChange ( of: encryptionEnabled) { oldEncryption, newEncryptionEnabled in
318317 if oldEncryption != newEncryptionEnabled && newEncryptionEnabled != node? . mqttConfig? . encryptionEnabled { hasChanges = true }
319318 }
320- . onChange ( of: jsonEnabled) { oldJson, newJsonEnabled in
321- if newJsonEnabled {
322- proxyToClientEnabled = false
323- }
324- if oldJson != newJsonEnabled && newJsonEnabled != node? . mqttConfig? . jsonEnabled { hasChanges = true }
325- }
326319 . onChange ( of: tlsEnabled) { oldTls, newTlsEnabled in
327320 if defaultServer && accessoryManager. checkIsVersionSupported ( forVersion: " 2.7.3 " ) {
328321 tlsEnabled = true
@@ -363,10 +356,14 @@ struct MQTTConfig: View {
363356 request: accessoryManager. requestMqttModuleConfig
364357 )
365358 }
359+ . onChange ( of: accessoryManager. mqttProxyConnected) { _, connected in
360+ mqttConnected = connected
361+ }
366362 }
367-
363+ }
364+
365+ private extension MQTTConfig {
368366 func setMqttValues( ) {
369-
370367 nearbyTopics = [ ]
371368 let geocoder = CLGeocoder ( )
372369 if LocationsHandler . shared. locationsArray. count > 0 {
@@ -377,69 +374,45 @@ struct MQTTConfig: View {
377374 Logger . services. error ( " Failed to reverse geocode location: \( error. localizedDescription, privacy: . public) " )
378375 return
379376 }
380-
381377 if let placemarks = placemarks, let placemark = placemarks. first {
382- /// Country Topic unless your region is a country
383378 if !( region? . isCountry ?? false ) {
384379 let countryTopic = defaultTopic + " / " + ( placemark. isoCountryCode ?? " " )
385- if !countryTopic. isEmpty {
386- nearbyTopics. append ( countryTopic)
387- }
380+ if !countryTopic. isEmpty { nearbyTopics. append ( countryTopic) }
388381 }
389382 let stateTopic = defaultTopic + " / " + ( placemark. administrativeArea ?? " " )
390- if !stateTopic. isEmpty {
391- nearbyTopics. append ( stateTopic)
392- }
383+ if !stateTopic. isEmpty { nearbyTopics. append ( stateTopic) }
393384 let countyTopic = defaultTopic + " / " + ( placemark. administrativeArea ?? " " ) + " / " + ( placemark. subAdministrativeArea? . lowercased ( ) . replacingOccurrences ( of: " " , with: " " ) ?? " " )
394- if !countyTopic. isEmpty {
395- nearbyTopics. append ( countyTopic)
396- }
385+ if !countyTopic. isEmpty { nearbyTopics. append ( countyTopic) }
397386 let cityTopic = defaultTopic + " / " + ( placemark. administrativeArea ?? " " ) + " / " + ( placemark. locality? . lowercased ( ) . replacingOccurrences ( of: " " , with: " " ) ?? " " )
398- if !cityTopic. isEmpty {
399- nearbyTopics. append ( cityTopic)
400- }
401- let neightborhoodTopic = defaultTopic + " / " + ( placemark. administrativeArea ?? " " ) + " / " + ( placemark. subLocality? . lowercased ( )
387+ if !cityTopic. isEmpty { nearbyTopics. append ( cityTopic) }
388+ let neighborhoodTopic = defaultTopic + " / " + ( placemark. administrativeArea ?? " " ) + " / " + ( placemark. subLocality? . lowercased ( )
402389 . replacingOccurrences ( of: " " , with: " " )
403390 . replacingOccurrences ( of: " ' " , with: " " ) ?? " " )
404- if !neightborhoodTopic. isEmpty {
405- nearbyTopics. append ( neightborhoodTopic)
406- }
391+ if !neighborhoodTopic. isEmpty { nearbyTopics. append ( neighborhoodTopic) }
407392 } else {
408393 Logger . services. debug ( " No Location " )
409394 }
410395 } )
411396 }
412-
413397 self . enabled = node? . mqttConfig? . enabled ?? false
414398 self . proxyToClientEnabled = node? . mqttConfig? . proxyToClientEnabled ?? false
415399 self . address = node? . mqttConfig? . address ?? " "
416- if address. lowercased ( ) . contains ( " mqtt.meshtastic.org " ) {
417- defaultServer = true
418- } else {
419- defaultServer = false
420- }
400+ defaultServer = address. lowercased ( ) . contains ( " mqtt.meshtastic.org " )
421401 self . username = node? . mqttConfig? . username ?? " "
422402 self . password = node? . mqttConfig? . password ?? " "
423403 self . root = node? . mqttConfig? . root ?? " msh "
424404 self . encryptionEnabled = node? . mqttConfig? . encryptionEnabled ?? false
425- self . jsonEnabled = node? . mqttConfig? . jsonEnabled ?? false
426405 if defaultServer && accessoryManager. checkIsVersionSupported ( forVersion: " 2.7.3 " ) {
427406 self . tlsEnabled = true
428407 } else {
429408 self . tlsEnabled = node? . mqttConfig? . tlsEnabled ?? false
430409 }
431410 self . mqttConnected = accessoryManager. mqttProxyConnected
432411 self . mapReportingEnabled = node? . mqttConfig? . mapReportingEnabled ?? false
433- if node? . mqttConfig? . mapPublishIntervalSecs ?? 0 < 3600 {
434- self . mapPublishIntervalSecs = UpdateInterval ( from: 3600 )
435- } else {
436- self . mapPublishIntervalSecs = UpdateInterval ( from: Int ( node? . mqttConfig? . mapPublishIntervalSecs ?? 3600 ) )
437- }
412+ self . mapPublishIntervalSecs = UpdateInterval ( from: max ( 3600 , Int ( node? . mqttConfig? . mapPublishIntervalSecs ?? 3600 ) ) )
438413 self . mapPositionPrecision = Double ( node? . mqttConfig? . mapPositionPrecision ?? 14 )
439414 self . mapReportingOptIn = UserDefaults . mapReportingOptIn
440- if mapPositionPrecision < 11 || mapPositionPrecision > 14 {
441- self . mapPositionPrecision = 14
442- }
415+ if mapPositionPrecision < 11 || mapPositionPrecision > 14 { self . mapPositionPrecision = 14 }
443416 self . hasChanges = false
444417 }
445418}
0 commit comments