diff --git a/src/main/kotlin/ca/gosyer/data/server/ServerService.kt b/src/main/kotlin/ca/gosyer/data/server/ServerService.kt index 79f8ec91..96e4de1b 100644 --- a/src/main/kotlin/ca/gosyer/data/server/ServerService.kt +++ b/src/main/kotlin/ca/gosyer/data/server/ServerService.kt @@ -37,6 +37,10 @@ class ServerService @Inject constructor( private val runtime = Runtime.getRuntime() var process: Process? = null + fun startAnyway() { + initialized.value = ServerResult.UNUSED + } + private fun copyJar(jarFile: File) { javaClass.getResourceAsStream("/Tachidesk.jar")?.buffered()?.use { input -> jarFile.outputStream().use { output -> diff --git a/src/main/kotlin/ca/gosyer/ui/base/components/ErrorScreen.kt b/src/main/kotlin/ca/gosyer/ui/base/components/ErrorScreen.kt index dff0832e..6309aa4e 100644 --- a/src/main/kotlin/ca/gosyer/ui/base/components/ErrorScreen.kt +++ b/src/main/kotlin/ca/gosyer/ui/base/components/ErrorScreen.kt @@ -24,11 +24,12 @@ import kotlin.random.Random fun ErrorScreen( errorMessage: String? = null, modifier: Modifier = Modifier, + retryMessage: String = "Retry", retry: (() -> Unit)? = null ) { Surface(modifier) { Box(Modifier.fillMaxSize()) { - Column(modifier = Modifier.align(Alignment.Center)) { + Column(modifier = Modifier.align(Alignment.Center), horizontalAlignment = Alignment.CenterHorizontally) { val errorFace = remember { getRandomErrorFace() } Text(errorFace, fontSize = 36.sp, color = MaterialTheme.colors.onBackground) if (errorMessage != null) { @@ -36,7 +37,7 @@ fun ErrorScreen( } if (retry != null) { Button(retry) { - Text("Retry") + Text(retryMessage) } } } diff --git a/src/main/kotlin/ca/gosyer/ui/base/components/LoadingScreen.kt b/src/main/kotlin/ca/gosyer/ui/base/components/LoadingScreen.kt index 853b8543..faaa94ce 100644 --- a/src/main/kotlin/ca/gosyer/ui/base/components/LoadingScreen.kt +++ b/src/main/kotlin/ca/gosyer/ui/base/components/LoadingScreen.kt @@ -22,6 +22,7 @@ fun LoadingScreen( isLoading: Boolean = true, modifier: Modifier = Modifier.fillMaxSize(), errorMessage: String? = null, + retryMessage: String = "Retry", retry: (() -> Unit)? = null ) { Surface(modifier) { @@ -32,7 +33,7 @@ fun LoadingScreen( } CircularProgressIndicator(Modifier.align(Alignment.Center).size(size)) } else { - ErrorScreen(errorMessage, modifier, retry) + ErrorScreen(errorMessage, modifier, retryMessage, retry) } } } diff --git a/src/main/kotlin/ca/gosyer/ui/main/MainMenu.kt b/src/main/kotlin/ca/gosyer/ui/main/MainMenu.kt index c5ae2568..89df6014 100644 --- a/src/main/kotlin/ca/gosyer/ui/main/MainMenu.kt +++ b/src/main/kotlin/ca/gosyer/ui/main/MainMenu.kt @@ -23,7 +23,6 @@ import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -57,11 +56,6 @@ import compose.icons.fontawesomeicons.regular.Bookmark import compose.icons.fontawesomeicons.regular.Compass import compose.icons.fontawesomeicons.regular.Edit import compose.icons.fontawesomeicons.regular.Map -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import mu.KotlinLogging -import kotlin.time.seconds @Composable fun MainMenu(rootBundle: Bundle) { diff --git a/src/main/kotlin/ca/gosyer/ui/main/main.kt b/src/main/kotlin/ca/gosyer/ui/main/main.kt index 22c3ee22..9f203ebb 100644 --- a/src/main/kotlin/ca/gosyer/ui/main/main.kt +++ b/src/main/kotlin/ca/gosyer/ui/main/main.kt @@ -19,7 +19,6 @@ import ca.gosyer.data.server.ServerService.ServerResult import ca.gosyer.data.ui.UiPreferences import ca.gosyer.data.ui.model.ThemeMode import ca.gosyer.data.ui.model.WindowSettings -import ca.gosyer.ui.base.components.ErrorScreen import ca.gosyer.ui.base.components.LoadingScreen import ca.gosyer.ui.base.theme.AppTheme import ca.gosyer.util.system.getAsFlow @@ -122,10 +121,13 @@ fun main() { val initialized by serverService.initialized.collectAsState() if (initialized == ServerResult.STARTED || initialized == ServerResult.UNUSED) { MainMenu(rootBundle) - } else if (initialized == ServerResult.STARTING) { - LoadingScreen() - } else if (initialized == ServerResult.FAILED) { - ErrorScreen("Unable to start server") + } else if (initialized == ServerResult.STARTING || initialized == ServerResult.FAILED) { + LoadingScreen( + initialized == ServerResult.STARTING, + errorMessage = "Unable to start server", + retryMessage = "Start anyway", + retry = serverService::startAnyway + ) } } } diff --git a/src/main/kotlin/ca/gosyer/ui/sources/SourcesMenu.kt b/src/main/kotlin/ca/gosyer/ui/sources/SourcesMenu.kt index 627e4066..0da25636 100644 --- a/src/main/kotlin/ca/gosyer/ui/sources/SourcesMenu.kt +++ b/src/main/kotlin/ca/gosyer/ui/sources/SourcesMenu.kt @@ -22,7 +22,6 @@ import androidx.compose.material.icons.filled.Home import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import ca.gosyer.data.models.Source diff --git a/src/main/kotlin/ca/gosyer/util/compose/ContextMenu.kt b/src/main/kotlin/ca/gosyer/util/compose/ContextMenu.kt index 93a04105..64b19e99 100644 --- a/src/main/kotlin/ca/gosyer/util/compose/ContextMenu.kt +++ b/src/main/kotlin/ca/gosyer/util/compose/ContextMenu.kt @@ -17,7 +17,7 @@ class ContextMenu internal constructor() { val logger = KotlinLogging.logger {} internal val list = mutableListOf Unit)?>>() - fun popupMenu() = JPopupMenu().apply { + internal fun popupMenu() = JPopupMenu().apply { fun (() -> Unit)?.andClose() { isVisible = false this?.invoke()