Keep a running switch's wizard request when a second rerun is refused

rerunSetupWizard set the one-shot request before it tried to obtain the switch, and cleared it when the switch was refused. A second confirmed call during the first one's window teardown therefore removed the first call's request: the session ended and the profile restarted without the wizard. The request is now set only by the call that owns the switch.

Written-by: Claude Fable 5.2
This commit is contained in:
Rsclub2_2 committed 2026-11-18 21:32:12 +01:00
1 parent a8cfe94853
commit f607b831ca
2 files changed
+85 -38

No files matched your search

@@ -111,6 +111,11 @@ public final class ApplicationRuntimeLauncher {
* other way round: a runtime shutting down flushes its pending layout write, and that
* must not land on the file the wizard has just written.</p>
*
* <p>The wizard is requested only once this call owns the switch. A call refused
* because a switch is already under way therefore leaves that switch's request alone:
* clearing it would let the running switch end the session and then start without the
* wizard it was made for.</p>
*
* @return true if the new runtime was built
*/
public static boolean rerunSetupWizard() {
@@ -120,16 +125,25 @@ public final class ApplicationRuntimeLauncher {
return false;
}
requestSetupWizard();
if (!beginSwitch()) {
return false;
}
try {
boolean switched = switchProfile(active.getProfile());
if (!switched) {
consumeSetupWizardRequest();
requestSetupWizard();
boolean switched = false;
try {
switched = performSwitch(active.getProfile());
} finally {
if (!switched) {
// The request is this call's own, and no start consumed it.
consumeSetupWizardRequest();
}
}
return switched;
} catch (RuntimeException e) {
consumeSetupWizardRequest();
throw e;
} finally {
endSwitch();
}
}
@@ -137,7 +151,8 @@ public final class ApplicationRuntimeLauncher {
* Replaces the running runtime with one bound to another operator profile.
*
* @param targetProfile profile to activate
* @return true if the new runtime was built
* @return true if the new runtime was built; false also when another switch is
* already under way
*/
public static boolean switchProfile(final OperatorProfile targetProfile) {
@@ -146,36 +161,42 @@ public final class ApplicationRuntimeLauncher {
}
try {
if (targetProfile == null) {
return false;
}
new OperatorProfileStore().recordLastUsed(targetProfile.getProfileId());
if (currentRuntime != null) {
currentRuntime.shutdownRuntime();
}
ActiveOperatorProfile.set(OperatorProfilePaths.resolve(targetProfile));
Kst4ContestApplication nextRuntime = new Kst4ContestApplication();
try {
nextRuntime.startRuntime();
} catch (Exception e) {
// The previous runtime is already gone, so there is nothing left to return to.
LOGGER.log(Level.SEVERE, "Could not start the selected operator profile", e);
Kst4ContestApplication.alertWindowEvent(
"The operator profile could not be started: " + e.getMessage()
+ "\n\nKST4Contest has to be closed.");
System.exit(1);
return false;
}
setCurrent(nextRuntime);
return true;
return performSwitch(targetProfile);
} finally {
endSwitch();
}
}
/** The switch itself. The caller holds the switch-in-progress mark. */
private static boolean performSwitch(final OperatorProfile targetProfile) {
if (targetProfile == null) {
return false;
}
new OperatorProfileStore().recordLastUsed(targetProfile.getProfileId());
if (currentRuntime != null) {
currentRuntime.shutdownRuntime();
}
ActiveOperatorProfile.set(OperatorProfilePaths.resolve(targetProfile));
Kst4ContestApplication nextRuntime = new Kst4ContestApplication();
try {
nextRuntime.startRuntime();
} catch (Exception e) {
// The previous runtime is already gone, so there is nothing left to return to.
LOGGER.log(Level.SEVERE, "Could not start the selected operator profile", e);
Kst4ContestApplication.alertWindowEvent(
"The operator profile could not be started: " + e.getMessage()
+ "\n\nKST4Contest has to be closed.");
System.exit(1);
return false;
}
setCurrent(nextRuntime);
return true;
}
}
@@ -43,15 +43,41 @@ class ApplicationRuntimeLauncherSetupWizardTest {
}
@Test
void rerunSetupWizardWhileSwitchInProgressReturnsFalseAndClearsRequest() {
void aRefusedRerunLeavesTheRequestOfTheRunningSwitchAlone() {
OperatorProfileSelection previous = ActiveOperatorProfile.get();
OperatorProfile profile = new OperatorProfile("wizard-guard-test", "Wizard Guard Test", false, false);
ActiveOperatorProfile.set(new OperatorProfileSelection(profile, "preferences.xml", "worked.db", false));
// A first rerun is under way: it holds the guard and its request waits for startRuntime.
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
ApplicationRuntimeLauncher.requestSetupWizard();
try {
// A second one arrives while the first tears its windows down, and is refused.
assertFalse(ApplicationRuntimeLauncher.rerunSetupWizard());
assertTrue(ApplicationRuntimeLauncher.consumeSetupWizardRequest(),
"the refused rerun took the running switch's request with it: that switch "
+ "would end the session and then start without the wizard");
} finally {
ApplicationRuntimeLauncher.endSwitch();
ApplicationRuntimeLauncher.consumeSetupWizardRequest();
ActiveOperatorProfile.set(previous);
}
}
@Test
void aRefusedRerunLeavesNoRequestOfItsOwn() {
OperatorProfileSelection previous = ActiveOperatorProfile.get();
OperatorProfile profile = new OperatorProfile("wizard-guard-test", "Wizard Guard Test", false, false);
ActiveOperatorProfile.set(new OperatorProfileSelection(profile, "preferences.xml", "worked.db", false));
// A plain profile switch is under way; nobody asked for the wizard.
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
try {
assertFalse(ApplicationRuntimeLauncher.rerunSetupWizard());
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(),
"a refused rerun must not leave a wizard request behind");
"a refused rerun must not hand its wizard to the switch that refused it");
} finally {
ApplicationRuntimeLauncher.endSwitch();
ApplicationRuntimeLauncher.consumeSetupWizardRequest();