mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 03:32:38 +08:00
fix: reset appInfoCache (#543)
This commit is contained in:
parent
fbf32d7859
commit
951e3971c9
|
@ -9,9 +9,11 @@ import li.songe.gkd.data.RawSubscription
|
|||
import li.songe.gkd.data.SubsItem
|
||||
import li.songe.gkd.db.DbSet
|
||||
import li.songe.gkd.service.updateLauncherAppId
|
||||
import li.songe.gkd.util.appInfoCacheFlow
|
||||
import li.songe.gkd.util.authActionFlow
|
||||
import li.songe.gkd.util.checkUpdate
|
||||
import li.songe.gkd.util.initFolder
|
||||
import li.songe.gkd.util.initOrResetAppInfoCache
|
||||
import li.songe.gkd.util.launchTry
|
||||
import li.songe.gkd.util.logZipDir
|
||||
import li.songe.gkd.util.newVersionApkDir
|
||||
|
@ -28,6 +30,13 @@ class MainViewModel : ViewModel() {
|
|||
// 每次打开页面更新记录桌面 appId
|
||||
updateLauncherAppId()
|
||||
|
||||
// https://github.com/gkd-kit/gkd/issues/543
|
||||
viewModelScope.launchTry(Dispatchers.IO) {
|
||||
if (appInfoCacheFlow.value.size < 16) {
|
||||
initOrResetAppInfoCache()
|
||||
}
|
||||
}
|
||||
|
||||
val localSubsItem = SubsItem(
|
||||
id = -2, order = -2, mtime = System.currentTimeMillis()
|
||||
)
|
||||
|
|
|
@ -92,18 +92,23 @@ fun updateAppInfo(appIds: List<String>) {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun initOrResetAppInfoCache() {
|
||||
if (updateAppMutex.isLocked) return
|
||||
updateAppMutex.withLock {
|
||||
val appMap = mutableMapOf<String, AppInfo>()
|
||||
app.packageManager.getInstalledPackages(0).forEach { packageInfo ->
|
||||
val info = packageInfo.toAppInfo()
|
||||
if (info != null) {
|
||||
appMap[packageInfo.packageName] = info
|
||||
}
|
||||
}
|
||||
appInfoCacheFlow.value = appMap.toImmutableMap()
|
||||
}
|
||||
}
|
||||
|
||||
fun initAppState() {
|
||||
packageReceiver
|
||||
appScope.launchTry(Dispatchers.IO) {
|
||||
updateAppMutex.withLock {
|
||||
val appMap = mutableMapOf<String, AppInfo>()
|
||||
app.packageManager.getInstalledPackages(0).forEach { packageInfo ->
|
||||
val info = packageInfo.toAppInfo()
|
||||
if (info != null) {
|
||||
appMap[packageInfo.packageName] = info
|
||||
}
|
||||
}
|
||||
appInfoCacheFlow.value = appMap.toImmutableMap()
|
||||
}
|
||||
initOrResetAppInfoCache()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user