mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-11-19 01:52:29 +01:00
Harden the setup wizard after the branch review
Written-by: Gemini 4 Hydrogen (Antigravity) Written-by: Claude Fable 5.2
This commit is contained in:
13 files changed
+248
-31
No files matched your search
@@ -517,9 +517,11 @@ wizard.source.stationKeep=Station unverändert lassen (Locator {0})
|
||||
wizard.personal.title=Persönliches
|
||||
wizard.personal.lead=Gehört zum Operator.
|
||||
wizard.personal.name=Anzeigename im Chat
|
||||
wizard.personal.nameInvalid=Der Name darf kein Zeichen | enthalten.
|
||||
wizard.login.title=Anmeldung bei ON4KST
|
||||
wizard.login.lead=Die Zugangsdaten deines ON4KST-Kontos.
|
||||
wizard.login.callsignInvalid=Das sieht nicht nach einem Rufzeichen aus.
|
||||
wizard.login.passwordInvalid=Das Passwort darf nicht mit einem Leerzeichen beginnen oder enden und kein Zeichen | enthalten.
|
||||
wizard.site.title=Standort und Bänder
|
||||
wizard.site.lead=Gehört zur Station, nicht zum Operator.
|
||||
wizard.site.locatorInvalid=Sechsstelliger Maidenhead-Locator, zum Beispiel JO50AA.
|
||||
|
||||
@@ -526,9 +526,11 @@ wizard.source.stationKeep=Leave the station unchanged (locator {0})
|
||||
wizard.personal.title=Personal
|
||||
wizard.personal.lead=Belongs to the operator.
|
||||
wizard.personal.name=Name shown in the chat
|
||||
wizard.personal.nameInvalid=The name must not contain a | character.
|
||||
wizard.login.title=ON4KST login
|
||||
wizard.login.lead=The credentials of your ON4KST account.
|
||||
wizard.login.callsignInvalid=This does not look like a callsign.
|
||||
wizard.login.passwordInvalid=The password must not begin or end with a blank and must not contain a | character.
|
||||
wizard.site.title=Location and bands
|
||||
wizard.site.lead=Belongs to the station, not to the operator.
|
||||
wizard.site.locatorInvalid=Six-character Maidenhead locator, for example JO50AA.
|
||||
|
||||
@@ -32,6 +32,13 @@ public final class ApplicationRuntimeLauncher {
|
||||
private static final java.util.concurrent.atomic.AtomicBoolean SETUP_WIZARD_REQUESTED =
|
||||
new java.util.concurrent.atomic.AtomicBoolean(false);
|
||||
|
||||
/**
|
||||
* Guards {@link #switchProfile(OperatorProfile)} against re-entry while window teardown
|
||||
* inside {@link Kst4ContestApplication#shutdownRuntime()} is still pumping events.
|
||||
*/
|
||||
private static final java.util.concurrent.atomic.AtomicBoolean SWITCH_IN_PROGRESS =
|
||||
new java.util.concurrent.atomic.AtomicBoolean(false);
|
||||
|
||||
private ApplicationRuntimeLauncher() {
|
||||
// Utility class.
|
||||
}
|
||||
@@ -83,6 +90,20 @@ public final class ApplicationRuntimeLauncher {
|
||||
return SETUP_WIZARD_REQUESTED.getAndSet(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a profile switch as in progress if none is currently running.
|
||||
*
|
||||
* @return true if this call obtained the mark
|
||||
*/
|
||||
static boolean beginSwitch() {
|
||||
return SWITCH_IN_PROGRESS.compareAndSet(false, true);
|
||||
}
|
||||
|
||||
/** Clears the in-progress mark of a profile switch. */
|
||||
static void endSwitch() {
|
||||
SWITCH_IN_PROGRESS.set(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuilds the runtime of the active profile with the setup wizard in front of it.
|
||||
*
|
||||
@@ -100,7 +121,16 @@ public final class ApplicationRuntimeLauncher {
|
||||
}
|
||||
|
||||
requestSetupWizard();
|
||||
return switchProfile(active.getProfile());
|
||||
try {
|
||||
boolean switched = switchProfile(active.getProfile());
|
||||
if (!switched) {
|
||||
consumeSetupWizardRequest();
|
||||
}
|
||||
return switched;
|
||||
} catch (RuntimeException e) {
|
||||
consumeSetupWizardRequest();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,33 +141,41 @@ public final class ApplicationRuntimeLauncher {
|
||||
*/
|
||||
public static boolean switchProfile(final OperatorProfile targetProfile) {
|
||||
|
||||
if (targetProfile == null) {
|
||||
if (!beginSwitch()) {
|
||||
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;
|
||||
}
|
||||
if (targetProfile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setCurrent(nextRuntime);
|
||||
return true;
|
||||
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 {
|
||||
endSwitch();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ private fun categoryName(number: Int): String = ChatCategory(number).getChatCate
|
||||
* The wizard's pages and its button row.
|
||||
*
|
||||
* All decisions are in [state]; this draws them. The texts are read from [languageStore] in
|
||||
* the composition, so the language picker on the first page switches the wizard itself.
|
||||
* the composition, so the language picker on the personal page switches the wizard itself.
|
||||
*
|
||||
* @param saveFailed whether the last Save could not write the file
|
||||
* @param onLater the operator does not want to set up now; nothing is written
|
||||
@@ -183,6 +183,7 @@ private fun PersonalPage(state: SetupWizardState, strings: Strings, languageStor
|
||||
onSelect = { languageStore.use(it) },
|
||||
)
|
||||
Form.text(strings.wizardPersonalName, state.name) { state.name = it }
|
||||
if (state.nameRefused) Refusal(strings.wizardPersonalNameInvalid)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -192,6 +193,7 @@ private fun LoginPage(state: SetupWizardState, strings: Strings) {
|
||||
Form.text(strings.stationCallsign, state.callsign) { state.callsign = it }
|
||||
if (state.callsignRefused) Refusal(strings.wizardLoginCallsignInvalid)
|
||||
Form.password(strings.stationPassword, state.password) { state.password = it }
|
||||
if (state.passwordRefused) Refusal(strings.wizardLoginPasswordInvalid)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -249,6 +251,10 @@ private fun SummaryPage(state: SetupWizardState, strings: Strings, saveFailed: B
|
||||
if (state.leavesIntegrationsUntouched) Text(strings.wizardSummaryIntegrationsUnchanged)
|
||||
|
||||
Form.section(strings.wizardSummaryPersonal) {
|
||||
SummaryRow(
|
||||
strings.guiLanguage,
|
||||
if (state.language == SYSTEM_LANGUAGE) strings.guiLanguageSystem else state.language.uppercase(),
|
||||
)
|
||||
SummaryRow(strings.wizardPersonalName, state.name.ifBlank { strings.wizardSummaryNone })
|
||||
Form.button(strings.wizardChange) { state.edit(WizardPage.PERSONAL) }
|
||||
}
|
||||
|
||||
@@ -204,10 +204,10 @@ class SetupWizardState(prefs: ChatPreferences) {
|
||||
}
|
||||
|
||||
private val personalComplete: Boolean
|
||||
get() = name.isNotBlank()
|
||||
get() = isStorableName(name)
|
||||
|
||||
private val loginComplete: Boolean
|
||||
get() = isPlausibleCallsign(callsign) && password.isNotEmpty()
|
||||
get() = isPlausibleCallsign(callsign) && isStorablePassword(password)
|
||||
|
||||
private val stationComplete: Boolean
|
||||
get() = isLocator(locator) && bands.isNotEmpty() && category in CATEGORY_NUMBERS &&
|
||||
@@ -217,10 +217,18 @@ class SetupWizardState(prefs: ChatPreferences) {
|
||||
val mandatoryComplete: Boolean
|
||||
get() = personalComplete && loginComplete && stationComplete
|
||||
|
||||
/** A chat name that was typed and cannot be sent. An empty or blank field is not an error yet. */
|
||||
val nameRefused: Boolean
|
||||
get() = name.isNotBlank() && !isStorableName(name)
|
||||
|
||||
/** A callsign that was typed and does not look like one. An empty field is not an error yet. */
|
||||
val callsignRefused: Boolean
|
||||
get() = callsign.isNotBlank() && !isPlausibleCallsign(callsign)
|
||||
|
||||
/** A password that was typed and cannot be stored or sent. An empty field is not an error yet. */
|
||||
val passwordRefused: Boolean
|
||||
get() = password.isNotEmpty() && !isStorablePassword(password)
|
||||
|
||||
/** A locator that was typed and is not one. An empty field is not an error yet. */
|
||||
val locatorRefused: Boolean
|
||||
get() = locator.isNotBlank() && !isLocator(locator)
|
||||
@@ -342,6 +350,21 @@ class SetupWizardState(prefs: ChatPreferences) {
|
||||
/** Whether a text is a six-character Maidenhead locator, in either case. */
|
||||
fun isLocator(text: String): Boolean = LOCATOR.matches(text.trim())
|
||||
|
||||
/**
|
||||
* Whether a password can be stored in preferences.xml and sent in an ON4KST login frame:
|
||||
* not blank, free of surrounding whitespace (which the XML reader trims), and free of
|
||||
* frame delimiters.
|
||||
*/
|
||||
fun isStorablePassword(text: String): Boolean =
|
||||
text.isNotBlank() && text == text.trim() && '|' !in text && '\r' !in text && '\n' !in text
|
||||
|
||||
/**
|
||||
* Whether a chat display name can be sent in an ON4KST frame: not blank and free of
|
||||
* frame delimiters.
|
||||
*/
|
||||
fun isStorableName(text: String): Boolean =
|
||||
text.isNotBlank() && '|' !in text && '\r' !in text && '\n' !in text
|
||||
|
||||
/**
|
||||
* The chat category the lowest band belongs to: 1 for 50/70 MHz, 2 for 144/432 MHz,
|
||||
* 3 above. Null without a band. A suggestion only -- the operator confirms it.
|
||||
|
||||
@@ -145,9 +145,11 @@ object SetupWizardLauncher {
|
||||
/*
|
||||
* A file that cannot be read is not a profile to set up: the wizard would start from
|
||||
* compiled-in defaults and Save would write them over whatever the file holds. The
|
||||
* runtime deals with such a file as it always did.
|
||||
* runtime deals with such a file as it always did. A throwing read counts as failed too.
|
||||
*/
|
||||
if (!prefs.readPreferencesFromXmlFile()) return SetupWizardOutcome.NOT_SHOWN
|
||||
if (!runCatching { prefs.readPreferencesFromXmlFile() }.getOrDefault(false)) {
|
||||
return SetupWizardOutcome.NOT_SHOWN
|
||||
}
|
||||
|
||||
if (!forced && !LoginConfiguration.isUnconfigured(prefs)) return SetupWizardOutcome.NOT_SHOWN
|
||||
|
||||
|
||||
Reference in new issue
Block a user