xiaojingyuai-dsh 0.2.5 → 0.2.7
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 +1 -1
- package/client.js +54 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
## 更新
|
|
14
14
|
|
|
15
|
-
「设置 → 一只小鲸鱼AI → 插件更新」会从 `dafeiyu-download` OSS 检查新版本。更新清单使用 Ed25519 签名,更新包同时校验大小和 SHA-256
|
|
15
|
+
「设置 → 一只小鲸鱼AI → 插件更新」会从 `dafeiyu-download` OSS 检查新版本。更新清单使用 Ed25519 签名,更新包同时校验大小和 SHA-256。新版插件通过 DSH 官方插件管理器原位替换 npm 包,不需要手工移除旧版;更新完成后再重启 DSH,运行时缓存不会被重复下载。
|
|
16
16
|
|
|
17
17
|
## 运行目录
|
|
18
18
|
|
package/client.js
CHANGED
|
@@ -152,6 +152,7 @@ window.__ModuleLoader__.load({
|
|
|
152
152
|
selectedId: null, linkedId: null, phase: 'idle', busy: false, error: null,
|
|
153
153
|
actionBusy: null, actionMessage: null, actionError: null,
|
|
154
154
|
updateSource: null, updateInfo: null, updateBusy: false, updateError: null,
|
|
155
|
+
updateMessage: null, updateRestartRequired: false,
|
|
155
156
|
};
|
|
156
157
|
let attempted;
|
|
157
158
|
let currentRequest = 0;
|
|
@@ -228,7 +229,7 @@ window.__ModuleLoader__.load({
|
|
|
228
229
|
}
|
|
229
230
|
async function downloadLatest() {
|
|
230
231
|
if (snapshot.updateBusy || !snapshot.updateInfo?.available) return;
|
|
231
|
-
publish({ updateBusy: true, updateError: null });
|
|
232
|
+
publish({ updateBusy: true, updateError: null, updateMessage: null, updateRestartRequired: false });
|
|
232
233
|
try {
|
|
233
234
|
const result = await request({ action: 'download-update' }, lifetime.signal);
|
|
234
235
|
publish({ updateInfo: result.update });
|
|
@@ -238,6 +239,48 @@ window.__ModuleLoader__.load({
|
|
|
238
239
|
if (!lifetime.signal.aborted) publish({ updateBusy: false });
|
|
239
240
|
}
|
|
240
241
|
}
|
|
242
|
+
async function installLatest() {
|
|
243
|
+
const update = snapshot.updateInfo;
|
|
244
|
+
if (snapshot.updateBusy || !update?.available || !update.file) return;
|
|
245
|
+
const manager = ctx.remote && ctx.remote.pluginManager;
|
|
246
|
+
if (!manager || typeof manager.updateBundle !== 'function') {
|
|
247
|
+
publish({ updateError: '当前 DSH 版本不支持自动安装插件更新,请升级 DSH 后重试。' });
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const requestId = typeof globalThis.crypto?.randomUUID === 'function'
|
|
251
|
+
? globalThis.crypto.randomUUID()
|
|
252
|
+
: `xiaojingyuai-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
253
|
+
publish({
|
|
254
|
+
updateBusy: true, updateError: null, updateMessage: '正在通过 DSH 插件管理器安装…',
|
|
255
|
+
updateRestartRequired: false,
|
|
256
|
+
});
|
|
257
|
+
try {
|
|
258
|
+
const answer = await manager.updateBundle('xiaojingyuai-dsh', update.latestVersion, {
|
|
259
|
+
registry: 'https://registry.npmjs.org/',
|
|
260
|
+
requestId,
|
|
261
|
+
});
|
|
262
|
+
if (!answer || answer.ok === false) {
|
|
263
|
+
throw new Error(answer?.error?.message || 'DSH 插件管理器拒绝了更新');
|
|
264
|
+
}
|
|
265
|
+
const result = answer.value || {};
|
|
266
|
+
if (result.application === 'failed') {
|
|
267
|
+
throw new Error(result.error?.diagnostic || result.error?.code || '插件更新安装失败');
|
|
268
|
+
}
|
|
269
|
+
if (result.application === 'cancelled') throw new Error('插件更新已取消');
|
|
270
|
+
const restart = result.application === 'restart-required';
|
|
271
|
+
publish({
|
|
272
|
+
updateInfo: { ...update, available: false, file: null },
|
|
273
|
+
updateRestartRequired: restart,
|
|
274
|
+
updateMessage: restart
|
|
275
|
+
? `v${update.latestVersion} 已安装。重新打开 DSH 后生效。`
|
|
276
|
+
: `已更新到 v${update.latestVersion}。`,
|
|
277
|
+
});
|
|
278
|
+
} catch (error) {
|
|
279
|
+
if (!lifetime.signal.aborted) publish({ updateError: error.message || '安装插件更新失败' });
|
|
280
|
+
} finally {
|
|
281
|
+
if (!lifetime.signal.aborted) publish({ updateBusy: false });
|
|
282
|
+
}
|
|
283
|
+
}
|
|
241
284
|
const sync = () => { void connect(); };
|
|
242
285
|
const onPreference = event => {
|
|
243
286
|
if (event.key !== settingsKey) return;
|
|
@@ -382,12 +425,20 @@ window.__ModuleLoader__.load({
|
|
|
382
425
|
h('button', {
|
|
383
426
|
className: 'xjy-settings__action', type: 'button', disabled: state.updateBusy,
|
|
384
427
|
onClick: downloadLatest,
|
|
385
|
-
}, state.updateInfo.file ? '
|
|
428
|
+
}, state.updateInfo.file ? '重新校验下载' : '下载更新包')) : null,
|
|
386
429
|
state.updateInfo?.file ? h('div', { className: 'xjy-settings__row' },
|
|
387
430
|
h('div', null,
|
|
388
431
|
h('p', { className: 'xjy-settings__title' }, '更新包已校验'),
|
|
389
432
|
h('p', { className: 'xjy-settings__note' }, state.updateInfo.file),
|
|
390
|
-
h('p', { className: 'xjy-settings__note' }, '
|
|
433
|
+
h('p', { className: 'xjy-settings__note' }, '完整小插件包;Windows 运行时缓存会继续复用。')),
|
|
434
|
+
h('button', {
|
|
435
|
+
className: 'xjy-settings__action', type: 'button', disabled: state.updateBusy,
|
|
436
|
+
onClick: installLatest,
|
|
437
|
+
}, state.updateBusy ? '安装中' : '安装更新')) : null,
|
|
438
|
+
state.updateMessage ? h('div', { className: 'xjy-settings__row xjy-settings__footer' },
|
|
439
|
+
h('p', {
|
|
440
|
+
className: 'xjy-settings__note', role: 'status', 'aria-live': 'polite',
|
|
441
|
+
}, state.updateMessage)) : null));
|
|
391
442
|
}
|
|
392
443
|
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
393
444
|
name: 'settings.section', id: 'xiaojingyuai', order: 35, label: () => '一只小鲸鱼AI',
|