mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Refactor splash screen launch logic in Start.kt (#1357)
Simplifies the splash screen logic by removing coroutine delays and instead using a LaunchedEffect to trigger Base.main after the splash animation completes. The splash window now closes automatically when a new window is opened, improving startup flow and reliability.
This commit is contained in:
@@ -14,10 +14,14 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.*
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.WindowPosition
|
||||
import androidx.compose.ui.window.application
|
||||
import androidx.compose.ui.window.rememberWindowState
|
||||
import processing.app.Base
|
||||
import java.awt.AWTEvent
|
||||
import java.awt.event.WindowEvent
|
||||
|
||||
|
||||
/**
|
||||
* Show a splash screen window. A rewrite of Splash.java
|
||||
@@ -27,8 +31,6 @@ class Start {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
val duration = 200
|
||||
val timeMargin = 50
|
||||
|
||||
application {
|
||||
var starting by remember { mutableStateOf(true) }
|
||||
Window(
|
||||
@@ -44,24 +46,10 @@ class Start {
|
||||
)
|
||||
) {
|
||||
var visible by remember { mutableStateOf(false) }
|
||||
val composition = rememberCoroutineScope()
|
||||
var launched by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(Unit) {
|
||||
Toolkit.setIcon(window)
|
||||
|
||||
visible = true
|
||||
composition.launch {
|
||||
delay(duration.toLong() + timeMargin)
|
||||
try {
|
||||
Base.main(args)
|
||||
} catch (e: Exception) {
|
||||
throw InternalError("Failed to invoke main method", e)
|
||||
}
|
||||
composition.launch {
|
||||
visible = false
|
||||
delay(duration.toLong() + timeMargin)
|
||||
starting = false
|
||||
}
|
||||
}
|
||||
}
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
@@ -76,8 +64,23 @@ class Start {
|
||||
durationMillis = duration,
|
||||
easing = LinearEasing
|
||||
)
|
||||
)
|
||||
),
|
||||
) {
|
||||
LaunchedEffect(visible, transition.currentState) {
|
||||
if (launched) return@LaunchedEffect
|
||||
if (!visible) return@LaunchedEffect
|
||||
// Wait until the view is no longer transitioning
|
||||
if (transition.targetState != transition.currentState) return@LaunchedEffect
|
||||
launched = true
|
||||
Base.main(args)
|
||||
// List for any new windows opening, and close the splash when one does
|
||||
java.awt.Toolkit.getDefaultToolkit()
|
||||
.addAWTEventListener({ event ->
|
||||
if (event.id != WindowEvent.WINDOW_OPENED) return@addAWTEventListener
|
||||
|
||||
visible = false
|
||||
}, AWTEvent.WINDOW_EVENT_MASK);
|
||||
}
|
||||
Image(
|
||||
painter = painterResource("about-processing.svg"),
|
||||
contentDescription = "About",
|
||||
|
||||
Reference in New Issue
Block a user