88import fr .inria .corese .gui .feature .main .MainView ;
99import fr .inria .corese .gui .feature .main .ViewManager ;
1010import fr .inria .corese .gui .feature .main .navigation .NavigationBarController ;
11- import fr .inria .corese .gui .feature .startup .splash .StartupSplashController ;
1211import fr .inria .corese .gui .utils .AppExecutors ;
1312import fr .inria .corese .gui .utils .fx .SvgImageLoader ;
13+ import java .awt .SplashScreen ;
1414import java .util .Objects ;
15- import javafx .animation .PauseTransition ;
1615import javafx .application .Application ;
1716import javafx .application .Platform ;
1817import javafx .geometry .Rectangle2D ;
1918import javafx .scene .Scene ;
2019import javafx .scene .image .Image ;
2120import javafx .stage .Screen ;
2221import javafx .stage .Stage ;
23- import javafx .util .Duration ;
2422import org .slf4j .Logger ;
2523import org .slf4j .LoggerFactory ;
2624
@@ -42,17 +40,7 @@ public final class App extends Application {
4240 public void start (Stage primaryStage ) {
4341 Platform .setImplicitExit (true );
4442 ThemeManager themeManager = ThemeManager .getInstance ();
45-
46- StartupSplashController splashController = createStartupSplashController (themeManager );
47- if (splashController != null ) {
48- splashController .show ();
49- }
50-
51- long startupStartNanos = System .nanoTime ();
52- PauseTransition initializeDelay = new PauseTransition (Duration .millis (StartupSplashController .RENDER_GUARD_MS ));
53- initializeDelay .setOnFinished (
54- event -> initializeAndShowMainStage (primaryStage , splashController , startupStartNanos , themeManager ));
55- initializeDelay .play ();
43+ initializeAndShowMainStage (primaryStage , themeManager );
5644 }
5745
5846 @ Override
@@ -69,8 +57,7 @@ public static void main(String[] args) {
6957 System .exit (0 );
7058 }
7159
72- private static void initializeAndShowMainStage (Stage primaryStage , StartupSplashController splashController ,
73- long startupStartNanos , ThemeManager themeManager ) {
60+ private static void initializeAndShowMainStage (Stage primaryStage , ThemeManager themeManager ) {
7461 try {
7562 MainView mainView = new MainView ();
7663 NavigationBarController navigationController = new NavigationBarController ();
@@ -91,44 +78,22 @@ private static void initializeAndShowMainStage(Stage primaryStage, StartupSplash
9178 applyInitialWindowSize (primaryStage );
9279 primaryStage .setOnCloseRequest (event -> Platform .exit ());
9380
94- schedulePrimaryStageShow (primaryStage , splashController , startupStartNanos );
81+ primaryStage .show ();
82+ closeNativeSplashIfPresent ();
9583 } catch (RuntimeException e ) {
96- closeSplashStage ( splashController );
84+ closeNativeSplashIfPresent ( );
9785 throw e ;
9886 }
9987 }
10088
101- private static void schedulePrimaryStageShow (Stage primaryStage , StartupSplashController splashController ,
102- long startupStartNanos ) {
103- double elapsedMs = (System .nanoTime () - startupStartNanos ) / 1_000_000.0 ;
104- double remainingMs = StartupSplashController .MIN_DISPLAY_MS - elapsedMs ;
105- if (splashController == null || remainingMs <= 0 ) {
106- showPrimaryStageAndCloseSplash (primaryStage , splashController );
107- return ;
108- }
109- PauseTransition delay = new PauseTransition (Duration .millis (remainingMs ));
110- delay .setOnFinished (event -> showPrimaryStageAndCloseSplash (primaryStage , splashController ));
111- delay .play ();
112- }
113-
114- private static void showPrimaryStageAndCloseSplash (Stage primaryStage , StartupSplashController splashController ) {
115- primaryStage .show ();
116- closeSplashStage (splashController );
117- }
118-
119- private static void closeSplashStage (StartupSplashController splashController ) {
120- if (splashController == null ) {
121- return ;
122- }
123- splashController .close ();
124- }
125-
126- private static StartupSplashController createStartupSplashController (ThemeManager themeManager ) {
89+ private static void closeNativeSplashIfPresent () {
12790 try {
128- return new StartupSplashController (themeManager );
129- } catch (RuntimeException e ) {
130- LOGGER .warn ("Unable to create startup splash" , e );
131- return null ;
91+ SplashScreen splash = SplashScreen .getSplashScreen ();
92+ if (splash != null ) {
93+ splash .close ();
94+ }
95+ } catch (UnsupportedOperationException _) {
96+ // No native splash active.
13297 }
13398 }
13499
@@ -140,8 +105,8 @@ private static void applyApplicationIcon(Stage stage) {
140105 return ;
141106 }
142107
143- Image pngIcon = new Image (
144- Objects . requireNonNull ( App . class . getResourceAsStream ( APP_LOGO_PNG_RESOURCE ), "Application icon not found" ));
108+ Image pngIcon = new Image (Objects . requireNonNull ( App . class . getResourceAsStream ( APP_LOGO_PNG_RESOURCE ),
109+ "Application icon not found" ));
145110 stage .getIcons ().add (pngIcon );
146111 } catch (Exception e ) {
147112 LOGGER .warn ("Failed to load application icon" , e );
0 commit comments