@ququ-jiaxk/dsh-plugin-center 0.1.36 → 0.1.38
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 +14 -1
- package/lib/index.js +61 -1
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -30,7 +30,7 @@ __export(client_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(client_exports);
|
|
31
31
|
var import_react = require("react");
|
|
32
32
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
var PLUGIN_VERSION = true ? "0.1.
|
|
33
|
+
var PLUGIN_VERSION = true ? "0.1.38" : "0.0.0";
|
|
34
34
|
var PANEL_ID = "plugin-center";
|
|
35
35
|
var inject = ["slots", "remote", "remote.pluginManager"];
|
|
36
36
|
var hostCtx = null;
|
|
@@ -298,6 +298,19 @@ function Panel() {
|
|
|
298
298
|
if (manual) setError("\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
299
299
|
return;
|
|
300
300
|
}
|
|
301
|
+
if (result.status === "unsupported") {
|
|
302
|
+
setSelfUpdate({ phase: "idle" });
|
|
303
|
+
if (manual) {
|
|
304
|
+
setDialog({
|
|
305
|
+
title: "\u5F53\u524D DSH \u7248\u672C\u4E0D\u652F\u6301\u81EA\u66F4\u65B0",
|
|
306
|
+
description: String(result.hint ?? ""),
|
|
307
|
+
input: false,
|
|
308
|
+
confirmLabel: "\u77E5\u9053\u4E86",
|
|
309
|
+
action: async () => void 0
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
301
314
|
if (result.status === "available" && result.latest) {
|
|
302
315
|
setSelfUpdate({ phase: "available", to: result.latest });
|
|
303
316
|
if (manual) setNotice(`\u53D1\u73B0\u65B0\u7248\u672C v${result.latest}`);
|
package/lib/index.js
CHANGED
|
@@ -170,6 +170,28 @@ async function findSelfBundle(manager) {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
/** 自更新依赖 DSH 0.2.x 的 listVersions / updateBundle;旧版管理器没有这两个方法。 */
|
|
174
|
+
function selfUpdateCapability(manager) {
|
|
175
|
+
if (!manager) return { supported: false, reason: 'no-manager' }
|
|
176
|
+
if (typeof manager.listVersions !== 'function' || typeof manager.updateBundle !== 'function') {
|
|
177
|
+
return { supported: false, reason: 'dsh-version' }
|
|
178
|
+
}
|
|
179
|
+
return { supported: true }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function selfUpdateUnsupportedInfo(reason) {
|
|
183
|
+
if (reason === 'no-manager') {
|
|
184
|
+
return {
|
|
185
|
+
reason: 'no-manager',
|
|
186
|
+
hint: 'DSH 插件管理器不可用(当前不是 profile 模式),无法自更新。',
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
reason: 'dsh-version',
|
|
191
|
+
hint: '当前 DSH 版本不支持面板自更新(插件管理器缺少 listVersions / updateBundle)。请先把 DSH 升级到 0.2.2 或更高版本,再点标题旁的版本号检查。',
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
173
195
|
function loadConfig() {
|
|
174
196
|
try {
|
|
175
197
|
const parsed = JSON.parse(readFileSync(CONFIG_PATH, 'utf8'))
|
|
@@ -380,6 +402,10 @@ export function apply(ctx) {
|
|
|
380
402
|
installedVersion: own.version ?? HOST_VERSION,
|
|
381
403
|
updatable: Boolean(own.updatable),
|
|
382
404
|
source: own.source ?? null,
|
|
405
|
+
availability: own.availability ?? null,
|
|
406
|
+
readOnlyReason: own.readOnlyReason ?? null,
|
|
407
|
+
official: Boolean(own.official),
|
|
408
|
+
error: own.error ?? null,
|
|
383
409
|
}
|
|
384
410
|
}
|
|
385
411
|
} catch {
|
|
@@ -394,6 +420,7 @@ export function apply(ctx) {
|
|
|
394
420
|
installed,
|
|
395
421
|
self,
|
|
396
422
|
selfUpdate: readSelfUpdateRecord(),
|
|
423
|
+
selfUpdateSupported: selfUpdateCapability(manager).supported,
|
|
397
424
|
})
|
|
398
425
|
}
|
|
399
426
|
|
|
@@ -401,17 +428,40 @@ export function apply(ctx) {
|
|
|
401
428
|
const manager = ctx.get('pluginManager')
|
|
402
429
|
if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用(当前不是 profile 模式)' })
|
|
403
430
|
|
|
431
|
+
const capability = selfUpdateCapability(manager)
|
|
432
|
+
if (!capability.supported) {
|
|
433
|
+
return send(res, 200, {
|
|
434
|
+
status: 'unsupported',
|
|
435
|
+
...selfUpdateUnsupportedInfo(capability.reason),
|
|
436
|
+
version: HOST_VERSION,
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
|
|
404
440
|
const own = await findSelfBundle(manager)
|
|
405
441
|
const installedVersion = own?.version ?? HOST_VERSION
|
|
406
442
|
if (!own?.updatable) {
|
|
407
443
|
const blocked = selfUpdateBlockedInfo(own)
|
|
444
|
+
// listVersions 对不可升级的 bundle 会直接返回 DSH 的原始拒绝理由(不走网络),
|
|
445
|
+
// 把它带出来,省得只能猜是来源、版本还是只读。
|
|
446
|
+
let detail = null
|
|
447
|
+
try {
|
|
448
|
+
const refused = await manager.listVersions(SELF_PACKAGE)
|
|
449
|
+
if (refused?.status === 'refused' && refused.reason) detail = String(refused.reason)
|
|
450
|
+
} catch {
|
|
451
|
+
/* 旧版管理器可能没有 listVersions,忽略 */
|
|
452
|
+
}
|
|
408
453
|
return send(res, 200, {
|
|
409
454
|
status: 'not-updatable',
|
|
410
455
|
version: HOST_VERSION,
|
|
411
456
|
installedVersion,
|
|
412
457
|
source: own?.source ?? null,
|
|
413
458
|
reason: blocked.reason,
|
|
414
|
-
|
|
459
|
+
detail,
|
|
460
|
+
availability: own?.availability ?? null,
|
|
461
|
+
readOnlyReason: own?.readOnlyReason ?? null,
|
|
462
|
+
official: own?.official ?? null,
|
|
463
|
+
error: own?.error ?? null,
|
|
464
|
+
hint: detail ? `${blocked.hint}(DSH 判断:${detail})` : blocked.hint,
|
|
415
465
|
})
|
|
416
466
|
}
|
|
417
467
|
|
|
@@ -475,6 +525,16 @@ export function apply(ctx) {
|
|
|
475
525
|
const manager = ctx.get('pluginManager')
|
|
476
526
|
if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用(当前不是 profile 模式)' })
|
|
477
527
|
|
|
528
|
+
const capability = selfUpdateCapability(manager)
|
|
529
|
+
if (!capability.supported) {
|
|
530
|
+
const unsupported = selfUpdateUnsupportedInfo(capability.reason)
|
|
531
|
+
return send(res, 409, {
|
|
532
|
+
error: unsupported.hint,
|
|
533
|
+
code: 'unsupported',
|
|
534
|
+
reason: unsupported.reason,
|
|
535
|
+
})
|
|
536
|
+
}
|
|
537
|
+
|
|
478
538
|
const own = await findSelfBundle(manager)
|
|
479
539
|
if (!own?.updatable) {
|
|
480
540
|
const blocked = selfUpdateBlockedInfo(own)
|