@huaqiu/dsh-tool-plugin-update 0.6.25 → 0.6.28
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.
- package/lib/client.js +97 -8
- package/lib/client.js.map +1 -1
- package/package.json +3 -3
- package/src/client/index.ts +132 -9
- package/src/client/update-view.ts +35 -0
package/lib/client.js
CHANGED
|
@@ -1865,6 +1865,18 @@ window.__ModuleLoader__.load({
|
|
|
1865
1865
|
}, TOAST_HOLD_MS);
|
|
1866
1866
|
}
|
|
1867
1867
|
/**
|
|
1868
|
+
* Tear down a panel left open by a previous instance of this plugin.
|
|
1869
|
+
* @returns true when a panel had been open and the caller should re-open it.
|
|
1870
|
+
*/
|
|
1871
|
+
function takeOverUpdateView() {
|
|
1872
|
+
const overlay = document.querySelector("[data-hq-plugin-update-view]");
|
|
1873
|
+
if (overlay === null) return false;
|
|
1874
|
+
const close = overlay.__hqpuClose;
|
|
1875
|
+
if (typeof close === "function") close();
|
|
1876
|
+
else overlay.remove();
|
|
1877
|
+
return true;
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1868
1880
|
* Open (or focus) the update panel. Re-renders from the store; when the store
|
|
1869
1881
|
* is stale the panel first refreshes the report.
|
|
1870
1882
|
*/
|
|
@@ -2489,6 +2501,7 @@ window.__ModuleLoader__.load({
|
|
|
2489
2501
|
overlay.remove();
|
|
2490
2502
|
if (previouslyFocused !== null && previouslyFocused.isConnected) previouslyFocused.focus();
|
|
2491
2503
|
}
|
|
2504
|
+
overlay.__hqpuClose = onClose;
|
|
2492
2505
|
render();
|
|
2493
2506
|
}
|
|
2494
2507
|
/**
|
|
@@ -4443,6 +4456,15 @@ window.__ModuleLoader__.load({
|
|
|
4443
4456
|
document.head.appendChild(tag);
|
|
4444
4457
|
}
|
|
4445
4458
|
/**
|
|
4459
|
+
* A transient "installing" flag with no live job behind it is stale. An install
|
|
4460
|
+
* of this plugin's own package restarts DSH, so the last `/activity` read can
|
|
4461
|
+
* be lost; `schedulePoll()` then stops (no active job) while the 60 s report
|
|
4462
|
+
* refresh keeps running — the footer would say "更新中" forever. A real install
|
|
4463
|
+
* always has a non-terminal active job, so after this window without one we
|
|
4464
|
+
* stop claiming progress rather than waiting for a read that will never come.
|
|
4465
|
+
*/
|
|
4466
|
+
const STALE_INSTALL_MS = 12e4;
|
|
4467
|
+
/**
|
|
4446
4468
|
* In-memory update-report store shared by the badge and the modal.
|
|
4447
4469
|
*
|
|
4448
4470
|
* Exported for tests: the re-attach logic (watch a job by id, notice that the
|
|
@@ -4463,6 +4485,11 @@ window.__ModuleLoader__.load({
|
|
|
4463
4485
|
pollInFlight = false;
|
|
4464
4486
|
/** The job this panel started (or adopted) and is following by id. */
|
|
4465
4487
|
watchedJobId = null;
|
|
4488
|
+
/** True between `setInstalling(true)` and the install response landing: a
|
|
4489
|
+
* state read in that window has no job yet, and must not clear the flag. */
|
|
4490
|
+
installPending = false;
|
|
4491
|
+
/** When the transient installing flag was raised (stale-install watchdog). */
|
|
4492
|
+
installingSinceMs = 0;
|
|
4466
4493
|
/** hq-edge process identity from the last `/activity` read. */
|
|
4467
4494
|
activityBootId = null;
|
|
4468
4495
|
stalledFlag = false;
|
|
@@ -4494,6 +4521,7 @@ window.__ModuleLoader__.load({
|
|
|
4494
4521
|
* page comes back to a server that has no "active job" left to report).
|
|
4495
4522
|
*/
|
|
4496
4523
|
watchJob(id) {
|
|
4524
|
+
this.installPending = false;
|
|
4497
4525
|
this.watchedJobId = id;
|
|
4498
4526
|
if (id !== null) this.schedulePoll();
|
|
4499
4527
|
}
|
|
@@ -4524,14 +4552,16 @@ window.__ModuleLoader__.load({
|
|
|
4524
4552
|
this.active = status.activeJob;
|
|
4525
4553
|
this.recent = status.recentJobs;
|
|
4526
4554
|
if (this.active !== null) this.watchedJobId = this.active.id;
|
|
4527
|
-
|
|
4555
|
+
const watchedSettled = this.watchedJobId !== null && status.recentJobs.some((entry) => entry.id === this.watchedJobId && TERMINAL_PHASES.has(entry.phase));
|
|
4556
|
+
if (wasActive && this.active === null || watchedSettled) this.observeSettled();
|
|
4557
|
+
else this.settleStaleInstall();
|
|
4528
4558
|
this.emit();
|
|
4529
4559
|
this.schedulePoll();
|
|
4530
4560
|
}
|
|
4531
4561
|
/**
|
|
4532
4562
|
* Adopt a `/activity` snapshot.
|
|
4533
4563
|
*
|
|
4534
|
-
*
|
|
4564
|
+
* Three things only this read can tell us:
|
|
4535
4565
|
*
|
|
4536
4566
|
* - `bootId` changed → hq-edge was recreated underneath the page. That is
|
|
4537
4567
|
* what an install of this plugin's own package looks like from here: the
|
|
@@ -4539,6 +4569,11 @@ window.__ModuleLoader__.load({
|
|
|
4539
4569
|
* trusted, so the installing flag is cleared and the report re-read.
|
|
4540
4570
|
* - `stalled` → the active job has stopped advancing. The progress bar must
|
|
4541
4571
|
* stop pretending; the panel shows a "confirming" note with a retry.
|
|
4572
|
+
* - `job` → the durable record of the job we followed by id. It is the ONLY
|
|
4573
|
+
* evidence left when that job settled while DSH was restarting: the
|
|
4574
|
+
* active slot is already empty on this page's first read back, so there
|
|
4575
|
+
* is no active → null transition to notice. Without this check the
|
|
4576
|
+
* installing flag survives the restart and the panel stays "更新中".
|
|
4542
4577
|
*/
|
|
4543
4578
|
applyActivity(activity) {
|
|
4544
4579
|
const rebooted = this.activityBootId !== null && this.activityBootId !== activity.bootId;
|
|
@@ -4548,13 +4583,16 @@ window.__ModuleLoader__.load({
|
|
|
4548
4583
|
const wasActive = this.active !== null;
|
|
4549
4584
|
this.active = activity.activeJob;
|
|
4550
4585
|
if (activity.job !== null) this.upsertRecent(activity.job);
|
|
4586
|
+
const watchedSettled = this.watchedJobId !== null && activity.job !== null && activity.job.id === this.watchedJobId && TERMINAL_PHASES.has(activity.job.phase);
|
|
4587
|
+
const settled = wasActive && this.active === null || watchedSettled;
|
|
4551
4588
|
if (rebooted) {
|
|
4552
4589
|
this.installingFlag = false;
|
|
4553
4590
|
this.stalledFlag = false;
|
|
4554
4591
|
this.phaseAgeMsValue = 0;
|
|
4555
|
-
this.refresh();
|
|
4592
|
+
if (!settled) this.refresh();
|
|
4556
4593
|
}
|
|
4557
|
-
if (
|
|
4594
|
+
if (settled) this.observeSettled();
|
|
4595
|
+
else this.settleStaleInstall();
|
|
4558
4596
|
this.emit();
|
|
4559
4597
|
this.schedulePoll();
|
|
4560
4598
|
}
|
|
@@ -4565,11 +4603,29 @@ window.__ModuleLoader__.load({
|
|
|
4565
4603
|
*/
|
|
4566
4604
|
observeSettled() {
|
|
4567
4605
|
this.installingFlag = false;
|
|
4606
|
+
this.installPending = false;
|
|
4607
|
+
this.installingSinceMs = 0;
|
|
4568
4608
|
this.stalledFlag = false;
|
|
4569
4609
|
this.phaseAgeMsValue = 0;
|
|
4570
4610
|
this.watchedJobId = null;
|
|
4571
4611
|
this.refresh();
|
|
4572
4612
|
}
|
|
4613
|
+
/**
|
|
4614
|
+
* Last-resort reset for the restart case: the page is back, the transient
|
|
4615
|
+
* installing flag is still set, but no job is running and no re-attach read
|
|
4616
|
+
* is coming (the poll loop stops without an active job). Called on mount,
|
|
4617
|
+
* on every successful state read and on each idle refresh, so the footer
|
|
4618
|
+
* cannot stay "更新中" forever. A failed read is not evidence of anything, so
|
|
4619
|
+
* it never clears the flag. A live job, or an install request in flight, always
|
|
4620
|
+
* wins — this only clears a flag with nothing behind it.
|
|
4621
|
+
*/
|
|
4622
|
+
settleStaleInstall() {
|
|
4623
|
+
if (!this.installingFlag || this.installPending) return;
|
|
4624
|
+
if (this.active !== null && !TERMINAL_PHASES.has(this.active.phase)) return;
|
|
4625
|
+
const timedOut = Date.now() - this.installingSinceMs >= STALE_INSTALL_MS;
|
|
4626
|
+
if (this.watchedJobId !== null && !timedOut) return;
|
|
4627
|
+
this.observeSettled();
|
|
4628
|
+
}
|
|
4573
4629
|
/** Keep one job fresh in the local history without duplicating it. */
|
|
4574
4630
|
upsertRecent(job) {
|
|
4575
4631
|
const rest = this.recent.filter((entry) => entry.id !== job.id);
|
|
@@ -4590,6 +4646,25 @@ window.__ModuleLoader__.load({
|
|
|
4590
4646
|
}
|
|
4591
4647
|
}
|
|
4592
4648
|
/**
|
|
4649
|
+
* Re-attach after this plugin's own bundle was swapped mid-install.
|
|
4650
|
+
*
|
|
4651
|
+
* The freshly re-mounted panel starts with no state at all. If the restarted
|
|
4652
|
+
* DSH is not answering yet, one failed read leaves it on its skeleton until
|
|
4653
|
+
* the next 60 s idle tick — indistinguishable from "the page never updated".
|
|
4654
|
+
* Retry the durable-job read and the report a few times; both emit, so the
|
|
4655
|
+
* panel converges as soon as the server is back.
|
|
4656
|
+
*/
|
|
4657
|
+
async resync(attempts = 6, delayMs = 1e3) {
|
|
4658
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
4659
|
+
await this.fetchStatus();
|
|
4660
|
+
await this.refresh();
|
|
4661
|
+
if (this.current !== null) return;
|
|
4662
|
+
if (attempt + 1 < attempts) await new Promise((resolve) => {
|
|
4663
|
+
window.setTimeout(resolve, delayMs);
|
|
4664
|
+
});
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
/**
|
|
4593
4668
|
* One read. While a job is being followed, ask `/activity` about THAT job
|
|
4594
4669
|
* (survives the restart an update of this plugin causes); otherwise fall back
|
|
4595
4670
|
* to the plain `/status` list. An older hq-edge without `/activity` 404s and
|
|
@@ -4611,7 +4686,9 @@ window.__ModuleLoader__.load({
|
|
|
4611
4686
|
this.pollTimer = null;
|
|
4612
4687
|
}
|
|
4613
4688
|
const job = this.active;
|
|
4614
|
-
|
|
4689
|
+
const jobActive = job !== null && !TERMINAL_PHASES.has(job.phase);
|
|
4690
|
+
const awaitingReattach = this.installingFlag && this.watchedJobId !== null && Date.now() - this.installingSinceMs < STALE_INSTALL_MS;
|
|
4691
|
+
if (!jobActive && !awaitingReattach) {
|
|
4615
4692
|
this.pollBackoffMs = 1e3;
|
|
4616
4693
|
return;
|
|
4617
4694
|
}
|
|
@@ -4657,13 +4734,19 @@ window.__ModuleLoader__.load({
|
|
|
4657
4734
|
}
|
|
4658
4735
|
/** Mark the set as installing (set by the modal before the restart). */
|
|
4659
4736
|
setInstalling(flag) {
|
|
4737
|
+
if (flag && !this.installingFlag) this.installingSinceMs = Date.now();
|
|
4660
4738
|
this.installingFlag = flag;
|
|
4739
|
+
this.installPending = flag;
|
|
4740
|
+
if (!flag) this.installingSinceMs = 0;
|
|
4661
4741
|
this.emit();
|
|
4662
4742
|
}
|
|
4663
|
-
/** Idle refresh while mounted (60 s) — no overlapping poll loop.
|
|
4743
|
+
/** Idle refresh while mounted (60 s) — no overlapping poll loop. This is
|
|
4744
|
+
* also the only timer that still runs after a re-attach read was lost, so
|
|
4745
|
+
* it carries the stale-install fallback as well. */
|
|
4664
4746
|
startIdleRefresh() {
|
|
4665
4747
|
if (this.refreshTimer !== null) return;
|
|
4666
4748
|
this.refreshTimer = window.setInterval(() => {
|
|
4749
|
+
this.settleStaleInstall();
|
|
4667
4750
|
this.refresh();
|
|
4668
4751
|
}, 6e4);
|
|
4669
4752
|
}
|
|
@@ -4756,9 +4839,15 @@ window.__ModuleLoader__.load({
|
|
|
4756
4839
|
fn();
|
|
4757
4840
|
} catch {}
|
|
4758
4841
|
});
|
|
4842
|
+
store.settleStaleInstall();
|
|
4759
4843
|
store.startIdleRefresh();
|
|
4760
|
-
|
|
4761
|
-
|
|
4844
|
+
if (takeOverUpdateView()) {
|
|
4845
|
+
openView();
|
|
4846
|
+
store.resync();
|
|
4847
|
+
} else {
|
|
4848
|
+
store.refresh();
|
|
4849
|
+
store.fetchStatus();
|
|
4850
|
+
}
|
|
4762
4851
|
const dispose = () => {
|
|
4763
4852
|
try {
|
|
4764
4853
|
disposeEntry();
|