dsh-desktop-enhance 0.9.1 → 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 +56 -42
- package/lib/index.js +65 -38
- package/lib/installer.mjs +9 -11
- package/package.json +1 -1
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
|
|
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
|
|
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
|
|
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 (!
|
|
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
|
|
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
|
-
|
|
8670
|
-
|
|
8695
|
+
action: {
|
|
8696
|
+
label: t("update.download"),
|
|
8697
|
+
action: "download"
|
|
8698
|
+
},
|
|
8699
|
+
status: t("update.available").replace("{version}", view?.version ?? "")
|
|
8671
8700
|
} : {
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
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
|
-
|
|
8681
|
-
|
|
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
|
-
|
|
8689
|
-
|
|
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 =
|
|
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
|
-
},
|
|
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
|
@@ -4,7 +4,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import * as nodeInspector from "node:inspector";
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
|
-
import { createWriteStream } from "node:fs";
|
|
7
|
+
import { createWriteStream, rmSync } from "node:fs";
|
|
8
8
|
import { mkdir, readFile, realpath, rm } from "node:fs/promises";
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
10
|
import { basename, dirname, join } from "node:path";
|
|
@@ -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
|
|
3462
|
-
const
|
|
3463
|
-
if (
|
|
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;
|
|
@@ -3497,6 +3498,18 @@ const FEED_URL = "https://download.deepseek.com/dsh-desk/feeds/mac-arm64/nightly
|
|
|
3497
3498
|
function errorCode(error, fallback) {
|
|
3498
3499
|
return error instanceof Error && /^[A-Z][A-Z0-9_]+$/u.test(error.message) ? error.message : fallback;
|
|
3499
3500
|
}
|
|
3501
|
+
function removeStageDir(target) {
|
|
3502
|
+
const previous = Reflect.get(process, "noAsar");
|
|
3503
|
+
Reflect.set(process, "noAsar", true);
|
|
3504
|
+
try {
|
|
3505
|
+
rmSync(target, {
|
|
3506
|
+
recursive: true,
|
|
3507
|
+
force: true
|
|
3508
|
+
});
|
|
3509
|
+
} finally {
|
|
3510
|
+
Reflect.set(process, "noAsar", previous);
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3500
3513
|
function createUpdateEngine(deps) {
|
|
3501
3514
|
let state = {
|
|
3502
3515
|
phase: "idle",
|
|
@@ -3505,16 +3518,20 @@ function createUpdateEngine(deps) {
|
|
|
3505
3518
|
let feed;
|
|
3506
3519
|
const lifetime = new AbortController();
|
|
3507
3520
|
let pending;
|
|
3521
|
+
let pendingOp;
|
|
3508
3522
|
const set = (next) => state = next;
|
|
3509
|
-
function run(action) {
|
|
3523
|
+
function run(op, action) {
|
|
3510
3524
|
if (lifetime.signal.aborted) return Promise.reject(new Error("UPDATE_CLOSED"));
|
|
3511
|
-
if (pending || state.phase === "installing") return Promise.resolve(state);
|
|
3525
|
+
if (pending || state.phase === "installing") return pending ?? Promise.resolve(state);
|
|
3526
|
+
pendingOp = op;
|
|
3512
3527
|
pending = action().finally(() => {
|
|
3513
3528
|
pending = void 0;
|
|
3529
|
+
pendingOp = void 0;
|
|
3514
3530
|
});
|
|
3515
3531
|
return pending;
|
|
3516
3532
|
}
|
|
3517
3533
|
async function check() {
|
|
3534
|
+
if (state.phase === "ready") return state;
|
|
3518
3535
|
set({
|
|
3519
3536
|
phase: "checking",
|
|
3520
3537
|
currentVersion: deps.currentVersion
|
|
@@ -3525,13 +3542,15 @@ function createUpdateEngine(deps) {
|
|
|
3525
3542
|
const newer = compareVersions(parsed.version, deps.currentVersion) > 0;
|
|
3526
3543
|
const inRollout = stagingMatch(await deps.readUpdaterId(), parsed.stagingPercentage);
|
|
3527
3544
|
lifetime.signal.throwIfAborted();
|
|
3528
|
-
feed = parsed;
|
|
3545
|
+
feed = newer ? parsed : void 0;
|
|
3529
3546
|
return set({
|
|
3530
3547
|
phase: newer ? "available" : "idle",
|
|
3531
3548
|
currentVersion: deps.currentVersion,
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3549
|
+
...newer ? {
|
|
3550
|
+
version: parsed.version,
|
|
3551
|
+
releaseDate: parsed.releaseDate,
|
|
3552
|
+
size: parsed.size
|
|
3553
|
+
} : {},
|
|
3535
3554
|
installable: newer && inRollout,
|
|
3536
3555
|
inRollout,
|
|
3537
3556
|
stagingPercentage: parsed.stagingPercentage
|
|
@@ -3546,11 +3565,10 @@ function createUpdateEngine(deps) {
|
|
|
3546
3565
|
}
|
|
3547
3566
|
}
|
|
3548
3567
|
async function download() {
|
|
3549
|
-
if (!feed || !state.version) throw new Error("NOT_CHECKED");
|
|
3550
|
-
if (!state.installable) throw new Error("NOT_IN_ROLLOUT");
|
|
3551
3568
|
if (state.phase === "ready") return state;
|
|
3552
3569
|
const entry = feed;
|
|
3553
|
-
|
|
3570
|
+
if (!entry) throw new Error("NOT_CHECKED");
|
|
3571
|
+
const version = entry.version;
|
|
3554
3572
|
const archive = join(deps.stageDir, "archive.zip");
|
|
3555
3573
|
set({
|
|
3556
3574
|
...state,
|
|
@@ -3562,10 +3580,7 @@ function createUpdateEngine(deps) {
|
|
|
3562
3580
|
try {
|
|
3563
3581
|
if (!entry.url) throw new Error("FEED_WITHOUT_URL");
|
|
3564
3582
|
if (!entry.sha512) throw new Error("FEED_WITHOUT_SHA512");
|
|
3565
|
-
|
|
3566
|
-
recursive: true,
|
|
3567
|
-
force: true
|
|
3568
|
-
});
|
|
3583
|
+
removeStageDir(deps.stageDir);
|
|
3569
3584
|
await mkdir(deps.stageDir, {
|
|
3570
3585
|
recursive: true,
|
|
3571
3586
|
mode: 448
|
|
@@ -3595,10 +3610,7 @@ function createUpdateEngine(deps) {
|
|
|
3595
3610
|
});
|
|
3596
3611
|
} catch (error) {
|
|
3597
3612
|
try {
|
|
3598
|
-
|
|
3599
|
-
recursive: true,
|
|
3600
|
-
force: true
|
|
3601
|
-
});
|
|
3613
|
+
removeStageDir(deps.stageDir);
|
|
3602
3614
|
} catch {
|
|
3603
3615
|
return set({
|
|
3604
3616
|
...state,
|
|
@@ -3620,6 +3632,11 @@ function createUpdateEngine(deps) {
|
|
|
3620
3632
|
if (state.phase !== "ready" || !state.version) throw new Error("NOT_READY");
|
|
3621
3633
|
try {
|
|
3622
3634
|
if (deps.activeTasks()) throw new Error("TASKS_ACTIVE");
|
|
3635
|
+
set({
|
|
3636
|
+
...state,
|
|
3637
|
+
failedOperation: void 0,
|
|
3638
|
+
message: void 0
|
|
3639
|
+
});
|
|
3623
3640
|
await deps.spawnInstaller({
|
|
3624
3641
|
version: state.version,
|
|
3625
3642
|
stageDir: deps.stageDir
|
|
@@ -3641,16 +3658,27 @@ function createUpdateEngine(deps) {
|
|
|
3641
3658
|
}
|
|
3642
3659
|
return {
|
|
3643
3660
|
state: () => state,
|
|
3644
|
-
check: () => run(check),
|
|
3645
|
-
download: () =>
|
|
3646
|
-
|
|
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
|
+
},
|
|
3647
3678
|
async dispose() {
|
|
3648
3679
|
lifetime.abort();
|
|
3649
3680
|
await pending?.catch(() => {});
|
|
3650
|
-
if (state.phase !== "installing")
|
|
3651
|
-
recursive: true,
|
|
3652
|
-
force: true
|
|
3653
|
-
});
|
|
3681
|
+
if (state.phase !== "installing") removeStageDir(deps.stageDir);
|
|
3654
3682
|
}
|
|
3655
3683
|
};
|
|
3656
3684
|
}
|
|
@@ -3789,7 +3817,8 @@ function productionDeps(ctx, currentVersion, locations = defaultLocations()) {
|
|
|
3789
3817
|
cwd: dirname(app),
|
|
3790
3818
|
env: {
|
|
3791
3819
|
...process.env,
|
|
3792
|
-
ELECTRON_RUN_AS_NODE: "1"
|
|
3820
|
+
ELECTRON_RUN_AS_NODE: "1",
|
|
3821
|
+
ELECTRON_NO_ASAR: "1"
|
|
3793
3822
|
}
|
|
3794
3823
|
});
|
|
3795
3824
|
let settled = false;
|
|
@@ -3814,10 +3843,9 @@ function productionDeps(ctx, currentVersion, locations = defaultLocations()) {
|
|
|
3814
3843
|
const abort = () => finish(new Error("UPDATE_CLOSED"));
|
|
3815
3844
|
const exit = () => finish(new Error("INSTALLER_EXITED"));
|
|
3816
3845
|
const message = (value) => {
|
|
3817
|
-
if (
|
|
3818
|
-
|
|
3819
|
-
if (
|
|
3820
|
-
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;
|
|
3821
3849
|
try {
|
|
3822
3850
|
signal.throwIfAborted();
|
|
3823
3851
|
if (readActiveTasks(ctx)) throw new Error("TASKS_ACTIVE");
|
|
@@ -3847,10 +3875,9 @@ function json(body, status = 200) {
|
|
|
3847
3875
|
}
|
|
3848
3876
|
function registerUpdateRoute(ctx, load = async () => {
|
|
3849
3877
|
const locations = defaultLocations();
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
}).catch(() => {});
|
|
3878
|
+
try {
|
|
3879
|
+
removeStageDir(locations.stageDir);
|
|
3880
|
+
} catch {}
|
|
3854
3881
|
return createUpdateEngine(productionDeps(ctx, await readInstalledVersion(locations.app), locations));
|
|
3855
3882
|
}) {
|
|
3856
3883
|
const connection = ctx.get("connection");
|
package/lib/installer.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { spawn } from 'node:child_process'
|
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'
|
|
5
5
|
import { fileURLToPath } from 'node:url'
|
|
6
6
|
|
|
7
|
+
process.noAsar = true
|
|
7
8
|
const CODES = new Set(['INVALID_INPUT', 'INVALID_VERSION', 'INVALID_PATH', 'APP_MISSING', 'STAGED_MISSING', 'STAGED_VERSION_MISMATCH', 'STAGING_CROSS_DEVICE', 'SIGNATURE_IDENTITY_UNAVAILABLE', 'INSTALLED_SIGNATURE_INVALID', 'STAGED_SIGNATURE_INVALID', 'BACKUP_EXISTS', 'FAILED_EXISTS', 'LOG_UNAVAILABLE', 'IPC_FAILED', 'INSTALL_NOT_COMMITTED', 'COMMIT_TIMEOUT', 'INVALID_COMMIT', 'APP_QUERY_FAILED', 'APP_DID_NOT_EXIT', 'STOP_FAILED', 'BACKUP_FAILED', 'REPLACE_FAILED', 'NEW_APP_NOT_READY', 'ROLLED_BACK', 'ROLLBACK_STOP_FAILED', 'ROLLBACK_RESTORE_FAILED', 'ROLLBACK_LAUNCH_FAILED', 'INSTALL_FAILED'])
|
|
8
9
|
const failure = code => Object.assign(new Error(code), { code })
|
|
9
10
|
const errorCode = (error, fallback = 'INSTALL_FAILED') => CODES.has(error?.code) ? error.code : fallback
|
|
@@ -68,8 +69,7 @@ async function validate(raw) {
|
|
|
68
69
|
return { ...raw, app, stageDir, stagedApp, logDir, backup, failed, installed, stagingDirectory }
|
|
69
70
|
}
|
|
70
71
|
async function handoff() {
|
|
71
|
-
if (typeof process.send !== 'function')
|
|
72
|
-
if (!process.connected) throw failure('INSTALL_NOT_COMMITTED')
|
|
72
|
+
if (typeof process.send !== 'function' || !process.connected) throw failure('INSTALL_NOT_COMMITTED')
|
|
73
73
|
await new Promise((resolve, reject) => {
|
|
74
74
|
const finish = error => {
|
|
75
75
|
clearTimeout(timer); process.off('message', message); process.off('disconnect', disconnected)
|
|
@@ -120,6 +120,11 @@ async function launch(app, port, emit) {
|
|
|
120
120
|
} while (Date.now() < deadline)
|
|
121
121
|
return false
|
|
122
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
|
+
}
|
|
123
128
|
async function install(input, emit) {
|
|
124
129
|
let backedUp = false, replaced = false, step = 'STOP_FAILED'
|
|
125
130
|
try {
|
|
@@ -143,10 +148,7 @@ async function install(input, emit) {
|
|
|
143
148
|
if (replaced) {
|
|
144
149
|
if (await exists(input.failed)) throw failure('ROLLBACK_RESTORE_FAILED')
|
|
145
150
|
await rename(input.app, input.failed)
|
|
146
|
-
try {
|
|
147
|
-
const staging = await lstat(input.stageDir)
|
|
148
|
-
if (staging.dev === input.stagingDirectory.dev && staging.ino === input.stagingDirectory.ino && await realpath(input.stageDir) === input.stageDir) await rm(input.stageDir, { recursive: true })
|
|
149
|
-
} catch {}
|
|
151
|
+
try { await removeVerifiedStageDir(input) } catch {}
|
|
150
152
|
}
|
|
151
153
|
if (backedUp) await rename(input.backup, input.app)
|
|
152
154
|
} catch { return { ok: false, code: 'ROLLBACK_RESTORE_FAILED' } }
|
|
@@ -160,11 +162,7 @@ async function install(input, emit) {
|
|
|
160
162
|
if (old.dev !== input.installed.dev || old.ino !== input.installed.ino) throw failure('INSTALL_FAILED')
|
|
161
163
|
await rm(input.backup, { recursive: true })
|
|
162
164
|
} catch { emit('BACKUP_CLEANUP_FAILED') }
|
|
163
|
-
try {
|
|
164
|
-
const staging = await lstat(input.stageDir)
|
|
165
|
-
if (staging.dev !== input.stagingDirectory.dev || staging.ino !== input.stagingDirectory.ino || await realpath(input.stageDir) !== input.stageDir) throw failure('INSTALL_FAILED')
|
|
166
|
-
await rm(input.stageDir, { recursive: true })
|
|
167
|
-
} catch { emit('STAGE_CLEANUP_FAILED') }
|
|
165
|
+
try { await removeVerifiedStageDir(input) } catch { emit('STAGE_CLEANUP_FAILED') }
|
|
168
166
|
return { ok: true, code: 'INSTALLED' }
|
|
169
167
|
}
|
|
170
168
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-desktop-enhance",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "DSH Desktop 界面增强:页内查找(Cmd+F)、轮次编号、上下文压缩行常显、建议、每步耗时、折叠文件夹状态计数、会话信息(含上下文注入 C1 视图)、工具管理、Skill 管理、独立远程接入与手机体验,以及智能建议、会话能力和远程接入的持久诊断日志。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"icon": "./icon.svg",
|