mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2026-01-06 03:42:33 +01:00
Add a start anyway if the server fails to load
This commit is contained in:
@@ -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 ->
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,7 +17,7 @@ class ContextMenu internal constructor() {
|
||||
val logger = KotlinLogging.logger {}
|
||||
internal val list = mutableListOf<Pair<Any, (() -> Unit)?>>()
|
||||
|
||||
fun popupMenu() = JPopupMenu().apply {
|
||||
internal fun popupMenu() = JPopupMenu().apply {
|
||||
fun (() -> Unit)?.andClose() {
|
||||
isVisible = false
|
||||
this?.invoke()
|
||||
|
||||
Reference in New Issue
Block a user