Add plugin settings screen
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package de.mm20.launcher2.plugin
|
||||
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface PluginRepository {
|
||||
@@ -10,8 +12,8 @@ interface PluginRepository {
|
||||
): Flow<List<Plugin>>
|
||||
fun get(authority: String): Flow<Plugin?>
|
||||
|
||||
fun insertMany(plugins: List<Plugin>)
|
||||
fun insert(plugin: Plugin)
|
||||
fun update(plugin: Plugin)
|
||||
fun deleteMany()
|
||||
fun insertMany(plugins: List<Plugin>): Job
|
||||
fun insert(plugin: Plugin): Job
|
||||
fun update(plugin: Plugin): Job
|
||||
fun deleteMany(): Job
|
||||
}
|
||||
@@ -421,6 +421,7 @@
|
||||
<string name="missing_permission_appshortcuts_search">Set %1$s as default home app to search app shortcuts.</string>
|
||||
<!-- Missing permission app shortcuts permission, used when creating a shortcut in the edit favorites sheet -->
|
||||
<string name="missing_permission_appshortcuts_create">Set %1$s as default home app to create shortcuts.</string>
|
||||
<string name="missing_permission_plugins">Plugin permission is required to use plugins.</string>
|
||||
<!-- Grant a permission, shown in permission banners -->
|
||||
<string name="grant_permission">Grant</string>
|
||||
<!-- Appearance preference title -->
|
||||
@@ -503,6 +504,10 @@
|
||||
<string name="preference_icon_shape_hexagon">Hexagon</string>
|
||||
<string name="preference_category_searchbar">Search bar</string>
|
||||
<string name="preference_screen_integrations">Integrations</string>
|
||||
<string name="preference_screen_plugins">Plugins</string>
|
||||
<string name="preference_screen_plugins_summary">Manage installed extensions</string>
|
||||
<string name="no_plugins_installed">No plugins installed</string>
|
||||
<string name="plugin_host_not_installed">Plugin host not installed</string>
|
||||
<string name="preference_theme_system">Follow system</string>
|
||||
<string name="preference_themed_icons">Themed icons</string>
|
||||
<string name="preference_themed_icons_summary">Color icons with the application\'s color scheme</string>
|
||||
|
||||
@@ -17,6 +17,7 @@ import de.mm20.launcher2.crashreporter.CrashReporter
|
||||
import de.mm20.launcher2.ktx.checkPermission
|
||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||
import de.mm20.launcher2.ktx.tryStartActivity
|
||||
import de.mm20.launcher2.plugin.contracts.PluginContract
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
@@ -63,6 +64,7 @@ enum class PermissionGroup {
|
||||
Notifications,
|
||||
AppShortcuts,
|
||||
Accessibility,
|
||||
Plugins,
|
||||
}
|
||||
|
||||
internal class PermissionsManagerImpl(
|
||||
@@ -83,6 +85,9 @@ internal class PermissionsManagerImpl(
|
||||
private val locationPermissionState = MutableStateFlow(
|
||||
checkPermissionOnce(PermissionGroup.Location)
|
||||
)
|
||||
private val pluginsPermissionState = MutableStateFlow(
|
||||
checkPermissionOnce(PermissionGroup.Plugins)
|
||||
)
|
||||
private val notificationsPermissionState = MutableStateFlow(false)
|
||||
private val accessibilityPermissionState = MutableStateFlow(false)
|
||||
private val appShortcutsPermissionState = MutableStateFlow(
|
||||
@@ -153,6 +158,14 @@ internal class PermissionsManagerImpl(
|
||||
CrashReporter.logException(e)
|
||||
}
|
||||
}
|
||||
|
||||
PermissionGroup.Plugins -> {
|
||||
ActivityCompat.requestPermissions(
|
||||
context,
|
||||
pluginPermissions,
|
||||
permissionGroup.ordinal
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +183,10 @@ internal class PermissionsManagerImpl(
|
||||
contactPermissions.all { context.checkPermission(it) }
|
||||
}
|
||||
|
||||
PermissionGroup.Plugins -> {
|
||||
pluginPermissions.all { context.checkPermission(it) }
|
||||
}
|
||||
|
||||
PermissionGroup.ExternalStorage -> {
|
||||
if (isAtLeastApiLevel(Build.VERSION_CODES.R)) {
|
||||
Environment.isExternalStorageManager()
|
||||
@@ -201,6 +218,7 @@ internal class PermissionsManagerImpl(
|
||||
PermissionGroup.Notifications -> notificationsPermissionState
|
||||
PermissionGroup.AppShortcuts -> appShortcutsPermissionState
|
||||
PermissionGroup.Accessibility -> accessibilityPermissionState
|
||||
PermissionGroup.Plugins -> pluginsPermissionState
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +227,7 @@ internal class PermissionsManagerImpl(
|
||||
permissions: Array<out String>,
|
||||
grantResults: IntArray
|
||||
) {
|
||||
val permissionGroup = PermissionGroup.values().getOrNull(requestCode) ?: return
|
||||
val permissionGroup = PermissionGroup.entries.getOrNull(requestCode) ?: return
|
||||
val granted = grantResults.all { it == PackageManager.PERMISSION_GRANTED }
|
||||
when (permissionGroup) {
|
||||
PermissionGroup.Calendar -> calendarPermissionState.value = granted
|
||||
@@ -219,6 +237,7 @@ internal class PermissionsManagerImpl(
|
||||
PermissionGroup.Notifications -> notificationsPermissionState.value = granted
|
||||
PermissionGroup.AppShortcuts -> appShortcutsPermissionState.value = granted
|
||||
PermissionGroup.Accessibility -> accessibilityPermissionState.value = granted
|
||||
PermissionGroup.Plugins -> pluginsPermissionState.value = granted
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,5 +280,6 @@ internal class PermissionsManagerImpl(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
)
|
||||
private val pluginPermissions = arrayOf(PluginContract.Permission)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user