FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactor splash screen launch logic by Stefterv · Pull Request #1357 · processing/processing4 · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .kt  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
45 changes: 24 additions & 21 deletions app/src/processing/app/ui/Start.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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",
Expand Down

Back | FazBrowse Home | New Git URL