feat(db): introduce transactional config installation (#3209)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-09-25 20:39:26 -05:00 committed by GitHub
parent 01290278e9
commit 6c0b2c55a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 63 deletions

View file

@ -221,4 +221,11 @@ interface NodeInfoDao {
@Query("UPDATE nodes SET notes = :notes WHERE num = :num")
fun setNodeNotes(num: Int, notes: String)
@Transaction
fun installConfig(mi: MyNodeEntity, nodes: List<NodeEntity>) {
clearMyNodeInfo()
setMyNodeInfo(mi)
putAll(nodes.map { getVerifiedNodeForUpsert(it) })
}
}

View file

@ -34,7 +34,7 @@ interface MeshPrefs {
@Singleton
class MeshPrefsImpl @Inject constructor(@MeshSharedPreferences private val prefs: SharedPreferences) : MeshPrefs {
override var deviceAddress: String? by NullableStringPrefDelegate(prefs, "device_address", null)
override var deviceAddress: String? by NullableStringPrefDelegate(prefs, "device_address", NO_DEVICE_SELECTED)
override fun shouldProvideNodeLocation(nodeNum: Int?): Boolean =
prefs.getBoolean(provideLocationKey(nodeNum), false)
@ -45,3 +45,5 @@ class MeshPrefsImpl @Inject constructor(@MeshSharedPreferences private val prefs
private fun provideLocationKey(nodeNum: Int?) = "provide-location-$nodeNum"
}
private const val NO_DEVICE_SELECTED = "n"