mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-11-19 01:52:29 +01:00
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:
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
|
* 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>
|
* 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
|
* @return true if the new runtime was built
|
||||||
*/
|
*/
|
||||||
public static boolean rerunSetupWizard() {
|
public static boolean rerunSetupWizard() {
|
||||||
@@ -120,16 +125,25 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
requestSetupWizard();
|
if (!beginSwitch()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean switched = switchProfile(active.getProfile());
|
requestSetupWizard();
|
||||||
if (!switched) {
|
|
||||||
consumeSetupWizardRequest();
|
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;
|
return switched;
|
||||||
} catch (RuntimeException e) {
|
} finally {
|
||||||
consumeSetupWizardRequest();
|
endSwitch();
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +151,8 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
* Replaces the running runtime with one bound to another operator profile.
|
* Replaces the running runtime with one bound to another operator profile.
|
||||||
*
|
*
|
||||||
* @param targetProfile profile to activate
|
* @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) {
|
public static boolean switchProfile(final OperatorProfile targetProfile) {
|
||||||
|
|
||||||
@@ -146,36 +161,42 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (targetProfile == null) {
|
return performSwitch(targetProfile);
|
||||||
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;
|
|
||||||
} finally {
|
} finally {
|
||||||
endSwitch();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+28
-2
@@ -43,15 +43,41 @@ class ApplicationRuntimeLauncherSetupWizardTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void rerunSetupWizardWhileSwitchInProgressReturnsFalseAndClearsRequest() {
|
void aRefusedRerunLeavesTheRequestOfTheRunningSwitchAlone() {
|
||||||
OperatorProfileSelection previous = ActiveOperatorProfile.get();
|
OperatorProfileSelection previous = ActiveOperatorProfile.get();
|
||||||
OperatorProfile profile = new OperatorProfile("wizard-guard-test", "Wizard Guard Test", false, false);
|
OperatorProfile profile = new OperatorProfile("wizard-guard-test", "Wizard Guard Test", false, false);
|
||||||
ActiveOperatorProfile.set(new OperatorProfileSelection(profile, "preferences.xml", "worked.db", 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());
|
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
|
||||||
try {
|
try {
|
||||||
assertFalse(ApplicationRuntimeLauncher.rerunSetupWizard());
|
assertFalse(ApplicationRuntimeLauncher.rerunSetupWizard());
|
||||||
|
|
||||||
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(),
|
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 {
|
} finally {
|
||||||
ApplicationRuntimeLauncher.endSwitch();
|
ApplicationRuntimeLauncher.endSwitch();
|
||||||
ApplicationRuntimeLauncher.consumeSetupWizardRequest();
|
ApplicationRuntimeLauncher.consumeSetupWizardRequest();
|
||||||
|
|||||||
Reference in new issue
Block a user