From 4ae0ccdc5dbc845c7f5ad082827c9e1d7d431007 Mon Sep 17 00:00:00 2001 From: Stef Tervelde Date: Fri, 12 Dec 2025 09:03:17 +0100 Subject: [PATCH] Refactor splash screen launch logic in Start.kt 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. --- app/src/processing/app/ui/Start.kt | 45 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/app/src/processing/app/ui/Start.kt b/app/src/processing/app/ui/Start.kt index d7ed635ec..592b73399 100644 --- a/app/src/processing/app/ui/Start.kt +++ b/app/src/processing/app/ui/Start.kt @@ -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) { 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",