diff --git a/app-desktop/src/main/java/kst4contest/view/ApplicationRuntimeLauncher.java b/app-desktop/src/main/java/kst4contest/view/ApplicationRuntimeLauncher.java index 1522473c..60400f34 100644 --- a/app-desktop/src/main/java/kst4contest/view/ApplicationRuntimeLauncher.java +++ b/app-desktop/src/main/java/kst4contest/view/ApplicationRuntimeLauncher.java @@ -24,6 +24,13 @@ public final class ApplicationRuntimeLauncher { private static Kst4ContestApplication currentRuntime; + /** + * Whether the next runtime start shows the setup wizard although the profile is set up. + * Set by the menu entry and cleared by the start that honours it. + */ + private static final java.util.concurrent.atomic.AtomicBoolean SETUP_WIZARD_REQUESTED = + new java.util.concurrent.atomic.AtomicBoolean(false); + private ApplicationRuntimeLauncher() { // Utility class. } @@ -61,6 +68,20 @@ public final class ApplicationRuntimeLauncher { System.exit(0); } + /** Asks the next runtime start to show the setup wizard. */ + static void requestSetupWizard() { + SETUP_WIZARD_REQUESTED.set(true); + } + + /** + * Tells a starting runtime whether the wizard was asked for, and forgets the request. + * + * @return true exactly once per request + */ + static boolean consumeSetupWizardRequest() { + return SETUP_WIZARD_REQUESTED.getAndSet(false); + } + /** * Replaces the running runtime with one bound to another operator profile. * diff --git a/app-desktop/src/main/java/kst4contest/view/Kst4ContestApplication.java b/app-desktop/src/main/java/kst4contest/view/Kst4ContestApplication.java index bf487561..d16bd3bb 100644 --- a/app-desktop/src/main/java/kst4contest/view/Kst4ContestApplication.java +++ b/app-desktop/src/main/java/kst4contest/view/Kst4ContestApplication.java @@ -42,6 +42,8 @@ import kst4contest.view.compose.SettingsWindow; import kst4contest.controller.ScoreService; import kst4contest.view.compose.SettingsWindow; import kst4contest.controller.On4KstConnectionState; +import kst4contest.view.compose.wizard.SetupWizardLauncher; +import kst4contest.view.compose.wizard.SetupWizardOutcome; import java.io.File; import java.io.IOException; @@ -2177,6 +2179,17 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos return; } + /* + * The setup wizard, before anything of this profile's runtime exists. It writes + * preferences.xml and the ChatController built below reads it like any stored + * setting, so there is no running session to bring up to date and no reload. + * Blocks until the wizard is closed; see SetupWizardWindow for why that is safe on + * either thread this method is called from. + */ + SetupWizardOutcome setupWizardOutcome = SetupWizardLauncher.runIfNeeded( + ActiveOperatorProfile.get().getPreferencesRelativeFileName(), + ApplicationRuntimeLauncher.consumeSetupWizardRequest()); + ApplicationRuntimeLauncher.setCurrent(this); ApplicationFileUtils.copyResourceIfRequired(ApplicationConstants.APPLICATION_NAME, STYLE_DEFAULTCSSDAY_RESOURCE, STYLE_DEFAULTCSSDAY_FILE); @@ -2297,6 +2310,15 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos //initialize the timeline uiDispatcher.runOnUi(this::updateTimelineVisuals); + /* + * "Save and connect" in the setup wizard. Here and not earlier: connecting needs the + * runtime this method has just finished building. The same path as File -> Connect, + * so a refused or failed connection is reported the way it is there. + */ + if (setupWizardOutcome == SetupWizardOutcome.SAVED_AND_CONNECT) { + uiDispatcher.runOnUi(this::menuActionConnect); + } + /* * Replaces Application.stop(), which only JavaFX ever called. This covers a SIGTERM * and a closing terminal; the ordinary exit still goes through diff --git a/app-desktop/src/test/java/kst4contest/view/ApplicationRuntimeLauncherSetupWizardTest.java b/app-desktop/src/test/java/kst4contest/view/ApplicationRuntimeLauncherSetupWizardTest.java new file mode 100644 index 00000000..bf45efeb --- /dev/null +++ b/app-desktop/src/test/java/kst4contest/view/ApplicationRuntimeLauncherSetupWizardTest.java @@ -0,0 +1,23 @@ +package kst4contest.view; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * The request to show the setup wizard on the next runtime start is honoured exactly once. + * A request that stuck would open the wizard on every later profile switch. + */ +class ApplicationRuntimeLauncherSetupWizardTest { + + @Test + void aRequestIsHonouredOnce() { + assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(), "nothing was requested"); + + ApplicationRuntimeLauncher.requestSetupWizard(); + + assertTrue(ApplicationRuntimeLauncher.consumeSetupWizardRequest()); + assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(), "the request must not stick"); + } +}