diff --git a/Meshtastic/Persistence/Persistence.swift b/Meshtastic/Persistence/Persistence.swift index 9165c433..997fdbea 100644 --- a/Meshtastic/Persistence/Persistence.swift +++ b/Meshtastic/Persistence/Persistence.swift @@ -57,17 +57,14 @@ class PersistenceController { guard let url = self.container.persistentStoreDescriptions.first?.url else { return } let persistentStoreCoordinator = self.container.persistentStoreCoordinator - do { - try persistentStoreCoordinator.destroyPersistentStore(at: url, ofType: NSSQLiteStoreType, options: nil) print("💥 CoreData database truncated. All app data has been erased.") - + do { try persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil) } catch let error { print("💣 Failed to re-create CoreData database: " + error.localizedDescription) - try persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil) } } catch let error { diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 56fc496a..f0235049 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -216,7 +216,12 @@ struct Connect: View { if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.state == CBPeripheralState.connected { bleManager.disconnectPeripheral() } - PersistenceController.shared.clearDatabase() + do { + PersistenceController.shared.clearDatabase() + } catch let error { + print("💣 Failed to re-create CoreData database: " + error.localizedDescription) + } + let radio = bleManager.peripherals.first(where: { $0.peripheral.identifier.uuidString == selectedPeripherialId }) if radio != nil { bleManager.connectTo(peripheral: radio!.peripheral) diff --git a/Meshtastic/Views/Settings/Config/DeviceConfig.swift b/Meshtastic/Views/Settings/Config/DeviceConfig.swift index 5572c330..4d4c227c 100644 --- a/Meshtastic/Views/Settings/Config/DeviceConfig.swift +++ b/Meshtastic/Views/Settings/Config/DeviceConfig.swift @@ -25,6 +25,7 @@ struct DeviceConfig: View { @State var serialEnabled = true @State var debugLogEnabled = false @State var rebroadcastMode = 0 + @State var nodeInfoBroadcastSecs = 900 @State var doubleTapAsButtonPress = false @State var isManaged = false @@ -77,6 +78,15 @@ struct DeviceConfig: View { Text(RebroadcastModes(rawValue: rebroadcastMode)?.description ?? "") .foregroundColor(.gray) .font(.caption) + Picker("Node Info Broadcast Interval", selection: $nodeInfoBroadcastSecs ) { + ForEach(UpdateIntervals.allCases) { ui in + if ui.rawValue >= 3600 { + Text(ui.description) + } + } + } + .pickerStyle(DefaultPickerStyle()) + .padding(.top, 10) Toggle(isOn: $doubleTapAsButtonPress) { Label("Double Tap as Button", systemImage: "hand.tap") } @@ -206,8 +216,8 @@ struct DeviceConfig: View { dc.debugLogEnabled = debugLogEnabled dc.buttonGpio = UInt32(buttonGPIO) dc.buzzerGpio = UInt32(buzzerGPIO) - //dc.gpsEnGpio = UInt32(gpsEnGPIO) dc.rebroadcastMode = RebroadcastModes(rawValue: rebroadcastMode)?.protoEnumValue() ?? RebroadcastModes.all.protoEnumValue() + dc.nodeInfoBroadcastSecs = UInt32(nodeInfoBroadcastSecs) dc.doubleTapAsButtonPress = doubleTapAsButtonPress dc.isManaged = isManaged let adminMessageId = bleManager.saveDeviceConfig(config: dc, fromUser: connectedNode!.user!, toUser: node!.user!, adminIndex: connectedNode?.myInfo?.adminIndex ?? 0) @@ -275,6 +285,11 @@ struct DeviceConfig: View { if newRebroadcastMode != node!.deviceConfig!.rebroadcastMode { hasChanges = true } } } + .onChange(of: nodeInfoBroadcastSecs) { newNodeInfoBroadcastSecs in + if node != nil && node?.deviceConfig != nil { + if newNodeInfoBroadcastSecs != node!.deviceConfig!.nodeInfoBroadcastSecs { hasChanges = true } + } + } .onChange(of: doubleTapAsButtonPress) { newDoubleTapAsButtonPress in if node != nil && node?.deviceConfig != nil { if newDoubleTapAsButtonPress != node!.deviceConfig!.doubleTapAsButtonPress { hasChanges = true } @@ -293,6 +308,7 @@ struct DeviceConfig: View { self.buttonGPIO = Int(node?.deviceConfig?.buttonGpio ?? 0) self.buzzerGPIO = Int(node?.deviceConfig?.buzzerGpio ?? 0) self.rebroadcastMode = Int(node?.deviceConfig?.rebroadcastMode ?? 0) + self.nodeInfoBroadcastSecs = Int(node?.deviceConfig?.nodeInfoBroadcastSecs ?? 900) self.doubleTapAsButtonPress = node?.deviceConfig?.doubleTapAsButtonPress ?? false self.isManaged = node?.deviceConfig?.isManaged ?? false self.hasChanges = false diff --git a/Meshtastic/Views/Settings/Config/PositionConfig.swift b/Meshtastic/Views/Settings/Config/PositionConfig.swift index dfbfb9c2..674f994d 100644 --- a/Meshtastic/Views/Settings/Config/PositionConfig.swift +++ b/Meshtastic/Views/Settings/Config/PositionConfig.swift @@ -108,7 +108,9 @@ struct PositionConfig: View { Picker("Position Broadcast Interval", selection: $positionBroadcastSeconds) { ForEach(UpdateIntervals.allCases) { at in - Text(at.description) + if at.rawValue >= 900 { + Text(at.description) + } } } .pickerStyle(DefaultPickerStyle())