mirror of
https://github.com/revanced/revanced-manager-compose
synced 2024-06-02 19:36:16 +02:00
fe95afca6c
* feat: store patched apps * fix: missing string * feat: save patch selection * feat: things * fix: fix broken query * fix: remove redundant `withContext` * fix: fix
33 lines
1.2 KiB
Kotlin
33 lines
1.2 KiB
Kotlin
package app.revanced.manager.ui.viewmodel
|
|
|
|
import android.content.pm.PackageInfo
|
|
import androidx.compose.runtime.mutableStateMapOf
|
|
import androidx.lifecycle.ViewModel
|
|
import androidx.lifecycle.viewModelScope
|
|
import app.revanced.manager.domain.repository.InstalledAppRepository
|
|
import app.revanced.manager.util.PM
|
|
import app.revanced.manager.util.collectEach
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.flow.flowOn
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.withContext
|
|
|
|
class InstalledAppsViewModel(
|
|
private val installedAppsRepository: InstalledAppRepository,
|
|
private val pm: PM
|
|
) : ViewModel() {
|
|
val apps = installedAppsRepository.getAll().flowOn(Dispatchers.IO)
|
|
|
|
val packageInfoMap = mutableStateMapOf<String, PackageInfo?>()
|
|
|
|
init {
|
|
viewModelScope.launch {
|
|
apps.collectEach { installedApp ->
|
|
packageInfoMap[installedApp.currentPackageName] = withContext(Dispatchers.IO) {
|
|
pm.getPackageInfo(installedApp.currentPackageName)
|
|
.also { if (it == null) installedAppsRepository.delete(installedApp) }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |