mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Optimize Context.dataStore
This commit is contained in:
parent
b359c0f3d3
commit
58a21d7782
@ -87,10 +87,10 @@ private var unlockedDataStore: DataStore<Preferences>? = null
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
val Context.dataStore: DataStore<Preferences>
|
||||
get() {
|
||||
val userManager = getSystemService(Context.USER_SERVICE) as UserManager
|
||||
if (userManager.isUserUnlocked) {
|
||||
// The device has been unlocked
|
||||
return unlockedDataStore ?: run {
|
||||
return unlockedDataStore ?: run {
|
||||
val userManager = getSystemService(Context.USER_SERVICE) as UserManager
|
||||
return if (userManager.isUserUnlocked) {
|
||||
// The device has been unlocked
|
||||
val newDataStore = PreferenceDataStoreFactory.create(
|
||||
corruptionHandler = null,
|
||||
migrations = listOf(),
|
||||
@ -109,18 +109,17 @@ val Context.dataStore: DataStore<Preferences>
|
||||
}
|
||||
|
||||
newDataStore
|
||||
}
|
||||
} else {
|
||||
// The device is still locked, return default data store
|
||||
|
||||
if(!DefaultDataStore.subtypesInitialized) {
|
||||
DefaultDataStore.subtypesInitialized = true
|
||||
GlobalScope.launch {
|
||||
DefaultDataStore.updateSubtypes(Subtypes.getDirectBootInitialLayouts(this@dataStore))
|
||||
} else {
|
||||
// The device is still locked, return default data store
|
||||
if (!DefaultDataStore.subtypesInitialized) {
|
||||
DefaultDataStore.subtypesInitialized = true
|
||||
GlobalScope.launch {
|
||||
DefaultDataStore.updateSubtypes(Subtypes.getDirectBootInitialLayouts(this@dataStore))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DefaultDataStore
|
||||
DefaultDataStore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user