Add plugin error message if a plugin is not working
This commit is contained in:
parent
0c8d3e9218
commit
2070a25c7e
@ -6,6 +6,7 @@ import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
@ -18,11 +19,15 @@ fun Banner(
|
||||
modifier: Modifier = Modifier,
|
||||
text: String,
|
||||
icon: ImageVector,
|
||||
color: Color = MaterialTheme.colorScheme.surfaceVariant,
|
||||
primaryAction: (@Composable () -> Unit)? = null,
|
||||
secondaryAction: (@Composable () -> Unit)? = null,
|
||||
) {
|
||||
Card(
|
||||
modifier = modifier,
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = color,
|
||||
),
|
||||
shape = MaterialTheme.shapes.small,
|
||||
) {
|
||||
Column {
|
||||
|
||||
@ -17,11 +17,14 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material.icons.automirrored.rounded.InsertDriveFile
|
||||
import androidx.compose.material.icons.rounded.Delete
|
||||
import androidx.compose.material.icons.rounded.Error
|
||||
import androidx.compose.material.icons.rounded.ErrorOutline
|
||||
import androidx.compose.material.icons.rounded.FileCopy
|
||||
import androidx.compose.material.icons.rounded.Info
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material.icons.rounded.Verified
|
||||
import androidx.compose.material.icons.rounded.Warning
|
||||
import androidx.compose.material.icons.rounded.WarningAmber
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@ -191,7 +194,6 @@ fun PluginSettingsScreen(pluginId: String) {
|
||||
start = 12.dp,
|
||||
end = 12.dp,
|
||||
top = 16.dp,
|
||||
bottom = 24.dp
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
@ -199,7 +201,7 @@ fun PluginSettingsScreen(pluginId: String) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.horizontalScroll(rememberScrollState())
|
||||
.padding(bottom = 24.dp, start = 12.dp, end = 12.dp)
|
||||
.padding(bottom = 24.dp, start = 12.dp, end = 12.dp, top = 24.dp)
|
||||
) {
|
||||
for (type in types) {
|
||||
Row(
|
||||
@ -268,7 +270,7 @@ fun PluginSettingsScreen(pluginId: String) {
|
||||
Banner(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
text = state.message ?: "You need to setup this plugin first",
|
||||
icon = Icons.Rounded.ErrorOutline,
|
||||
icon = Icons.Rounded.Info,
|
||||
primaryAction = {
|
||||
TextButton(onClick = {
|
||||
try {
|
||||
@ -281,6 +283,13 @@ fun PluginSettingsScreen(pluginId: String) {
|
||||
}
|
||||
}
|
||||
)
|
||||
} else if (state is PluginState.Error) {
|
||||
Banner(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
text = "This plugin isn't working correctly",
|
||||
icon = Icons.Rounded.Error,
|
||||
color = MaterialTheme.colorScheme.errorContainer,
|
||||
)
|
||||
}
|
||||
SwitchPreference(
|
||||
title = plugin.plugin.label,
|
||||
|
||||
@ -17,6 +17,8 @@ sealed class PluginState {
|
||||
val message: String? = null,
|
||||
) : PluginState()
|
||||
|
||||
data object Error: PluginState()
|
||||
|
||||
companion object {
|
||||
fun fromBundle(bundle: Bundle): PluginState? {
|
||||
val type = bundle.getString("type") ?: return null
|
||||
|
||||
@ -144,7 +144,7 @@ internal class PluginServiceImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getPluginState(plugin: Plugin): PluginState? {
|
||||
override suspend fun getPluginState(plugin: Plugin): PluginState {
|
||||
val bundle = withContext(Dispatchers.IO) {
|
||||
context.contentResolver.call(
|
||||
Uri.Builder()
|
||||
@ -155,8 +155,8 @@ internal class PluginServiceImpl(
|
||||
null,
|
||||
null
|
||||
)
|
||||
} ?: return null
|
||||
return PluginState.fromBundle(bundle)
|
||||
} ?: return PluginState.Error
|
||||
return PluginState.fromBundle(bundle) ?: PluginState.Error
|
||||
}
|
||||
|
||||
override fun isPluginHostInstalled(): Flow<Boolean> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user