Auto refresh plugin list after granting plugin permission

This commit is contained in:
MM20 2023-12-11 14:12:16 +01:00
parent fced1bc14e
commit d13ca6cd6c
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 14 additions and 1 deletions

View File

@ -41,5 +41,6 @@ dependencies {
implementation(project(":core:ktx")) implementation(project(":core:ktx"))
implementation(project(":core:base")) implementation(project(":core:base"))
implementation(project(":core:crashreporter")) implementation(project(":core:crashreporter"))
implementation(project(":core:permissions"))
} }

View File

@ -4,5 +4,5 @@ import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module import org.koin.dsl.module
val servicesPluginsModule = module { val servicesPluginsModule = module {
single<PluginService> { PluginServiceImpl(androidContext(), get()) } single<PluginService> { PluginServiceImpl(androidContext(), get(), get()) }
} }

View File

@ -13,6 +13,8 @@ import android.os.Build
import android.util.Base64 import android.util.Base64
import android.util.Log import android.util.Log
import de.mm20.launcher2.ktx.tryStartActivity import de.mm20.launcher2.ktx.tryStartActivity
import de.mm20.launcher2.permissions.PermissionGroup
import de.mm20.launcher2.permissions.PermissionsManager
import de.mm20.launcher2.plugin.Plugin import de.mm20.launcher2.plugin.Plugin
import de.mm20.launcher2.plugin.PluginPackage import de.mm20.launcher2.plugin.PluginPackage
import de.mm20.launcher2.plugin.PluginRepository import de.mm20.launcher2.plugin.PluginRepository
@ -24,6 +26,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.flowOn
@ -62,6 +65,7 @@ interface PluginService {
internal class PluginServiceImpl( internal class PluginServiceImpl(
private val context: Context, private val context: Context,
private val repository: PluginRepository, private val repository: PluginRepository,
private val permissionsManager: PermissionsManager,
) : PluginService { ) : PluginService {
private val scope: CoroutineScope = CoroutineScope(Job() + Dispatchers.Default) private val scope: CoroutineScope = CoroutineScope(Job() + Dispatchers.Default)
@ -80,6 +84,14 @@ internal class PluginServiceImpl(
addAction(Intent.ACTION_PACKAGE_CHANGED) addAction(Intent.ACTION_PACKAGE_CHANGED)
addDataScheme("package") addDataScheme("package")
}) })
scope.launch {
permissionsManager.hasPermission(PermissionGroup.Plugins).collectLatest {
if (it) {
refreshPlugins()
}
}
}
} }
override fun enablePluginPackage(plugin: PluginPackage) { override fun enablePluginPackage(plugin: PluginPackage) {