diff --git a/core/datastore/src/main/kotlin/org/meshtastic/core/datastore/UiPreferencesDataSource.kt b/core/datastore/src/main/kotlin/org/meshtastic/core/datastore/UiPreferencesDataSource.kt index 62dace0df..6ba636743 100644 --- a/core/datastore/src/main/kotlin/org/meshtastic/core/datastore/UiPreferencesDataSource.kt +++ b/core/datastore/src/main/kotlin/org/meshtastic/core/datastore/UiPreferencesDataSource.kt @@ -48,7 +48,9 @@ class UiPreferencesDataSource @Inject constructor(private val dataStore: DataSto private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO) - val appIntroCompleted: StateFlow = dataStore.prefStateFlow(key = APP_INTRO_COMPLETED, default = false) + // Start this flow eagerly, so app intro doesn't flash (when disabled) on cold app start. + val appIntroCompleted: StateFlow = + dataStore.prefStateFlow(key = APP_INTRO_COMPLETED, default = false, started = SharingStarted.Eagerly) // Default value for AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM val theme: StateFlow = dataStore.prefStateFlow(key = THEME, default = -1) @@ -87,8 +89,11 @@ class UiPreferencesDataSource @Inject constructor(private val dataStore: DataSto dataStore.setPref(key = SHOW_IGNORED, value = value) } - private fun DataStore.prefStateFlow(key: Preferences.Key, default: T): StateFlow = - data.map { it[key] ?: default }.stateIn(scope = scope, started = SharingStarted.Lazily, initialValue = default) + private fun DataStore.prefStateFlow( + key: Preferences.Key, + default: T, + started: SharingStarted = SharingStarted.Lazily, + ): StateFlow = data.map { it[key] ?: default }.stateIn(scope = scope, started = started, initialValue = default) private fun DataStore.setPref(key: Preferences.Key, value: T) { scope.launch { edit { it[key] = value } }