mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Let the app try reconnecting once on its own when its countdown ends
AI Assisted
This commit is contained in:
1 parent
7021ff9a48
commit
e80713742e
2 files changed
+25
-3
No files matched your search
+15
-3
@@ -950,7 +950,10 @@ function stopRetryCountdown() {
|
||||
stateButton.disabled = false;
|
||||
}
|
||||
|
||||
function showState(text, buttonLabel, onButton, onCancel, { tired = false, retryAfter = 0 } = {}) {
|
||||
// One automatic Try reconnecting per run of trouble (cleared when a new page is announced).
|
||||
let autoReconnected = false;
|
||||
|
||||
function showState(text, buttonLabel, onButton, onCancel, { tired = false, retryAfter = 0, autoRetry = false } = {}) {
|
||||
// The poll repeats the same waiting message every tick: that must not
|
||||
// restart a countdown that is already running (or its button).
|
||||
if (retryAfter > 0 && !stateBox.hidden && stateText.textContent === text && stateButton.textContent.startsWith('Try reconnecting')) return;
|
||||
@@ -975,7 +978,15 @@ function showState(text, buttonLabel, onButton, onCancel, { tired = false, retry
|
||||
retryTimer = setInterval(() => {
|
||||
left -= 1;
|
||||
stateButton.textContent = retryLabel(left);
|
||||
if (left <= 0) stopRetryCountdown();
|
||||
if (left <= 0) {
|
||||
stopRetryCountdown();
|
||||
// The button is on now: press it once for the person. If that try
|
||||
// fails, the button stays for them.
|
||||
if (autoRetry && onButton) {
|
||||
autoReconnected = true;
|
||||
onButton();
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
@@ -1020,7 +1031,7 @@ async function pollConsole() {
|
||||
if (action === 'wait-for-phase') {
|
||||
// Covers the old phase's page and its "Lost contact" until the new one
|
||||
// says hello. Never over a question the box is already asking.
|
||||
if (stateCancelEl.hidden) showState(loopDetailEl.textContent, 'Try reconnecting', reconnectConsole, undefined, { retryAfter: RETRY_AFTER_SECONDS });
|
||||
if (stateCancelEl.hidden) showState(loopDetailEl.textContent, 'Try reconnecting', reconnectConsole, undefined, { retryAfter: RETRY_AFTER_SECONDS, autoRetry: !autoReconnected });
|
||||
return;
|
||||
}
|
||||
markConsoleDead();
|
||||
@@ -1110,6 +1121,7 @@ function showAnnounced(notice) {
|
||||
restarting = false;
|
||||
// A new page is a new start: the budget is per run of trouble, not per launch.
|
||||
reconnects = 0;
|
||||
autoReconnected = false;
|
||||
if (!consoleKnown) {
|
||||
consoleKnown = true;
|
||||
if (!pollTimer) pollTimer = setInterval(pollConsole, STATUS_POLL_MS);
|
||||
|
||||
@@ -444,6 +444,16 @@ test("app.js re-arms the hello check and offers Try reconnecting on the loop's w
|
||||
assert.match(app, /loopStep === 'Starting' && stepBefore !== 'Starting' && consoleKnown\) void pollConsole\(\)/, "a phase starting looks at the console at once, so the countdown does not wait for the next poll");
|
||||
});
|
||||
|
||||
test("app.js tries Try reconnecting once by itself when its countdown ends, once per run of trouble", () => {
|
||||
const app = fs.readFileSync(path.join(HERE, "..", "plan2code-app", "ui", "app.js"), "utf8");
|
||||
const show = app.slice(app.indexOf("function showState"), app.indexOf("function hideState"));
|
||||
assert.match(show, /autoRetry/, "showState takes an autoRetry option");
|
||||
assert.match(show, /if \(left <= 0\) \{[^}]*onButton/s, "the countdown's end runs the button's action itself");
|
||||
assert.match(app, /showState\(loopDetailEl\.textContent[^)]*autoRetry: !autoReconnected/s, "the loop's wait for a phase's page tries once");
|
||||
const announced = app.slice(app.indexOf("function showAnnounced"), app.indexOf("window.__TAURI__.event.listen('console-page'"));
|
||||
assert.match(announced, /autoReconnected = false/, "each new page gets its own automatic try");
|
||||
});
|
||||
|
||||
test("app.js refills the reconnect budget on a new page and brings the page back when a loop ends", () => {
|
||||
const app = fs.readFileSync(path.join(HERE, "..", "plan2code-app", "ui", "app.js"), "utf8");
|
||||
const announced = app.slice(app.indexOf("function showAnnounced"), app.indexOf("window.__TAURI__.event.listen('console-page'"));
|
||||
|
||||
Reference in new issue
Block a user