修正应用锁逻辑错误

This commit is contained in:
2026-06-17 09:53:56 +08:00
parent 4ebd1babe3
commit be613749c4
10 changed files with 227 additions and 124 deletions
@@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
@@ -162,6 +163,22 @@ class SettingsRepository(private val context: Context, private val cryptoManager
}
}
suspend fun getLastBackgroundTime(): Long {
return dataStore.data.map { it[PreferencesKeys.LAST_BACKGROUND_TIME] ?: 0L }.first()
}
suspend fun setLastBackgroundTime(time: Long) {
dataStore.edit { preferences ->
preferences[PreferencesKeys.LAST_BACKGROUND_TIME] = time
}
}
suspend fun clearLastBackgroundTime() {
dataStore.edit { preferences ->
preferences.remove(PreferencesKeys.LAST_BACKGROUND_TIME)
}
}
val isFlagSecureEnabled: Flow<Boolean> = dataStore.data.map { preferences ->
preferences[PreferencesKeys.FLAG_SECURE_ENABLED] ?: false
}
@@ -244,6 +261,7 @@ class SettingsRepository(private val context: Context, private val cryptoManager
val FAILED_ATTEMPTS = intPreferencesKey("failed_attempts")
val LOCKOUT_END_TIME = longPreferencesKey("lockout_end_time")
val APP_LOCK_TRIGGER = intPreferencesKey("app_lock_trigger")
val LAST_BACKGROUND_TIME = longPreferencesKey("last_background_time")
val THEME_MODE = intPreferencesKey("theme_mode")
val DYNAMIC_COLOR = booleanPreferencesKey("dynamic_color")
val SEED_COLOR = intPreferencesKey("seed_color")