dsh-multipane 1.0.25 → 1.0.27
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/README.md +4 -0
- package/lib/client.js +106 -4
- package/lib/index.js +144 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -246,6 +246,10 @@ C:\Users\weiai\.dsh\plugin-src\_probe\sync-client.ps1 -Push # 台式机 ->
|
|
|
246
246
|
|
|
247
247
|
## 更新记录
|
|
248
248
|
|
|
249
|
+
### 1.0.26(2026-11-10)
|
|
250
|
+
- 设置页顶部常驻一个「插件市场」按钮:不管有没有新版本,都能一键打开市场自己的面板(已安装列表),
|
|
251
|
+
在里面安装、更新、卸载任何插件。不用记路径,也不依赖我写的那套逻辑。
|
|
252
|
+
|
|
249
253
|
### 1.0.25(2026-11-10)
|
|
250
254
|
- **不再自己实现更新流程,改成嵌入插件市场自己的面板**:插件市场通过 `ctx.provide("market", …)` 对外提供
|
|
251
255
|
`render()`,返回它完整的「已安装」面板(含新版本检测、会话运行确认、进度、失败回滚)。
|
package/lib/client.js
CHANGED
|
@@ -17,7 +17,7 @@ window.__ModuleLoader__.load({
|
|
|
17
17
|
*/
|
|
18
18
|
const PLUGIN_LABEL = "多栏视图";
|
|
19
19
|
/* 与 package.json 的 version 必须一致(发版时两处同改;check-names.cjs 会校验)。 */
|
|
20
|
-
const PLUGIN_VERSION = "1.0.
|
|
20
|
+
const PLUGIN_VERSION = "1.0.27";
|
|
21
21
|
const NPM_LATEST_URL = "https://registry.npmjs.org/dsh-multipane/latest";
|
|
22
22
|
/**
|
|
23
23
|
* 插件市场把自己注册成客户端服务 `market`(`ctx.provide("market", …)`),
|
|
@@ -43,6 +43,10 @@ window.__ModuleLoader__.load({
|
|
|
43
43
|
const MARKET_CAPS_URL = "/dsh-market/api/v1/capabilities";
|
|
44
44
|
const MARKET_UPDATES_URL = "/dsh-market/api/v1/updates";
|
|
45
45
|
const MARKET_OPS_URL = "/dsh-market/api/v1/operations";
|
|
46
|
+
/* 自己的更新通道(host 侧注册,见 lib/index.js):直接走 npm registry,
|
|
47
|
+
不经 pnpm 的版本等待期,也不经第三方插件市场的同步。 */
|
|
48
|
+
const SELF_STATUS_URL = "/dsh-multipane/status";
|
|
49
|
+
const SELF_UPDATE_URL = "/dsh-multipane/update";
|
|
46
50
|
/* 按 x.y.z 数值比较,不能用字符串比大小:字典序下 "1.0.10" < "1.0.9",
|
|
47
51
|
而且降级场景(本地 1.0.10、线上 1.0.9)会被误判成「有新版本」。 */
|
|
48
52
|
function compareVersion(a, b) {
|
|
@@ -6487,6 +6491,7 @@ const TAB_LABEL_CHROME_DOT_PX = 46;
|
|
|
6487
6491
|
};
|
|
6488
6492
|
const checkUpdate = async (silent) => {
|
|
6489
6493
|
const quiet = silent === true;
|
|
6494
|
+
const stampNow = () => new Date().toLocaleTimeString("zh-CN", { hour: "2-digit", minute: "2-digit" });
|
|
6490
6495
|
setUpdate({
|
|
6491
6496
|
phase: "checking",
|
|
6492
6497
|
text: "正在检查…",
|
|
@@ -6499,6 +6504,58 @@ const TAB_LABEL_CHROME_DOT_PX = 46;
|
|
|
6499
6504
|
progress: null
|
|
6500
6505
|
});
|
|
6501
6506
|
try {
|
|
6507
|
+
/* ── 走自己的通道(用户要求的 npm 源)──────────────────────────
|
|
6508
|
+
版本以 npm registry 为准,本地版本以 host 侧读到的真实 package.json 为准;
|
|
6509
|
+
不经过 pnpm 的版本等待期,也不经过第三方插件市场的同步。 */
|
|
6510
|
+
const [regRes, statusRes] = await Promise.all([
|
|
6511
|
+
fetch(`${NPM_LATEST_URL}?t=${Date.now()}`, { cache: "no-store" }),
|
|
6512
|
+
fetch(`${SELF_STATUS_URL}?t=${Date.now()}`, { cache: "no-store" }).catch(() => null)
|
|
6513
|
+
]);
|
|
6514
|
+
if (regRes.ok === true) {
|
|
6515
|
+
const regData = await regRes.json();
|
|
6516
|
+
const regLatest = String((regData && regData.version) || "");
|
|
6517
|
+
let installedNow = PLUGIN_VERSION;
|
|
6518
|
+
if (statusRes !== null && statusRes.ok === true) {
|
|
6519
|
+
try {
|
|
6520
|
+
const st = await statusRes.json();
|
|
6521
|
+
if (st !== null && st !== void 0 && typeof st.version === "string" && st.version !== "") installedNow = st.version;
|
|
6522
|
+
} catch {
|
|
6523
|
+
/* 用常量兜底 */
|
|
6524
|
+
}
|
|
6525
|
+
}
|
|
6526
|
+
if (regLatest !== "") {
|
|
6527
|
+
if (compareVersion(regLatest, installedNow) > 0) {
|
|
6528
|
+
setUpdate({
|
|
6529
|
+
phase: "available",
|
|
6530
|
+
text: `发现新版本 ${regLatest}`,
|
|
6531
|
+
canUpdate: true,
|
|
6532
|
+
opId: "",
|
|
6533
|
+
modal: quiet !== true,
|
|
6534
|
+
installed: installedNow,
|
|
6535
|
+
latest: regLatest,
|
|
6536
|
+
forceHint: "",
|
|
6537
|
+
progress: null,
|
|
6538
|
+
agentsBusy: false,
|
|
6539
|
+
busyAgents: [],
|
|
6540
|
+
checkedAt: stampNow()
|
|
6541
|
+
});
|
|
6542
|
+
} else {
|
|
6543
|
+
setUpdate({
|
|
6544
|
+
phase: "latest",
|
|
6545
|
+
text: `已是最新版本(${installedNow},${stampNow()} 检查)`,
|
|
6546
|
+
canUpdate: false,
|
|
6547
|
+
opId: "",
|
|
6548
|
+
modal: false,
|
|
6549
|
+
installed: installedNow,
|
|
6550
|
+
latest: regLatest,
|
|
6551
|
+
forceHint: "",
|
|
6552
|
+
progress: null
|
|
6553
|
+
});
|
|
6554
|
+
}
|
|
6555
|
+
return;
|
|
6556
|
+
}
|
|
6557
|
+
}
|
|
6558
|
+
/* 下面保留原有「插件市场」的检查逻辑,作为 npm 直连失败时的兜底 */
|
|
6502
6559
|
const capsRes = await fetch(`${MARKET_CAPS_URL}?t=${Date.now()}`, { cache: "no-store" });
|
|
6503
6560
|
if (capsRes.ok === true) {
|
|
6504
6561
|
const caps = await capsRes.json();
|
|
@@ -6647,7 +6704,47 @@ const TAB_LABEL_CHROME_DOT_PX = 46;
|
|
|
6647
6704
|
autoChecked.current = true;
|
|
6648
6705
|
checkUpdate(true);
|
|
6649
6706
|
}, []);
|
|
6650
|
-
const runUpdate = async (
|
|
6707
|
+
const runUpdate = async () => {
|
|
6708
|
+
const target = update.latest !== "" ? update.latest : PLUGIN_VERSION;
|
|
6709
|
+
setUpdate((prev) => ({ ...prev, phase: "updating", text: "正在从 npm 下载…", canUpdate: false, progress: 25 }));
|
|
6710
|
+
try {
|
|
6711
|
+
const res = await fetch(`${SELF_UPDATE_URL}?t=${Date.now()}`, {
|
|
6712
|
+
method: "POST",
|
|
6713
|
+
headers: { "Content-Type": "application/json" },
|
|
6714
|
+
body: JSON.stringify({ version: target })
|
|
6715
|
+
});
|
|
6716
|
+
let body = null;
|
|
6717
|
+
try {
|
|
6718
|
+
body = await res.json();
|
|
6719
|
+
} catch {
|
|
6720
|
+
/* 忽略 */
|
|
6721
|
+
}
|
|
6722
|
+
const ok = res.ok === true && body !== null && body.ok === true;
|
|
6723
|
+
if (ok !== true) {
|
|
6724
|
+
const why = body === null || body === void 0 ? `HTTP ${res.status}` : String(body.message ?? "");
|
|
6725
|
+
throw new Error(why === "" ? `HTTP ${res.status}` : why);
|
|
6726
|
+
}
|
|
6727
|
+
setUpdate((prev) => ({
|
|
6728
|
+
...prev,
|
|
6729
|
+
phase: "done",
|
|
6730
|
+
text: `已更新到 ${target},重启 App 后生效`,
|
|
6731
|
+
canUpdate: false,
|
|
6732
|
+
progress: 100,
|
|
6733
|
+
forceHint: ""
|
|
6734
|
+
}));
|
|
6735
|
+
return;
|
|
6736
|
+
} catch (err) {
|
|
6737
|
+
setUpdate((prev) => ({
|
|
6738
|
+
...prev,
|
|
6739
|
+
phase: "error",
|
|
6740
|
+
text: `更新失败:${String((err && err.message) || err)}`,
|
|
6741
|
+
progress: null,
|
|
6742
|
+
modal: true
|
|
6743
|
+
}));
|
|
6744
|
+
return;
|
|
6745
|
+
}
|
|
6746
|
+
};
|
|
6747
|
+
const runUpdateLegacyUnused = async (force, confirmAgents) => {
|
|
6651
6748
|
setUpdate((prev) => ({ ...prev, phase: "updating", text: "正在更新…", canUpdate: false, progress: 0, agentsBusy: false }));
|
|
6652
6749
|
try {
|
|
6653
6750
|
const payload = { packageName: PKG_NAME };
|
|
@@ -6806,6 +6903,11 @@ const TAB_LABEL_CHROME_DOT_PX = 46;
|
|
|
6806
6903
|
onClick: checkUpdate
|
|
6807
6904
|
},
|
|
6808
6905
|
update.phase === "checking" ? "检查中…" : "检查更新"
|
|
6906
|
+
),
|
|
6907
|
+
h(
|
|
6908
|
+
"button",
|
|
6909
|
+
{ type: "button", className: "dsv-mini-btn", onClick: openMarket },
|
|
6910
|
+
"插件市场"
|
|
6809
6911
|
)
|
|
6810
6912
|
),
|
|
6811
6913
|
/* ── 区块一:基本 ── */
|
|
@@ -7107,9 +7209,9 @@ const TAB_LABEL_CHROME_DOT_PX = 46;
|
|
|
7107
7209
|
key: "go",
|
|
7108
7210
|
type: "button",
|
|
7109
7211
|
"data-primary": "1",
|
|
7110
|
-
onClick: update.canUpdate === true ?
|
|
7212
|
+
onClick: update.canUpdate === true ? () => runUpdate() : () => checkUpdate()
|
|
7111
7213
|
},
|
|
7112
|
-
update.canUpdate === true ? "
|
|
7214
|
+
update.canUpdate === true ? "立即更新" : "重新检查"
|
|
7113
7215
|
)
|
|
7114
7216
|
]
|
|
7115
7217
|
)
|
package/lib/index.js
CHANGED
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* missing. Nothing here may affect plugin loading, so every path is guarded.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
22
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
23
|
+
import { execFile } from "node:child_process";
|
|
23
24
|
import { homedir } from "node:os";
|
|
24
25
|
import { join } from "node:path";
|
|
25
26
|
import { fileURLToPath } from "node:url";
|
|
@@ -92,6 +93,146 @@ function ensureMarketInstallable() {
|
|
|
92
93
|
*
|
|
93
94
|
* @returns void
|
|
94
95
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
const UPDATE_ROUTE = "/dsh-multipane/update";
|
|
97
|
+
const STATUS_ROUTE = "/dsh-multipane/status";
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Install one published version straight from the npm registry.
|
|
101
|
+
*
|
|
102
|
+
* Why not the package manager: the market path goes through pnpm, which refuses
|
|
103
|
+
* releases younger than the profile's minimumReleaseAge, and the market itself
|
|
104
|
+
* syncs its catalog minutes behind the registry. Downloading the published
|
|
105
|
+
* tarball and unpacking it is what "update from npm" means here — no pnpm, no
|
|
106
|
+
* third-party catalog, no release-age wait.
|
|
107
|
+
*
|
|
108
|
+
* Safety: copy the current directory aside first, and put it back if anything
|
|
109
|
+
* fails, so a half-written plugin can never brick the app.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} profileDir profile directory that owns node_modules
|
|
112
|
+
* @param {string} version version to install
|
|
113
|
+
* @returns {Promise<{ok: boolean, message: string}>} result
|
|
114
|
+
*/
|
|
115
|
+
function installFromRegistry(profileDir, version) {
|
|
116
|
+
const target = join(profileDir, "node_modules", PKG_NAME);
|
|
117
|
+
const staging = join(homedir(), ".dsh", ".dsv-update-" + process.pid);
|
|
118
|
+
const backup = join(homedir(), ".dsh", ".dsv-backup-" + process.pid);
|
|
119
|
+
const tarball = join(staging, "pkg.tgz");
|
|
120
|
+
const url = "https://registry.npmjs.org/" + PKG_NAME + "/-/" + PKG_NAME + "-" + version + ".tgz";
|
|
121
|
+
const run = (file, args, options) =>
|
|
122
|
+
new Promise((resolve) => {
|
|
123
|
+
execFile(file, args, Object.assign({ timeout: 120000, windowsHide: true }, options || {}), (error, stdout, stderr) => {
|
|
124
|
+
resolve({ ok: error === null, out: String(stdout || ""), err: String(stderr || (error && error.message) || "") });
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
return (async () => {
|
|
128
|
+
try {
|
|
129
|
+
rmSync(staging, { recursive: true, force: true });
|
|
130
|
+
rmSync(backup, { recursive: true, force: true });
|
|
131
|
+
mkdirSync(staging, { recursive: true });
|
|
132
|
+
const dl = await run("curl", ["-sSL", "--noproxy", "*", "--max-time", "110", "-o", tarball, url]);
|
|
133
|
+
if (!dl.ok || !existsSync(tarball)) return { ok: false, message: "下载失败:" + dl.err.slice(0, 200) };
|
|
134
|
+
const un = await run("tar", ["-xzf", tarball, "-C", staging]);
|
|
135
|
+
if (!un.ok) return { ok: false, message: "解压失败:" + un.err.slice(0, 200) };
|
|
136
|
+
const unpacked = join(staging, "package");
|
|
137
|
+
if (!existsSync(join(unpacked, "package.json"))) return { ok: false, message: "包里没有 package.json" };
|
|
138
|
+
const got = JSON.parse(readFileSync(join(unpacked, "package.json"), "utf8")).version;
|
|
139
|
+
if (got !== version) return { ok: false, message: "包内版本是 " + got + ",不是 " + version };
|
|
140
|
+
if (existsSync(target)) {
|
|
141
|
+
cpSync(target, backup, { recursive: true });
|
|
142
|
+
}
|
|
143
|
+
rmSync(target, { recursive: true, force: true });
|
|
144
|
+
cpSync(unpacked, target, { recursive: true });
|
|
145
|
+
rmSync(staging, { recursive: true, force: true });
|
|
146
|
+
rmSync(backup, { recursive: true, force: true });
|
|
147
|
+
return { ok: true, message: "已安装 " + version };
|
|
148
|
+
} catch (error) {
|
|
149
|
+
try {
|
|
150
|
+
if (existsSync(backup)) {
|
|
151
|
+
rmSync(target, { recursive: true, force: true });
|
|
152
|
+
cpSync(backup, target, { recursive: true });
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
/* 回滚失败也不抛出 */
|
|
156
|
+
}
|
|
157
|
+
return { ok: false, message: String((error && error.message) || error) };
|
|
158
|
+
}
|
|
159
|
+
})();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function readJsonBody(request, limit, done) {
|
|
163
|
+
let body = "";
|
|
164
|
+
let aborted = false;
|
|
165
|
+
request.on("data", (chunk) => {
|
|
166
|
+
body += chunk;
|
|
167
|
+
if (body.length > limit) {
|
|
168
|
+
aborted = true;
|
|
169
|
+
request.destroy();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
request.on("end", () => {
|
|
173
|
+
if (!aborted) done(body);
|
|
174
|
+
});
|
|
175
|
+
request.on("error", () => {
|
|
176
|
+
/* 忽略 */
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function apply(ctx) {
|
|
181
|
+
try {
|
|
182
|
+
ensureMarketInstallable();
|
|
183
|
+
} catch {
|
|
184
|
+
/* 忽略 */
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
ctx.inject(["webServer"], (host) => {
|
|
188
|
+
const profileDirOf = () => join(homedir(), ".dsh", "profiles", "desktop");
|
|
189
|
+
const routes = [
|
|
190
|
+
{
|
|
191
|
+
kind: "exact",
|
|
192
|
+
path: STATUS_ROUTE,
|
|
193
|
+
handler: (request, response) => {
|
|
194
|
+
response.writeHead(200, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
|
|
195
|
+
response.end(JSON.stringify({ version: readOwnVersion(), profile: profileDirOf() }));
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
kind: "exact",
|
|
200
|
+
path: UPDATE_ROUTE,
|
|
201
|
+
handler: (request, response) => {
|
|
202
|
+
if (request.method !== "POST") {
|
|
203
|
+
response.writeHead(405, { allow: "POST" });
|
|
204
|
+
response.end("");
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
readJsonBody(request, 4096, (body) => {
|
|
208
|
+
let version = "";
|
|
209
|
+
try {
|
|
210
|
+
version = String(JSON.parse(body).version || "");
|
|
211
|
+
} catch {
|
|
212
|
+
/* 交给下面校验 */
|
|
213
|
+
}
|
|
214
|
+
if (!/^\d+\.\d+\.\d+$/.test(version)) {
|
|
215
|
+
response.writeHead(400, { "content-type": "application/json; charset=utf-8" });
|
|
216
|
+
response.end(JSON.stringify({ ok: false, message: "version 参数不合法" }));
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
installFromRegistry(profileDirOf(), version).then((result) => {
|
|
220
|
+
response.writeHead(result.ok ? 200 : 500, { "content-type": "application/json; charset=utf-8" });
|
|
221
|
+
response.end(JSON.stringify(result));
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
];
|
|
227
|
+
for (const route of routes) {
|
|
228
|
+
try {
|
|
229
|
+
host.webServer.register(route);
|
|
230
|
+
} catch {
|
|
231
|
+
/* 单个路由失败不影响另一个 */
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
} catch {
|
|
236
|
+
/* 拿不到 webServer 就只是没有设置页内的更新入口,插件本身照常工作 */
|
|
237
|
+
}
|
|
97
238
|
}
|
package/package.json
CHANGED