dsh-desktop-enhance 0.9.2 → 0.9.3

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 CHANGED
@@ -8166,12 +8166,12 @@ ABORT_ERR ETIMEDOUT ECONNREFUSED ECONNRESET EPIPE EADDRINUSE ENOSPC EACCES STORE
8166
8166
  }
8167
8167
  //#endregion
8168
8168
  //#region src/client/remote/panel.ts
8169
- function isPlainRecord$1(value) {
8169
+ function isPlainRecord(value) {
8170
8170
  return typeof value === "object" && value !== null && !Array.isArray(value);
8171
8171
  }
8172
8172
  function isStatus(value) {
8173
- if (!isPlainRecord$1(value)) return false;
8174
- return typeof value.enabled === "boolean" && typeof value.running === "boolean" && Number.isInteger(value.port) && Number(value.port) >= 1 && Number(value.port) <= 65535 && typeof value.nativeLoopback === "boolean" && (value.management === "local" || value.management === "remote") && (value.currentDeviceId === null || typeof value.currentDeviceId === "string") && (value.error === null || typeof value.error === "string") && Array.isArray(value.devices) && value.devices.every((device) => isPlainRecord$1(device) && typeof device.id === "string" && typeof device.name === "string" && typeof device.userAgent === "string" && typeof device.online === "boolean" && typeof device.createdAt === "number" && Number.isSafeInteger(device.createdAt) && device.createdAt >= 0 && (device.revokedAt === void 0 || typeof device.revokedAt === "number" && Number.isSafeInteger(device.revokedAt) && device.revokedAt >= device.createdAt));
8173
+ if (!isPlainRecord(value)) return false;
8174
+ return typeof value.enabled === "boolean" && typeof value.running === "boolean" && Number.isInteger(value.port) && Number(value.port) >= 1 && Number(value.port) <= 65535 && typeof value.nativeLoopback === "boolean" && (value.management === "local" || value.management === "remote") && (value.currentDeviceId === null || typeof value.currentDeviceId === "string") && (value.error === null || typeof value.error === "string") && Array.isArray(value.devices) && value.devices.every((device) => isPlainRecord(device) && typeof device.id === "string" && typeof device.name === "string" && typeof device.userAgent === "string" && typeof device.online === "boolean" && typeof device.createdAt === "number" && Number.isSafeInteger(device.createdAt) && device.createdAt >= 0 && (device.revokedAt === void 0 || typeof device.revokedAt === "number" && Number.isSafeInteger(device.revokedAt) && device.revokedAt >= device.createdAt));
8175
8175
  }
8176
8176
  async function request$1(signal, body) {
8177
8177
  const response = await globalThis.fetch(REMOTE_MANAGEMENT_ROUTE, {
@@ -8524,9 +8524,6 @@ ABORT_ERR ETIMEDOUT ECONNREFUSED ECONNRESET EPIPE EADDRINUSE ENOSPC EACCES STORE
8524
8524
  "installing"
8525
8525
  ].includes(phase);
8526
8526
  const requestError = (caught) => caught instanceof Error && ["update.unauthorized", "update.unavailable"].includes(caught.message) ? caught.message : "update.requestFailed";
8527
- function isPlainRecord(value) {
8528
- return typeof value === "object" && value !== null && !Array.isArray(value);
8529
- }
8530
8527
  const PHASES = [
8531
8528
  "idle",
8532
8529
  "checking",
@@ -8537,10 +8534,13 @@ ABORT_ERR ETIMEDOUT ECONNREFUSED ECONNRESET EPIPE EADDRINUSE ENOSPC EACCES STORE
8537
8534
  "installing",
8538
8535
  "error"
8539
8536
  ];
8537
+ function isUpdatePhase(value) {
8538
+ return typeof value === "string" && PHASES.some((phase) => phase === value);
8539
+ }
8540
8540
  function isView(value) {
8541
8541
  if (!isPlainRecord(value)) return false;
8542
8542
  if (typeof value.currentVersion !== "string") return false;
8543
- if (!PHASES.includes(value.phase)) return false;
8543
+ if (!isUpdatePhase(value.phase)) return false;
8544
8544
  if (value.version !== void 0 && typeof value.version !== "string") return false;
8545
8545
  if (value.percent !== void 0 && typeof value.percent !== "number") return false;
8546
8546
  if (value.installable !== void 0 && typeof value.installable !== "boolean") return false;
@@ -8663,51 +8663,65 @@ ABORT_ERR ETIMEDOUT ECONNREFUSED ECONNRESET EPIPE EADDRINUSE ENOSPC EACCES STORE
8663
8663
  }, []);
8664
8664
  const phase = view?.phase ?? "idle";
8665
8665
  const installable = view?.installable === true;
8666
- const primary = () => {
8666
+ const describePhase = () => {
8667
8667
  switch (phase) {
8668
+ case "checking": return {
8669
+ action: null,
8670
+ status: t("update.checking")
8671
+ };
8672
+ case "downloading": return {
8673
+ action: null,
8674
+ status: t("update.downloading").replace("{percent}", String(view?.percent ?? 0))
8675
+ };
8676
+ case "verifying": return {
8677
+ action: null,
8678
+ status: t("update.verifying")
8679
+ };
8680
+ case "installing": return {
8681
+ action: null,
8682
+ status: t("update.installing")
8683
+ };
8684
+ case "ready": {
8685
+ const status = view?.message === "TASKS_ACTIVE" ? t("update.tasksActive") : view?.message === "TASK_STATE_UNAVAILABLE" ? t("update.taskStateUnavailable") : view?.failedOperation === "install" ? t("update.installFailed") : t("update.ready").replace("{version}", view?.version ?? "");
8686
+ return {
8687
+ action: {
8688
+ label: t("update.install"),
8689
+ action: "install"
8690
+ },
8691
+ status
8692
+ };
8693
+ }
8668
8694
  case "available": return installable ? {
8669
- label: t("update.download"),
8670
- action: "download"
8695
+ action: {
8696
+ label: t("update.download"),
8697
+ action: "download"
8698
+ },
8699
+ status: t("update.available").replace("{version}", view?.version ?? "")
8671
8700
  } : {
8672
- label: t("update.check"),
8673
- action: "check"
8674
- };
8675
- case "ready": return {
8676
- label: t("update.install"),
8677
- action: "install"
8701
+ action: {
8702
+ label: t("update.check"),
8703
+ action: "check"
8704
+ },
8705
+ status: t("update.notInRollout").replace("{version}", view?.version ?? "").replace("{percent}", String(view?.stagingPercentage ?? 0))
8678
8706
  };
8679
8707
  case "error": return {
8680
- label: t("update.retry"),
8681
- action: view?.failedOperation === "download" ? "download" : "check"
8708
+ action: {
8709
+ label: t("update.retry"),
8710
+ action: view?.failedOperation === "download" ? "download" : "check"
8711
+ },
8712
+ status: t("update.failed")
8682
8713
  };
8683
- case "checking":
8684
- case "downloading":
8685
- case "verifying":
8686
- case "installing": return null;
8687
8714
  default: return {
8688
- label: t("update.check"),
8689
- action: "check"
8715
+ action: {
8716
+ label: t("update.check"),
8717
+ action: "check"
8718
+ },
8719
+ status: view?.message === "TASKS_ACTIVE" ? t("update.tasksActive") : t("update.upToDate")
8690
8720
  };
8691
8721
  }
8692
8722
  };
8693
8723
  const busyPhase = inProgress(phase);
8694
- const action = primary();
8695
- const statusLine = () => {
8696
- switch (phase) {
8697
- case "checking": return t("update.checking");
8698
- case "downloading": return t("update.downloading").replace("{percent}", String(view?.percent ?? 0));
8699
- case "verifying": return t("update.verifying");
8700
- case "installing": return t("update.installing");
8701
- case "ready":
8702
- if (view?.message === "TASKS_ACTIVE") return t("update.tasksActive");
8703
- if (view?.message === "TASK_STATE_UNAVAILABLE") return t("update.taskStateUnavailable");
8704
- if (view?.failedOperation === "install") return t("update.installFailed");
8705
- return t("update.ready").replace("{version}", view?.version ?? "");
8706
- case "available": return installable ? t("update.available").replace("{version}", view?.version ?? "") : t("update.notInRollout").replace("{version}", view?.version ?? "").replace("{percent}", String(view?.stagingPercentage ?? 0));
8707
- case "error": return t("update.failed");
8708
- default: return view?.message === "TASKS_ACTIVE" ? t("update.tasksActive") : t("update.upToDate");
8709
- }
8710
- };
8724
+ const { action, status } = describePhase();
8711
8725
  const restartNote = phase === "ready" || phase === "installing";
8712
8726
  return h("section", {
8713
8727
  className: "de-update",
@@ -8723,7 +8737,7 @@ ABORT_ERR ETIMEDOUT ECONNREFUSED ECONNRESET EPIPE EADDRINUSE ENOSPC EACCES STORE
8723
8737
  }, action.label)), h("p", {
8724
8738
  className: "de-update-status",
8725
8739
  "data-update-phase": phase
8726
- }, statusLine()), view?.size !== void 0 && phase === "available" ? h("p", { className: "de-update-meta" }, readableSize(view.size)) : null, restartNote ? h("p", {
8740
+ }, status), view?.size !== void 0 && phase === "available" ? h("p", { className: "de-update-meta" }, readableSize(view.size)) : null, restartNote ? h("p", {
8727
8741
  className: "de-update-warning",
8728
8742
  role: "note"
8729
8743
  }, t("update.restartNote")) : null, error === "" ? null : h("p", {
package/lib/index.js CHANGED
@@ -3458,9 +3458,9 @@ function compareVersions(left, right) {
3458
3458
  if (a === null) throw new Error(`INVALID_VERSION:${left}`);
3459
3459
  if (b === null) throw new Error(`INVALID_VERSION:${right}`);
3460
3460
  for (let index = 0; index < 3; index += 1) {
3461
- const left = a.numbers[index] ?? 0;
3462
- const right = b.numbers[index] ?? 0;
3463
- if (left !== right) return left < right ? -1 : 1;
3461
+ const leftPart = a.numbers[index] ?? 0;
3462
+ const rightPart = b.numbers[index] ?? 0;
3463
+ if (leftPart !== rightPart) return leftPart < rightPart ? -1 : 1;
3464
3464
  }
3465
3465
  if (a.pre === null && b.pre === null) return 0;
3466
3466
  if (a.pre === null) return 1;
@@ -3482,7 +3482,8 @@ function compareVersions(left, right) {
3482
3482
  return 0;
3483
3483
  }
3484
3484
  function stagingMatch(updaterId, stagingPercentage) {
3485
- if (stagingPercentage === void 0) return true;
3485
+ if (stagingPercentage === void 0 || stagingPercentage >= 100) return true;
3486
+ if (stagingPercentage <= 0) return false;
3486
3487
  const normalized = (updaterId ?? "").trim();
3487
3488
  const match = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/iu.exec(normalized);
3488
3489
  if (match === null) return true;
@@ -3498,16 +3499,15 @@ function errorCode(error, fallback) {
3498
3499
  return error instanceof Error && /^[A-Z][A-Z0-9_]+$/u.test(error.message) ? error.message : fallback;
3499
3500
  }
3500
3501
  function removeStageDir(target) {
3501
- const proc = process;
3502
- const previous = proc.noAsar;
3503
- proc.noAsar = true;
3502
+ const previous = Reflect.get(process, "noAsar");
3503
+ Reflect.set(process, "noAsar", true);
3504
3504
  try {
3505
3505
  rmSync(target, {
3506
3506
  recursive: true,
3507
3507
  force: true
3508
3508
  });
3509
3509
  } finally {
3510
- proc.noAsar = previous;
3510
+ Reflect.set(process, "noAsar", previous);
3511
3511
  }
3512
3512
  }
3513
3513
  function createUpdateEngine(deps) {
@@ -3518,16 +3518,20 @@ function createUpdateEngine(deps) {
3518
3518
  let feed;
3519
3519
  const lifetime = new AbortController();
3520
3520
  let pending;
3521
+ let pendingOp;
3521
3522
  const set = (next) => state = next;
3522
- function run(action) {
3523
+ function run(op, action) {
3523
3524
  if (lifetime.signal.aborted) return Promise.reject(new Error("UPDATE_CLOSED"));
3524
- if (pending || state.phase === "installing") return Promise.resolve(state);
3525
+ if (pending || state.phase === "installing") return pending ?? Promise.resolve(state);
3526
+ pendingOp = op;
3525
3527
  pending = action().finally(() => {
3526
3528
  pending = void 0;
3529
+ pendingOp = void 0;
3527
3530
  });
3528
3531
  return pending;
3529
3532
  }
3530
3533
  async function check() {
3534
+ if (state.phase === "ready") return state;
3531
3535
  set({
3532
3536
  phase: "checking",
3533
3537
  currentVersion: deps.currentVersion
@@ -3538,13 +3542,15 @@ function createUpdateEngine(deps) {
3538
3542
  const newer = compareVersions(parsed.version, deps.currentVersion) > 0;
3539
3543
  const inRollout = stagingMatch(await deps.readUpdaterId(), parsed.stagingPercentage);
3540
3544
  lifetime.signal.throwIfAborted();
3541
- feed = parsed;
3545
+ feed = newer ? parsed : void 0;
3542
3546
  return set({
3543
3547
  phase: newer ? "available" : "idle",
3544
3548
  currentVersion: deps.currentVersion,
3545
- version: parsed.version,
3546
- releaseDate: parsed.releaseDate,
3547
- size: parsed.size,
3549
+ ...newer ? {
3550
+ version: parsed.version,
3551
+ releaseDate: parsed.releaseDate,
3552
+ size: parsed.size
3553
+ } : {},
3548
3554
  installable: newer && inRollout,
3549
3555
  inRollout,
3550
3556
  stagingPercentage: parsed.stagingPercentage
@@ -3559,11 +3565,10 @@ function createUpdateEngine(deps) {
3559
3565
  }
3560
3566
  }
3561
3567
  async function download() {
3562
- if (!feed || !state.version) throw new Error("NOT_CHECKED");
3563
- if (!state.installable) throw new Error("NOT_IN_ROLLOUT");
3564
3568
  if (state.phase === "ready") return state;
3565
3569
  const entry = feed;
3566
- const version = state.version;
3570
+ if (!entry) throw new Error("NOT_CHECKED");
3571
+ const version = entry.version;
3567
3572
  const archive = join(deps.stageDir, "archive.zip");
3568
3573
  set({
3569
3574
  ...state,
@@ -3627,6 +3632,11 @@ function createUpdateEngine(deps) {
3627
3632
  if (state.phase !== "ready" || !state.version) throw new Error("NOT_READY");
3628
3633
  try {
3629
3634
  if (deps.activeTasks()) throw new Error("TASKS_ACTIVE");
3635
+ set({
3636
+ ...state,
3637
+ failedOperation: void 0,
3638
+ message: void 0
3639
+ });
3630
3640
  await deps.spawnInstaller({
3631
3641
  version: state.version,
3632
3642
  stageDir: deps.stageDir
@@ -3648,16 +3658,27 @@ function createUpdateEngine(deps) {
3648
3658
  }
3649
3659
  return {
3650
3660
  state: () => state,
3651
- check: () => run(check),
3652
- download: () => run(download),
3653
- install: (confirmation) => confirmation?.confirm === true ? run(install) : Promise.reject(new Error("CONFIRMATION_REQUIRED")),
3661
+ check: () => run("check", check),
3662
+ download: () => {
3663
+ if (lifetime.signal.aborted) return Promise.reject(new Error("UPDATE_CLOSED"));
3664
+ if (pendingOp === "download" && pending) return pending;
3665
+ if (state.phase === "ready" || state.phase === "installing") return Promise.resolve(state);
3666
+ if (!feed) return Promise.reject(new Error("NOT_CHECKED"));
3667
+ if (!state.installable) return Promise.reject(new Error("NOT_IN_ROLLOUT"));
3668
+ return run("download", download);
3669
+ },
3670
+ install: (confirmation) => {
3671
+ if (confirmation?.confirm !== true) return Promise.reject(new Error("CONFIRMATION_REQUIRED"));
3672
+ if (lifetime.signal.aborted) return Promise.reject(new Error("UPDATE_CLOSED"));
3673
+ if (pendingOp === "install" && pending) return pending;
3674
+ if (state.phase === "installing") return Promise.resolve(state);
3675
+ if (state.phase !== "ready" || !state.version) return Promise.reject(new Error("NOT_READY"));
3676
+ return run("install", install);
3677
+ },
3654
3678
  async dispose() {
3655
3679
  lifetime.abort();
3656
3680
  await pending?.catch(() => {});
3657
- if (state.phase !== "installing") await rm(deps.stageDir, {
3658
- recursive: true,
3659
- force: true
3660
- });
3681
+ if (state.phase !== "installing") removeStageDir(deps.stageDir);
3661
3682
  }
3662
3683
  };
3663
3684
  }
@@ -3822,10 +3843,9 @@ function productionDeps(ctx, currentVersion, locations = defaultLocations()) {
3822
3843
  const abort = () => finish(new Error("UPDATE_CLOSED"));
3823
3844
  const exit = () => finish(new Error("INSTALLER_EXITED"));
3824
3845
  const message = (value) => {
3825
- if (!value || typeof value !== "object") return;
3826
- const data = value;
3827
- if (data.type === "error") return finish(new Error(typeof data.code === "string" ? data.code : "INSTALLER_FAILED"));
3828
- if (data.type !== "ready") return;
3846
+ if (typeof value !== "object" || value === null || !("type" in value)) return;
3847
+ if (value.type === "error") return finish(new Error("code" in value && typeof value.code === "string" ? value.code : "INSTALLER_FAILED"));
3848
+ if (value.type !== "ready") return;
3829
3849
  try {
3830
3850
  signal.throwIfAborted();
3831
3851
  if (readActiveTasks(ctx)) throw new Error("TASKS_ACTIVE");
package/lib/installer.mjs CHANGED
@@ -69,8 +69,7 @@ async function validate(raw) {
69
69
  return { ...raw, app, stageDir, stagedApp, logDir, backup, failed, installed, stagingDirectory }
70
70
  }
71
71
  async function handoff() {
72
- if (typeof process.send !== 'function') return
73
- if (!process.connected) throw failure('INSTALL_NOT_COMMITTED')
72
+ if (typeof process.send !== 'function' || !process.connected) throw failure('INSTALL_NOT_COMMITTED')
74
73
  await new Promise((resolve, reject) => {
75
74
  const finish = error => {
76
75
  clearTimeout(timer); process.off('message', message); process.off('disconnect', disconnected)
@@ -121,6 +120,11 @@ async function launch(app, port, emit) {
121
120
  } while (Date.now() < deadline)
122
121
  return false
123
122
  }
123
+ async function removeVerifiedStageDir(input) {
124
+ const staging = await lstat(input.stageDir)
125
+ if (staging.dev !== input.stagingDirectory.dev || staging.ino !== input.stagingDirectory.ino || await realpath(input.stageDir) !== input.stageDir) throw failure('INSTALL_FAILED')
126
+ await rm(input.stageDir, { recursive: true })
127
+ }
124
128
  async function install(input, emit) {
125
129
  let backedUp = false, replaced = false, step = 'STOP_FAILED'
126
130
  try {
@@ -144,10 +148,7 @@ async function install(input, emit) {
144
148
  if (replaced) {
145
149
  if (await exists(input.failed)) throw failure('ROLLBACK_RESTORE_FAILED')
146
150
  await rename(input.app, input.failed)
147
- try {
148
- const staging = await lstat(input.stageDir)
149
- if (staging.dev === input.stagingDirectory.dev && staging.ino === input.stagingDirectory.ino && await realpath(input.stageDir) === input.stageDir) await rm(input.stageDir, { recursive: true })
150
- } catch {}
151
+ try { await removeVerifiedStageDir(input) } catch {}
151
152
  }
152
153
  if (backedUp) await rename(input.backup, input.app)
153
154
  } catch { return { ok: false, code: 'ROLLBACK_RESTORE_FAILED' } }
@@ -161,11 +162,7 @@ async function install(input, emit) {
161
162
  if (old.dev !== input.installed.dev || old.ino !== input.installed.ino) throw failure('INSTALL_FAILED')
162
163
  await rm(input.backup, { recursive: true })
163
164
  } catch { emit('BACKUP_CLEANUP_FAILED') }
164
- try {
165
- const staging = await lstat(input.stageDir)
166
- if (staging.dev !== input.stagingDirectory.dev || staging.ino !== input.stagingDirectory.ino || await realpath(input.stageDir) !== input.stageDir) throw failure('INSTALL_FAILED')
167
- await rm(input.stageDir, { recursive: true })
168
- } catch { emit('STAGE_CLEANUP_FAILED') }
165
+ try { await removeVerifiedStageDir(input) } catch { emit('STAGE_CLEANUP_FAILED') }
169
166
  return { ok: true, code: 'INSTALLED' }
170
167
  }
171
168
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-desktop-enhance",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "DSH Desktop 界面增强:页内查找(Cmd+F)、轮次编号、上下文压缩行常显、建议、每步耗时、折叠文件夹状态计数、会话信息(含上下文注入 C1 视图)、工具管理、Skill 管理、独立远程接入与手机体验,以及智能建议、会话能力和远程接入的持久诊断日志。",
5
5
  "type": "module",
6
6
  "icon": "./icon.svg",