Observe confirmed Bluetooth preferences from the application owner

This commit is contained in:
evgeny committed 2026-10-29 13:51:58 +01:00
1 parent 1651d1b870
commit ae4f524448
2 files changed
+13 -2

No files matched your search

@@ -111,7 +111,14 @@ class ChatApplication : Application() {
/* One-time event callback registration — survives ViewModel recreation */
NativeLib.setEventCallback(AppEventHandler)
com.utun.chat.data.BleRadio.init()
try { com.utun.chat.data.BleRadio.init() }
catch (e: Exception) { LogManager.addLog("ERROR", "discovery", "BLE initialization failed: $e") }
applicationScope.launch {
configProvider.changes.observe("Bluetooth", configProvider.bluetoothSettings).collect { flags ->
try { com.utun.chat.data.BleRadio.applySettings(flags) }
catch (e: Exception) { LogManager.addLog("ERROR", "discovery", "BLE preference application failed flags=$flags: $e") }
}
}
/* Incoming-call system effects (wake + ringtone + notification) — app-scoped */
IncomingCallManager.init()
@@ -45,7 +45,11 @@ class ConfigProvider(private val context: Context) {
val changes = SettingsOperations()
private val configFiles = ConfigFileStore { level, message -> LogManager.addLog(level, "CFG", message) }
private val bleFlags = intPreferencesKey("bluetooth_flags")
fun getBleFlags(): Int = runBlocking { context.dataStore.data.first()[bleFlags] ?: 0 }
val bluetoothSettings: Flow<Int> = context.dataStore.data.map { preferences ->
val flags = preferences[bleFlags] ?: 0
if (flags !in 0..7) LogManager.addLog("WARN", "discovery", "Invalid stored BLE flags=$flags; disabling Bluetooth")
flags.takeIf { it in 0..7 } ?: 0
}.distinctUntilChanged()
suspend fun setBleFlags(flags: Int) {
require(flags in 0..7)
context.dataStore.edit { it[bleFlags] = flags }