@floless/app 0.151.0 → 0.152.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,10 +7,21 @@
7
7
  view and sends ONE thing back: the person's click, naming the batch it
8
8
  showed. Every string shown is the server's, set with textContent.
9
9
 
10
- States: a pill only when something is offered or needs the person; the
10
+ States: a pill only when something is offered, needs the person, or a check started from this page is still running; the
11
11
  dialog lists "Ready to approve" cards, "Needs you" rows, the downloads
12
12
  line and the consequence footnote; after the click, the results replace
13
13
  the cards in a live region.
14
+
15
+ While a check runs (it can take minutes: each tool download is its own
16
+ wait, see aware-aeco/aware#671) the dialog shows the server's own account
17
+ of it: the steps, which one is active, what it is on and how long it has
18
+ been on it. It asks for that at most once a second (a slow answer skips a
19
+ tick) and only while the dialog is open and a check is running; those
20
+ answers are shown, never applied as the view.
21
+
22
+ A running check never holds the person in the dialog (#2143): Esc and the cancel button (it reads "Close" while a check
23
+ runs, "Not now" otherwise) leave it, the check goes on in the server, and the footer pill says so until the Check
24
+ request this page sent is answered. Only an approval locks the dialog.
14
25
  ────────────────────────────────────────────────────────────────────────── */
15
26
  (function () {
16
27
  'use strict';
@@ -22,6 +33,8 @@
22
33
  var $title = document.getElementById('tool-updates-title');
23
34
  var $body = document.getElementById('tool-updates-body');
24
35
  var $live = document.getElementById('tool-updates-live');
36
+ var $progress = document.getElementById('tool-updates-progress');
37
+ var $announce = document.getElementById('tool-updates-announce');
25
38
  var $foot = document.getElementById('tool-updates-foot');
26
39
  var $check = document.getElementById('tool-updates-check');
27
40
  var $cancel = document.getElementById('tool-updates-cancel');
@@ -56,8 +69,196 @@
56
69
  view = Object.assign({}, view, { cleanup: next });
57
70
  return true;
58
71
  }
59
- var busy = false;
72
+ var approving = false; // an approval is running: the one thing that holds the dialog, because its results are shown only here
73
+ var checking = false; // the Check for updates request is in flight; the person may close the dialog meanwhile
74
+ var checkController = null; // cancels that request when its answer never comes back
75
+ var answerLost = false; // that request was given up on
76
+ var quietAsks = 0; // progress answers in a row saying nothing runs while the Check request is still unanswered
60
77
  var returnFocus = null;
78
+ var PILL_TIP = $pill.getAttribute('data-tip');
79
+ var LOST_ANSWER_AFTER_QUIET_ASKS = 3; // three idle progress answers in a row (about 1 s apart): the answer to the Check request is taken as lost
80
+
81
+ // ── A running check, as the server describes it ───────────────────────────────────────────────────────────
82
+ // The clock is deliberately here although the headless-run styling avoids one (web/app.css, "Headless runs (#571
83
+ // slice 3)"): that run has no progress signal, so a duration there would carry no meaning. This one is the time on a
84
+ // real step, which lets a person tell waiting from stuck. The page subtracts the server's epoch from its own clock,
85
+ // which holds because the page and the server are on the same machine.
86
+ var CLOCK_AFTER_SECONDS = 10; // quick steps stay quiet; a slow one starts showing how long it has taken
87
+ var MARKS = { done: '✓', problem: '!' };
88
+ var progress = null; // the server's progress record ({steps, since}) for the check running now (null before its first answer)
89
+ var lostContact = false; // the last ask for them got no answer: the clock then says nothing it cannot back
90
+ var paintedSteps = null;
91
+ var announced = null;
92
+ var announcedProblems = {};
93
+ var watchTimer = null;
94
+ var polling = false;
95
+ var rereading = false; // the view re-read after a background check ended is on its way
96
+ var pollSentAt = 0;
97
+ var pollController = null;
98
+ var watchGeneration = 0; // bumped whenever watching stops: an answer to an older ask belongs to nothing now
99
+ var POLL_PATIENCE_MS = 6000;
100
+
101
+ function checkInFlight() { return checking || !!(view && view.checking); }
102
+ function isOpen() { return $modal.classList.contains('show'); }
103
+ function checkRunning() { return isOpen() && checkInFlight(); }
104
+
105
+ function elapsedText(seconds) {
106
+ var nb = '\u00a0'; // never wraps between the number and its unit
107
+ if (seconds < 60) return seconds + nb + 's';
108
+ var minutes = Math.floor(seconds / 60);
109
+ var rest = seconds % 60;
110
+ var pad = function (n) { return (n < 10 ? '0' : '') + n; };
111
+ if (minutes < 60) return minutes + nb + 'min' + nb + pad(rest) + nb + 's';
112
+ return Math.floor(minutes / 60) + nb + 'h' + nb + pad(minutes % 60) + nb + 'min';
113
+ }
114
+
115
+ function paintClock() {
116
+ var clock = $progress.querySelector('.tool-updates-step-clock');
117
+ if (!clock) return;
118
+ // Hidden without a start time from the server, and while the server is not answering.
119
+ var seconds = progress && typeof progress.since === 'number' && !lostContact ? Math.max(0, Math.floor((Date.now() - progress.since) / 1000)) : -1;
120
+ clock.hidden = seconds < CLOCK_AFTER_SECONDS;
121
+ if (!clock.hidden) clock.textContent = elapsedText(seconds);
122
+ }
123
+
124
+ // What a screen reader hears: a step that did not do all it set out to, once; and the active step, when it or the item
125
+ // it is on changes. Never the clock, never a repeat.
126
+ function announce(steps) {
127
+ var parts = [];
128
+ steps.forEach(function (step) {
129
+ if (step.state !== 'problem') return;
130
+ var line = step.label + ': ' + (step.detail || 'did not finish');
131
+ if (announcedProblems[step.label] === line) return;
132
+ announcedProblems[step.label] = line;
133
+ parts.push(line);
134
+ });
135
+ var active = steps.filter(function (step) { return step.state === 'active'; })[0];
136
+ var sentence = active ? active.label + (active.detail ? ': ' + active.detail : '') : '';
137
+ if (sentence !== announced) {
138
+ announced = sentence;
139
+ if (sentence) parts.push(sentence);
140
+ }
141
+ if (parts.length) $announce.textContent = parts.join('. ');
142
+ }
143
+
144
+ function paintProgress() {
145
+ var steps = progress && Array.isArray(progress.steps) ? progress.steps : [];
146
+ var signature = JSON.stringify(steps) + '|' + lostContact;
147
+ // Rebuilt only when what it shows changes; the clock beside the active step ticks in place.
148
+ if (signature !== paintedSteps || !$progress.firstChild) {
149
+ $progress.textContent = '';
150
+ $progress.appendChild(el('div', 'tool-updates-progress-head', 'Checking for updates…'));
151
+ if (lostContact) $progress.appendChild(el('div', 'tool-updates-progress-lost', 'Lost contact with FloLess. Still trying…'));
152
+ if (steps.length) {
153
+ var list = el('ol', 'tool-updates-steps');
154
+ list.setAttribute('role', 'list');
155
+ steps.forEach(function (step) {
156
+ var row = el('li', 'tool-updates-step');
157
+ row.setAttribute('data-state', step.state);
158
+ if (step.state === 'active') row.setAttribute('aria-current', 'step');
159
+ var mark = el('span', 'tool-updates-step-mark', MARKS[step.state] || '');
160
+ mark.setAttribute('aria-hidden', 'true');
161
+ row.appendChild(mark);
162
+ row.appendChild(el('span', 'tool-updates-step-label', step.label));
163
+ if (step.state === 'active') {
164
+ var clock = el('span', 'tool-updates-step-clock');
165
+ clock.hidden = true;
166
+ clock.setAttribute('aria-hidden', 'true');
167
+ clock.setAttribute('data-tip', 'Time on this item so far');
168
+ row.appendChild(clock);
169
+ }
170
+ if (step.detail) row.appendChild(el('span', 'tool-updates-step-detail', step.detail));
171
+ list.appendChild(row);
172
+ });
173
+ $progress.appendChild(list);
174
+ }
175
+ // Not while contact is lost: the page cannot say then that the check keeps going.
176
+ if (!lostContact) $progress.appendChild(el('div', 'tool-updates-progress-hint', 'You can close this dialog. The check keeps going, and what it finds shows at the bottom of the screen.'));
177
+ paintedSteps = signature;
178
+ }
179
+ announce(steps);
180
+ paintClock();
181
+ }
182
+
183
+ /** One ask at a time: an older answer can never arrive after, and undo, a newer one. */
184
+ async function pollProgress() {
185
+ if (polling) return;
186
+ polling = true;
187
+ pollSentAt = Date.now();
188
+ var generation = watchGeneration;
189
+ var controller = new AbortController();
190
+ pollController = controller;
191
+ var body = null;
192
+ var failed = false;
193
+ try { body = await call('/api/tool-updates/progress', 'GET', undefined, controller.signal); } catch (error) { failed = true; }
194
+ // A 200 that is not the answer (a truncated or foreign body) is no contact either.
195
+ if (!failed && (!body || body.ok !== true || typeof body.checking !== 'boolean')) failed = true;
196
+ if (pollController === controller) { pollController = null; polling = false; }
197
+ // An answer to an ask from before the dialog was closed (or the check ended) belongs to nothing now.
198
+ if (generation !== watchGeneration || !checkRunning()) return;
199
+ if (failed) {
200
+ markLost();
201
+ } else {
202
+ lostContact = false;
203
+ // Shown, never applied: this is not the view (the view's ticket order belongs to the requests above). A pass that
204
+ // is queued behind another has no steps yet: the old ones go with it rather than freeze with a running clock.
205
+ if (body.checking) {
206
+ progress = body.progress || null;
207
+ quietAsks = 0;
208
+ } else {
209
+ progress = null; // nothing is running: no steps, and no clock counting on one
210
+ // The server has said "idle" three times running yet the Check request is unanswered: its answer is taken as lost, not late.
211
+ if (checking && ++quietAsks >= LOST_ANSWER_AFTER_QUIET_ASKS && checkController) { answerLost = true; checkController.abort(); }
212
+ // A check that ended without this page asking (a background one): the page reads the view and repaints, one read at a time.
213
+ if (!checking && !rereading) {
214
+ rereading = true;
215
+ var readDone = function () { rereading = false; };
216
+ refresh().then(readDone, readDone);
217
+ }
218
+ }
219
+ }
220
+ paintProgress();
221
+ }
222
+
223
+ /** The server is not answering: warn once per episode, whichever way the page found out. */
224
+ function markLost() {
225
+ if (!lostContact) console.warn('tool update progress unavailable');
226
+ lostContact = true;
227
+ }
228
+
229
+ function stopWatching() {
230
+ if (watchTimer) { clearInterval(watchTimer); watchTimer = null; }
231
+ watchGeneration += 1;
232
+ if (pollController) { pollController.abort(); pollController = null; }
233
+ polling = false;
234
+ progress = null;
235
+ lostContact = false;
236
+ paintedSteps = null;
237
+ announcedProblems = {};
238
+ $progress.textContent = '';
239
+ $announce.textContent = '';
240
+ }
241
+
242
+ /** Shows the panel exactly while a check runs in an open dialog, and asks the server how it is going. */
243
+ function syncProgress() {
244
+ var on = checkRunning();
245
+ $progress.hidden = !on;
246
+ if (on) $modal.setAttribute('data-checking', ''); else $modal.removeAttribute('data-checking');
247
+ if (!on) { stopWatching(); return; }
248
+ paintProgress();
249
+ if (watchTimer) return;
250
+ watchTimer = setInterval(function () {
251
+ // An ask that has not come back for a while is the server not answering, not a slow step: say so, give that ask
252
+ // up (it would otherwise hold every later one back for ever) and ask again on the next tick.
253
+ if (polling && Date.now() - pollSentAt > POLL_PATIENCE_MS) {
254
+ if (!lostContact) { markLost(); paintProgress(); }
255
+ if (pollController) pollController.abort();
256
+ }
257
+ paintClock();
258
+ void pollProgress();
259
+ }, 1000);
260
+ void pollProgress();
261
+ }
61
262
 
62
263
  function el(tag, cls, text) {
63
264
  var node = document.createElement(tag);
@@ -68,9 +269,12 @@
68
269
 
69
270
  function plural(n, one, many) { return n + ' ' + (n === 1 ? one : many); }
70
271
 
71
- async function call(path, method, payload) {
72
- var res = await fetch(path, { method: method || 'GET', headers: { 'content-type': 'application/json' }, body: payload });
73
- var body = await res.json().catch(function () { return { ok: false, error: 'FloLess received an unreadable answer (HTTP ' + res.status + ').' }; });
272
+ async function call(path, method, payload, signal) {
273
+ var res = await fetch(path, { method: method || 'GET', headers: { 'content-type': 'application/json' }, body: payload, signal: signal });
274
+ var body = await res.json().catch(function (error) {
275
+ if (error && error.name === 'AbortError') throw error; // the page gave this request up: not "an unreadable answer"
276
+ return { ok: false, error: 'FloLess received an unreadable answer (HTTP ' + res.status + ').' };
277
+ });
74
278
  if (!res.ok && body.ok !== true && !body.results) {
75
279
  var error = new Error(body.error || ('HTTP ' + res.status));
76
280
  error.body = body;
@@ -91,10 +295,13 @@
91
295
  var needs = view && view.supported ? view.needsYou || [] : [];
92
296
  var cleanup = cleanupNeeds();
93
297
  var urgent = offers.filter(function (o) { return !!o.advisory; }).length;
94
- if (!offers.length && !needs.length && !cleanup.length) {
298
+ // Only a check this page started: a background pass is not something the person is waiting for.
299
+ if (!offers.length && !needs.length && !cleanup.length && !checking) {
300
+ // A pill that disappears under the keyboard's focus must not drop focus to the page behind.
301
+ if (document.activeElement === $pill) { var menu = document.getElementById('menu-btn'); if (menu) menu.focus(); }
95
302
  $pill.hidden = true;
96
303
  $pill.removeAttribute('data-state');
97
- if ($modal.classList.contains('show') && !results) paint();
304
+ if (isOpen() && !results) paint();
98
305
  return;
99
306
  }
100
307
  var text;
@@ -110,18 +317,25 @@
110
317
  var days = Math.max.apply(null, offers.map(function (o) { return o.waitingDays || 0; }));
111
318
  text += ' · waiting ' + plural(days, 'day', 'days');
112
319
  }
113
- } else {
320
+ } else if (needs.length || cleanup.length) {
114
321
  state = 'needs';
115
322
  var folders = cleanup.filter(function (c) { return c.kind !== 'unreadable'; }).length;
116
323
  if (needs.length && cleanup.length) text = (needs.length + cleanup.length) + ' things need you';
117
324
  else if (needs.length) text = plural(needs.length, 'workflow needs you', 'workflows need you');
118
325
  else if (folders === cleanup.length) text = plural(folders, 'folder needs you', 'folders need you');
119
326
  else text = plural(cleanup.length, 'item needs you', 'items need you');
327
+ } else {
328
+ state = 'checking';
329
+ text = 'Checking for tool updates…';
120
330
  }
331
+ // Something to act on keeps its wording and colour; a running check is added to it, not put in its place.
332
+ if (checking && state !== 'checking') text += ' · checking…';
121
333
  $pill.textContent = text;
122
334
  $pill.setAttribute('data-state', state);
335
+ $pill.setAttribute('data-tip', !checking ? PILL_TIP : state === 'checking'
336
+ ? 'Still checking for tool updates. Open to watch it.' : PILL_TIP + '. A check is also running.');
123
337
  $pill.hidden = false;
124
- if ($modal.classList.contains('show') && !busy && !results) paint();
338
+ if (isOpen() && !approving && !results) paint();
125
339
  }
126
340
 
127
341
  // ── The dialog ─────────────────────────────────────────────────────────────
@@ -201,7 +415,7 @@
201
415
  var busyHere = forgetting === item.path;
202
416
  var button = el('button', 'tool-updates-open', busyHere ? 'Removing…' : 'Remove from list');
203
417
  button.type = 'button';
204
- button.disabled = busyHere || busy;
418
+ lock(button, forgetReason());
205
419
  button.setAttribute('data-command-id', 'shell.tool-updates-forget-folder');
206
420
  button.setAttribute('data-tip', 'Stop keeping old tool versions for the workflows in this folder');
207
421
  button.setAttribute('aria-label', 'Remove ' + (item.name || item.path) + ' from the list');
@@ -212,7 +426,7 @@
212
426
  }
213
427
 
214
428
  async function forgetFolder(item) {
215
- if (busy || forgetting) return;
429
+ if (approving || checking || forgetting) return;
216
430
  var path = item.path;
217
431
  var ok = false;
218
432
  forgetting = path;
@@ -341,6 +555,7 @@
341
555
  function paint() {
342
556
  var keepFocus = focusKey();
343
557
  try { paintNow(); } finally { restoreFocus(keepFocus); }
558
+ syncProgress();
344
559
  }
345
560
 
346
561
  function paintNow() {
@@ -399,28 +614,45 @@
399
614
  $approve.hidden = !canApprove;
400
615
  if (canApprove) $approve.textContent = 'Approve ' + plural(offers.length, 'workflow', 'workflows');
401
616
  $check.hidden = !!results || !(view && view.supported);
402
- $cancel.textContent = results ? 'Done' : 'Not now';
617
+ // "Not now" would read as cancelling the check, which closing the dialog does not do.
618
+ $cancel.textContent = results ? 'Done' : checkInFlight() ? 'Close' : 'Not now';
403
619
  }
404
620
 
405
- function setBusy(on, label) {
406
- busy = on;
407
- $modal.setAttribute('aria-busy', on ? 'true' : 'false');
408
- [$check, $cancel, $approve].forEach(function (b) { b.disabled = on; });
409
- Array.prototype.forEach.call($body.querySelectorAll('[data-command-id="shell.tool-updates-forget-folder"]'), function (b) { b.disabled = on || !!forgetting; });
410
- if (on && label) $approve.textContent = label;
621
+ /** A control that cannot be used right now says why (Instructor reads data-blocked-reason only while it is disabled). */
622
+ function lock(button, reason) {
623
+ button.disabled = !!reason;
624
+ if (reason) button.setAttribute('data-blocked-reason', reason); else button.removeAttribute('data-blocked-reason');
625
+ }
626
+
627
+ /** Why a button that needs the dialog to itself is held, or '' when nothing holds it. */
628
+ function heldReason(whileChecking) { return approving ? 'Approving now.' : checking ? whileChecking : ''; }
629
+
630
+ /** Why a Remove from list button is held (any row: one folder is removed at a time). */
631
+ function forgetReason() { return heldReason('Wait for the check to finish.') || (forgetting ? 'Removing a folder now.' : ''); }
632
+
633
+ function syncControls() {
634
+ // Only an approval is busy for the screen reader: a busy dialog can make it hold back the step announcements inside.
635
+ $modal.setAttribute('aria-busy', approving ? 'true' : 'false');
636
+ lock($check, heldReason('A check is already running.'));
637
+ lock($approve, heldReason('Wait for the check to finish, then approve.'));
638
+ lock($cancel, approving ? 'Approving now.' : '');
639
+ Array.prototype.forEach.call($body.querySelectorAll('[data-command-id="shell.tool-updates-forget-folder"]'), function (b) { lock(b, forgetReason()); });
411
640
  }
412
641
 
413
642
  async function refresh() {
414
643
  var ticket = nextTicket();
415
644
  try {
416
645
  var body = await call('/api/tool-updates');
646
+ // Only the server's own answer can be the view: a body that is not one keeps the last view on screen.
647
+ if (!body || body.ok !== true) throw new Error('not the server\'s answer');
417
648
  applyView(ticket, body);
418
649
  } catch (error) {
419
650
  // Keep the last answer on screen (and its pill): a dropped request is not "nothing to update".
420
651
  console.warn('tool updates unavailable', error);
421
- if ($modal.classList.contains('show') && !busy) $live.textContent = 'FloLess could not check for tool updates just now. What is shown is from the last check.';
652
+ if (isOpen() && !approving && !checking) $live.textContent = 'FloLess could not check for tool updates just now. What is shown is from the last check.';
422
653
  }
423
654
  paintPill();
655
+ syncProgress();
424
656
  }
425
657
 
426
658
  function open(fromEl) {
@@ -429,16 +661,20 @@
429
661
  $live.textContent = '';
430
662
  paint();
431
663
  $modal.classList.add('show');
664
+ syncProgress();
432
665
  // Focus the title, not the primary: approving is consequential and Enter on open must not do it.
433
666
  setTimeout(function () { $title.focus(); }, 0);
434
- void refresh().then(function () { if ($modal.classList.contains('show') && !busy && !results) paint(); });
667
+ void refresh().then(function () { if (isOpen() && !approving && !results) paint(); });
435
668
  }
436
669
 
437
670
  function close() {
438
- if (busy) return;
671
+ if (approving) return;
439
672
  $modal.classList.remove('show');
673
+ syncProgress();
440
674
  if (results) { results = null; }
441
- if (returnFocus && document.contains(returnFocus)) returnFocus.focus();
675
+ // The pill may have gone while the dialog was open (a check that found nothing): then the menu button, never the page behind.
676
+ var back = returnFocus && !returnFocus.hidden && document.contains(returnFocus) ? returnFocus : document.getElementById('menu-btn');
677
+ if (back) back.focus();
442
678
  returnFocus = null;
443
679
  }
444
680
 
@@ -459,33 +695,90 @@
459
695
  else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
460
696
  });
461
697
 
698
+ /** A line in the corner, for the end of a check the person left running. It takes no focus. A warning stays until it is closed: the person went away for a long check. */
699
+ function toast(text, kind) {
700
+ try { showToast(text, kind, kind === 'warn' ? { persistent: true } : undefined); } catch (error) { console.warn('tool update toast failed', error); }
701
+ }
702
+
462
703
  $check.addEventListener('click', async function () {
463
- setBusy(true);
464
- $live.textContent = 'Checking for new tool versions…';
704
+ if (checking || approving) return;
705
+ var controller = new AbortController();
706
+ checkController = controller;
707
+ checking = true;
708
+ var said = ''; // what the end of the check says: in the live line when the dialog is open, in a corner message when it was closed
709
+ var failed = false;
710
+ var downloadProblem = false;
465
711
  try {
712
+ answerLost = false;
713
+ quietAsks = 0;
714
+ syncControls();
715
+ // A button just disabled had the keyboard (Check, Approve or Remove from list), or focus was already outside the dialog
716
+ // (a browser that does not focus a button on a click): left alone, focus is on the page behind the dialog, where Esc is
717
+ // not heard and Tab leaves the dialog. Parked on the title (as open() does), Esc closes it and Tab stays inside.
718
+ var held = document.activeElement;
719
+ if (!held || !$dialog.contains(held) || held.disabled) $title.focus();
720
+ $live.textContent = ''; // the panel below says what is being checked; the live line is for what came of it
721
+ paintPill(); // the pill carries the running check once the dialog is closed; with the dialog open it also paints the panel
466
722
  var ticket = nextTicket();
467
- var answer = await call('/api/tool-updates/check', 'POST');
468
- applyView(ticket, answer);
723
+ var answer = await call('/api/tool-updates/check', 'POST', undefined, controller.signal);
724
+ // Only the server's own answer can be the view: a body that is not one must not replace what is on screen.
725
+ if (answer && answer.ok === true) applyView(ticket, answer);
726
+ // Said from the check's own answer, not from the view on screen: a dialog reopened mid-check re-reads the server, and that
727
+ // re-read (the previous pass's result) takes a later ticket than this answer and so wins the view.
469
728
  var n = (answer.offers || []).length;
470
- $live.textContent = n ? plural(n, 'workflow is', 'workflows are') + ' ready to approve.' : 'No workflows to approve.';
729
+ said = n ? plural(n, 'workflow is', 'workflows are') + ' ready to approve.' : 'No workflows to approve.';
730
+ downloadProblem = !!(answer.downloads && answer.downloads.error);
731
+ // Not a finished check: a 200 whose body is not the server's answer (ok is not true), or one carrying the server's own
732
+ // sentence (AWARE not asked, or too old). Both are read from THIS request's answer, never from a newer re-read.
733
+ if (answer.ok !== true || answer.sentence) {
734
+ console.warn('tool update check did not run', answer.sentence || answer.error || '');
735
+ failed = true;
736
+ said = 'The tool update check did not go through. Try again in a moment.';
737
+ }
471
738
  // The cleanup pass Check now started keeps running after this answer, and may already have finished and been
472
739
  // re-read: read the server again so this (older) answer never stands over a newer cleanup result.
473
740
  void refresh();
474
741
  } catch (error) {
475
- $live.textContent = error.message;
742
+ if (answerLost) {
743
+ // The server said three times running that nothing was running: it finished and its answer never got here, or the
744
+ // request never reached it. The page cannot tell which, so it says only what it knows and reads the view again.
745
+ said = 'FloLess got no answer to the check and cannot say whether it ran. Nothing is running now, and the list is what FloLess last read. You can check again.';
746
+ void refresh();
747
+ } else {
748
+ console.warn('tool update check failed', error);
749
+ failed = true;
750
+ said = 'The tool update check did not go through. Try again in a moment.';
751
+ }
476
752
  } finally {
477
- setBusy(false);
478
- paint();
479
- paintPill();
480
- // The button was disabled while busy, which drops focus to the page: put it back where the person was.
481
- if (!$check.hidden) $check.focus(); else $title.focus();
753
+ var left = !isOpen(); // closed while it ran: nothing below repaints it, moves focus into it, or writes its live line (only the button states are reset)
754
+ checking = false;
755
+ checkController = null;
756
+ answerLost = false;
757
+ // What came of it is said before anything is repainted, so a repaint that throws cannot swallow it.
758
+ if (left) {
759
+ if (failed) toast('The tool update check did not go through. Open Tool updates to try again.', 'warn');
760
+ else if (downloadProblem) toast('Tool update check finished, but downloading new tool versions ran into a problem. Open Tool updates for details.', 'warn');
761
+ else toast('Tool update check finished. ' + said, 'ok');
762
+ } else {
763
+ $live.textContent = said;
764
+ }
765
+ syncControls();
766
+ paintPill(); // also repaints an open dialog; the panel goes unless the view still says a check is running
767
+ if (!left) {
768
+ // Put focus back on Check if it is still parked on the title (above) or fell out of the dialog; anywhere else the
769
+ // person put it themselves.
770
+ var kept = document.activeElement;
771
+ if (!kept || kept === $title || !$dialog.contains(kept)) { if (!$check.hidden) $check.focus(); else $title.focus(); }
772
+ }
482
773
  }
483
774
  });
484
775
 
485
776
  $approve.addEventListener('click', async function () {
486
- if (!view || !view.batchId) return;
777
+ if (!view || !view.batchId || checking || approving) return;
487
778
  var apps = (view.offers || []).map(function (o) { return o.app; });
488
- setBusy(true, 'Approving…');
779
+ approving = true;
780
+ syncControls();
781
+ $approve.textContent = 'Approving…';
489
782
  $live.textContent = 'Approving ' + plural(apps.length, 'workflow', 'workflows') + '…';
490
783
  try {
491
784
  var ticket = nextTicket();
@@ -509,7 +802,8 @@
509
802
  await refresh();
510
803
  $live.textContent = 'FloLess did not hear back after your approval, so it cannot say yet which workflows moved. The list below is what is still waiting.';
511
804
  } finally {
512
- setBusy(false);
805
+ approving = false;
806
+ syncControls();
513
807
  paint();
514
808
  paintPill();
515
809
  var head = document.getElementById('tool-updates-results-head');