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