dsh-desktop-statusbar 3.0.1 → 3.0.2
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 +498 -31
- package/lib/exchange-rate.js +199 -0
- package/lib/index.js +252 -31
- package/lib/self-update.js +338 -35
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -74,7 +74,7 @@ window.__ModuleLoader__.load({
|
|
|
74
74
|
*/
|
|
75
75
|
const CONFIG_VERSION = 6;
|
|
76
76
|
/** 插件版本:显示在设置页底部,用来确认页面加载的是哪一版客户端代码。 */
|
|
77
|
-
const VERSION = "3.0.
|
|
77
|
+
const VERSION = "3.0.2";
|
|
78
78
|
/** 官方参考价的版本:官方调价时改这个数字,老价格库会自动并入新参考价。 */
|
|
79
79
|
const PRICE_VERSION = 2;
|
|
80
80
|
/** 项目主页:设置页那个「去 GitHub 点 star」按钮跳这里(与 package.json 的 repository 同址)。 */
|
|
@@ -186,6 +186,48 @@ window.__ModuleLoader__.load({
|
|
|
186
186
|
return a === "CNY" ? value / REFERENCE_RATE : value * REFERENCE_RATE;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
/**
|
|
190
|
+
* 用**指定汇率**折算(不读全局 REFERENCE_RATE)。
|
|
191
|
+
*
|
|
192
|
+
* 存在的理由:台账里每天可能记着「当天拉到的汇率」(`day.rateAt`),
|
|
193
|
+
* 用它折算才能让历史金额**不随今天的汇率漂移**。`convertCurrency` 保持原样,
|
|
194
|
+
* 其它调用点(队友费用、活跃总览等)继续走内置常量。
|
|
195
|
+
*
|
|
196
|
+
* @param {number} amount
|
|
197
|
+
* @param {string} from
|
|
198
|
+
* @param {string} to
|
|
199
|
+
* @param {number} rate 「1 USD = ? CNY」
|
|
200
|
+
* @returns {number}
|
|
201
|
+
*/
|
|
202
|
+
function convertWithRate(amount, from, to, rate) {
|
|
203
|
+
const value = Number(amount);
|
|
204
|
+
if (Number.isFinite(value) !== true) return amount;
|
|
205
|
+
const a = normalizeCurrency(from);
|
|
206
|
+
const b = normalizeCurrency(to);
|
|
207
|
+
const usable = Number.isFinite(rate) === true && rate > 0 ? rate : REFERENCE_RATE;
|
|
208
|
+
if (a === b || usable === null || Number.isFinite(usable) !== true || usable <= 0) return value;
|
|
209
|
+
return a === "CNY" ? value / usable : value * usable;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 「当下的钱」该用的汇率:host 每次返回余额时会把最新的汇率一并带回来,
|
|
215
|
+
* 客户端存进 `liveExchangeRate`。没拿到过就退回内置常量。
|
|
216
|
+
*
|
|
217
|
+
* 为什么不在这里自己发请求:汇率由 host 统一拉(每天 9:00 一次),
|
|
218
|
+
* 客户端只负责显示,多一个请求点就多一处失败面。
|
|
219
|
+
*
|
|
220
|
+
* @returns {number}
|
|
221
|
+
*/
|
|
222
|
+
function liveRate() {
|
|
223
|
+
return Number.isFinite(liveExchangeRate) === true && liveExchangeRate > 0
|
|
224
|
+
? liveExchangeRate
|
|
225
|
+
: REFERENCE_RATE;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** host 带回来的当前汇率(「1 USD = ? CNY」);没拿到过是 null。 */
|
|
229
|
+
let liveExchangeRate = null;
|
|
230
|
+
|
|
189
231
|
/** 一格未填时的占位:用 `null` 表示"这里还没填过",与用户明确填的 0 区分开。 */
|
|
190
232
|
const EMPTY_TIER = { input: null, cacheRead: null, cacheWrite: null, output: null };
|
|
191
233
|
|
|
@@ -603,9 +645,15 @@ window.__ModuleLoader__.load({
|
|
|
603
645
|
}
|
|
604
646
|
|
|
605
647
|
/** 按某模型条目单价算出来的金额 → 折成显示币种(只用于显示,不回写任何地方)。 */
|
|
606
|
-
function toDisplayCurrency(amount, book, model, displayCurrency, defaultCurrency) {
|
|
648
|
+
function toDisplayCurrency(amount, book, model, displayCurrency, defaultCurrency, rate) {
|
|
607
649
|
if (amount === null || amount === undefined) return amount;
|
|
608
|
-
|
|
650
|
+
const from = entryCurrencyOf(book, model, defaultCurrency);
|
|
651
|
+
/* 传了汇率就用它(台账里每天记着的那个),没传就退回全局常量 —— 后者是
|
|
652
|
+
老台账的形态,也保证其它调用点的行为一个字不变。 */
|
|
653
|
+
if (rate !== undefined && rate !== null) {
|
|
654
|
+
return convertWithRate(amount, from, displayCurrency, rate);
|
|
655
|
+
}
|
|
656
|
+
return convertCurrency(amount, from, displayCurrency);
|
|
609
657
|
}
|
|
610
658
|
|
|
611
659
|
/** 模型名显示用:deepseek → DeepSeek、glm → GLM、gpt → GPT,其余按 - 分段首字母大写。 */
|
|
@@ -1370,6 +1418,11 @@ window.__ModuleLoader__.load({
|
|
|
1370
1418
|
updateRunning: "正在更新中",
|
|
1371
1419
|
updateFailed: "更新失败",
|
|
1372
1420
|
updateDone: "更新成功,重启 DSH 后生效",
|
|
1421
|
+
/* 修复安装:不装新版本,只让 pnpm 按现有清单把 node_modules 重新对齐
|
|
1422
|
+
(升级失败后四处状态互相矛盾时用)。文案必须与「更新」区分开。 */
|
|
1423
|
+
updateErrorTruncated: "(输出较长,只显示最后 {limit} 个字符;完整内容见日志)",
|
|
1424
|
+
updateErrorCopy: "复制",
|
|
1425
|
+
updateErrorCopied: "已复制",
|
|
1373
1426
|
/* 开发模式:连点版本号 5 次进入。不做成可见控件 —— 它面向作者调试,
|
|
1374
1427
|
普通用户装了插件也不该看到一个「预览」勾选框。进入后标题右侧挂一枚胶囊。 */
|
|
1375
1428
|
devModeBadge: "开发模式",
|
|
@@ -1505,6 +1558,11 @@ window.__ModuleLoader__.load({
|
|
|
1505
1558
|
updateRunning: "Updating",
|
|
1506
1559
|
updateFailed: "Update failed",
|
|
1507
1560
|
updateDone: "Update succeeded — restart DSH to apply",
|
|
1561
|
+
/* Repair: no new version is installed; pnpm just realigns node_modules
|
|
1562
|
+
with the existing manifests (used after a failed upgrade). */
|
|
1563
|
+
updateErrorTruncated: "(output is long; showing the last {limit} characters — see the log for the full text)",
|
|
1564
|
+
updateErrorCopy: "Copy",
|
|
1565
|
+
updateErrorCopied: "Copied",
|
|
1508
1566
|
devModeBadge: "Dev mode",
|
|
1509
1567
|
devModeHint: "Dev mode: the update button only simulates states — nothing is installed",
|
|
1510
1568
|
sectionTitle: "Status Bar Settings",
|
|
@@ -4692,8 +4750,10 @@ window.__ModuleLoader__.load({
|
|
|
4692
4750
|
if (one.toppedUp === undefined && one.granted === undefined) return;
|
|
4693
4751
|
sawAny = true;
|
|
4694
4752
|
const code = one.currency === "USD" ? "USD" : "CNY";
|
|
4695
|
-
|
|
4696
|
-
|
|
4753
|
+
/* 余额是「当下的钱」,所以用**当前**汇率(不是台账里某天记下的那个)。 */
|
|
4754
|
+
const live = liveRate();
|
|
4755
|
+
topSum += convertWithRate(Number(one.toppedUp) || 0, code, symbolCurrency, live);
|
|
4756
|
+
grantSum += convertWithRate(Number(one.granted) || 0, code, symbolCurrency, live);
|
|
4697
4757
|
});
|
|
4698
4758
|
/* 一个币种都没带这两个字段 ⇒ 当作"拿不到",回退老口径 */
|
|
4699
4759
|
if (sawAny !== true) return null;
|
|
@@ -5289,6 +5349,23 @@ window.__ModuleLoader__.load({
|
|
|
5289
5349
|
".dsb-settings .dsb-action{box-sizing:border-box;height:28px;padding:0 12px;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary);background:transparent;border:1px solid var(--dsw-alias-separator-primary,rgba(127,127,127,.3));border-radius:6px;cursor:pointer;white-space:nowrap}",
|
|
5290
5350
|
".dsb-settings .dsb-action:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.1))}",
|
|
5291
5351
|
".dsb-settings .dsb-action-sm{height:24px;padding:0 8px;font-size:12px}",
|
|
5352
|
+
/* 更新失败时摊在按钮下方的 pnpm 原文。
|
|
5353
|
+
**刻意不设 max-height、不用 overflow** —— 用户明确要求「不需要我滚动,
|
|
5354
|
+
直接滑到最下面展示全文」:让它自然展开,整页跟着变长,而不是变成一个小滚动框。
|
|
5355
|
+
代价是超长输出会把页面撑得很高,所以渲染侧先截到固定字符数(见 UPDATE_ERROR_MAX_CHARS)。 */
|
|
5356
|
+
/* 报错块:`flex-basis:100%` 让它在 `.dsb-foot` 这个 flex 容器里**独占一整行、撑满宽度**,
|
|
5357
|
+
与上面的价格框左右对齐。不加它的话宽度只由文字决定,右边会缺一节。
|
|
5358
|
+
**四周内边距对称(8px 10px)**:不为按钮预留任何行高或宽度 ——
|
|
5359
|
+
按钮是绝对定位、浮在内容之上的,它不需要文字流给它让位。 */
|
|
5360
|
+
".dsb-settings .dsb-update-error{position:relative;flex:0 0 100%;width:100%;box-sizing:border-box;margin:6px 0 0;padding:8px 10px;border-radius:6px;background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.1));color:var(--dsw-alias-label-secondary,var(--dsw-alias-label-primary));font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11px;line-height:1.45;white-space:pre-wrap;word-break:break-word}",
|
|
5361
|
+
/* 复制按钮:**绝对靠右**,钉在报错块右下角,**不占文字流的任何空间**。
|
|
5362
|
+
位置用 right/bottom 各 10px 与 pre 的内边距对齐,右边缘与文字右边缘齐平。
|
|
5363
|
+
**绝不加底部内边距**:早先为了"不让按钮压住文字"给 pre 加了 padding-bottom,
|
|
5364
|
+
结果那一条被撑成了一行只放按钮的空白(截图里就是最后多出来的一截)。
|
|
5365
|
+
正确的做法是让按钮浮在最后一行**右侧的空白处** —— 那段空白本来就有,
|
|
5366
|
+
因为最后一行文字几乎不可能正好写满整行。 */
|
|
5367
|
+
".dsb-settings .dsb-update-error-copy{position:absolute;right:10px;bottom:6px;display:flex;align-items:center;justify-content:center;width:20px;height:20px;padding:0;border:none;border-radius:4px;background:transparent;color:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-secondary));cursor:pointer}",
|
|
5368
|
+
".dsb-settings .dsb-update-error-copy:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.15));color:var(--dsw-alias-label-primary)}",
|
|
5292
5369
|
/* 「正在更新中」后面那三个点:依次亮起,表示还在跑 */
|
|
5293
5370
|
".dsb-dots{margin-left:1px}",
|
|
5294
5371
|
".dsb-dots span{animation:dsb-dot 1.2s ease-in-out infinite}",
|
|
@@ -5338,8 +5415,10 @@ window.__ModuleLoader__.load({
|
|
|
5338
5415
|
* note 是更新动作的结果:null / "done" / "failed"。
|
|
5339
5416
|
* failedTarget 记「失败的那次试的是哪个版本」:失败态点一下退回可重试时,
|
|
5340
5417
|
* 文案要回到那个版本号(而不是 last 里可能已被刷新的别的版本)。
|
|
5418
|
+
* mode 记这次动作是「更新」(update)还是「修复安装」(repair):
|
|
5419
|
+
* 两种模式共用同一套状态机,只有请求 URL 与文案不同(修复中 / 更新中)。
|
|
5341
5420
|
*/
|
|
5342
|
-
let updateState = { hasUpdate: false, latest: null, busy: false, note: null, reason: null, failedTarget: null };
|
|
5421
|
+
let updateState = { hasUpdate: false, latest: null, busy: false, note: null, reason: null, failedTarget: null, mode: "update", errorCopied: false };
|
|
5343
5422
|
|
|
5344
5423
|
/**
|
|
5345
5424
|
* 开发模式(连点版本号 5 次进入):让作者在没有新版本的时候也能看到更新按钮的
|
|
@@ -5361,6 +5440,37 @@ window.__ModuleLoader__.load({
|
|
|
5361
5440
|
const DEV_VERSION = "9.9.9";
|
|
5362
5441
|
/** 演示用的假失败原因,走的就是真实失败时那条显示路径。 */
|
|
5363
5442
|
const DEV_FAIL_REASON = "release-age";
|
|
5443
|
+
/* 更新失败的**全部分类**,与 host 侧 `classifyPnpmFailure()` 的返回值一一对应
|
|
5444
|
+
(见 lib/self-update.js:outdated-lockfile / store-error / postinstall-failed /
|
|
5445
|
+
symlink-failed / disk-full / install-failed),另加 `timeout` 与 `release-age`
|
|
5446
|
+
这两个不来自分类器的原因 —— 它们也是真实会出现的失败态。
|
|
5447
|
+
连点更新按钮依次轮换,6 种分类都能在界面上看到,**不必等真实失败**。
|
|
5448
|
+
新增分类时**必须同步这里**,否则开发模式演示不到、界面文案也没人验证。 */
|
|
5449
|
+
const DEV_UPDATE_FAILURE_REASONS = [
|
|
5450
|
+
"outdated-lockfile",
|
|
5451
|
+
"symlink-failed",
|
|
5452
|
+
"postinstall-failed",
|
|
5453
|
+
"store-error",
|
|
5454
|
+
"disk-full",
|
|
5455
|
+
"install-failed",
|
|
5456
|
+
"timeout",
|
|
5457
|
+
"release-age"
|
|
5458
|
+
];
|
|
5459
|
+
/* 每种失败原因配一段**形似真实 pnpm 输出**的假原文。
|
|
5460
|
+
为什么要有:失败原文现在会常驻显示在按钮下方,开发模式里必须能看到它长什么样、
|
|
5461
|
+
多长、换行对不对 —— 否则这条界面只能等真实失败才有机会验证。
|
|
5462
|
+
文案刻意与 `classifyPnpmFailure()` 的判据对得上(错误码写全),
|
|
5463
|
+
这样演示出来的样子和真实抓到的样子是同一种。 */
|
|
5464
|
+
const DEV_UPDATE_FAILURE_OUTPUT = {
|
|
5465
|
+
"outdated-lockfile": " ERR_PNPM_OUTDATED_LOCKFILE Cannot install with \"frozen-lockfile\" because pnpm-lock.yaml is not up to date with package.json\n\nFailure reason:\n lockfile is not up to date\n\nNote that this is a demo output shown in development mode.",
|
|
5466
|
+
"symlink-failed": " Progress: resolved 99, reused 78, downloaded 1, added 80\n [EPERM] operation not permitted, symlink '/home/user/.dsh/local-plugins/example-plugin' -> '/home/user/.dsh/profiles/desktop/node_modules/example-plugin'\n\nNote that this is a demo output shown in development mode.",
|
|
5467
|
+
"postinstall-failed": " node_modules/example-native postinstall$ node install.cjs\n ELIFECYCLE Command failed with exit code 1.\n Error: spawn EPERM\n\nNote that this is a demo output shown in development mode.",
|
|
5468
|
+
"store-error": " ERR_SQLITE_ERROR: unable to open database file\n at StoreIndex.openDatabase (pnpm.mjs:143380)\n\nNote that this is a demo output shown in development mode.",
|
|
5469
|
+
"disk-full": " ENOSPC: no space left on device, write\n\nNote that this is a demo output shown in development mode.",
|
|
5470
|
+
"install-failed": " Progress: resolved 99, reused 78, downloaded 1, added 80\n ERR_PNPM_UNEXPECTED_STORE Unexpected store location\n\nNote that this is a demo output shown in development mode.",
|
|
5471
|
+
"timeout": " Progress: resolved 99, reused 78, downloaded 1, added 80\n (install did not finish before the timeout; the process was terminated)\n\nNote that this is a demo output shown in development mode.",
|
|
5472
|
+
"release-age": " ERR_PNPM_NO_MATURE_MATCHING_VERSION No matching version found for dsh-desktop-statusbar@9.9.9\n\nNote that this is a demo output shown in development mode."
|
|
5473
|
+
};
|
|
5364
5474
|
/** 「更新中」演示的时长:够看清三个点的动效,又不至于让人等。 */
|
|
5365
5475
|
const DEV_BUSY_MS = 2200;
|
|
5366
5476
|
/** 进入/退出开发模式需要连点几次版本号。 */
|
|
@@ -6713,12 +6823,19 @@ window.__ModuleLoader__.load({
|
|
|
6713
6823
|
* 也别挂一个点不开的假提示。
|
|
6714
6824
|
*/
|
|
6715
6825
|
function loadUpdateFlag() {
|
|
6716
|
-
/* 宿主是拿 ?current= 里的版本来比大小的;不带就等于没版本可比,会被当成「没有新版」。
|
|
6826
|
+
/* 宿主是拿 ?current= 里的版本来比大小的;不带就等于没版本可比,会被当成「没有新版」。
|
|
6827
|
+
顺带把最近一次失败记录取回来:失败原文就靠它显示在按钮下方,
|
|
6828
|
+
刷新页面之后也要能看到上一次的报错,不能只活在内存里。 */
|
|
6717
6829
|
return window.fetch(VERSION_URL + "?current=" + encodeURIComponent(VERSION), { cache: "no-store" })
|
|
6718
6830
|
.then((response) => (response.ok === true ? response.json() : null))
|
|
6719
|
-
.then((payload) =>
|
|
6720
|
-
|
|
6721
|
-
|
|
6831
|
+
.then((payload) => {
|
|
6832
|
+
if (payload === null || payload === undefined) return null
|
|
6833
|
+
/* 没有失败记录时也要显式清空:否则上一次的旧报错会一直挂在界面上。 */
|
|
6834
|
+
syncLastUpdateFailure(payload.lastFailure === undefined ? null : payload.lastFailure)
|
|
6835
|
+
return {
|
|
6836
|
+
hasUpdate: payload.hasUpdate === true,
|
|
6837
|
+
latest: typeof payload.latest === "string" && payload.latest.length > 0 ? payload.latest : null
|
|
6838
|
+
}
|
|
6722
6839
|
})
|
|
6723
6840
|
.catch(() => null);
|
|
6724
6841
|
}
|
|
@@ -6772,27 +6889,46 @@ window.__ModuleLoader__.load({
|
|
|
6772
6889
|
/* 开发模式下只演示:不真实安装(见 runDevPreview) */
|
|
6773
6890
|
if (devMode === true) { runDevPreview(); return; }
|
|
6774
6891
|
if (updateState.latest === null || updateState.busy === true) return;
|
|
6775
|
-
|
|
6892
|
+
requestSelfUpdate("update", updateState.latest);
|
|
6893
|
+
}
|
|
6894
|
+
|
|
6895
|
+
/**
|
|
6896
|
+
* 发一次自更新/修复请求。两种模式共用一个状态机,只有 URL 与文案不同。
|
|
6897
|
+
*
|
|
6898
|
+
* @param {"update"|"repair"} mode
|
|
6899
|
+
* @param {string|null} target update 模式的目标版本;repair 为 null
|
|
6900
|
+
*/
|
|
6901
|
+
function requestSelfUpdate(mode, target) {
|
|
6776
6902
|
/* 失败时记下"这个版本已经试过了":按钮点一下回到可重试文案时要用它。 */
|
|
6777
|
-
setUpdateState({ busy: true, note: null, reason: null, failedTarget: null });
|
|
6903
|
+
setUpdateState({ busy: true, note: null, reason: null, failedTarget: null, mode: mode });
|
|
6778
6904
|
const startedAt = Date.now();
|
|
6779
6905
|
/* 失败收敛到一处:状态 + 日志。三条失败路径(响应解不出 / 应答 ok:false / 网络异常)
|
|
6780
6906
|
都走这里,保证每一条都在日志里留下同样的字段。 */
|
|
6781
6907
|
const fail = (reason, extra) => {
|
|
6782
6908
|
const info = Object.assign({
|
|
6783
6909
|
reason: reason,
|
|
6910
|
+
mode: mode,
|
|
6784
6911
|
target: target,
|
|
6785
6912
|
current: VERSION,
|
|
6786
6913
|
at: Date.now(),
|
|
6787
6914
|
elapsedMs: Date.now() - startedAt
|
|
6788
6915
|
}, extra === undefined ? {} : extra);
|
|
6789
6916
|
reportUpdateFailure(info);
|
|
6790
|
-
setUpdateState({ busy: false, note: "failed", reason: reason, failedTarget: target });
|
|
6917
|
+
setUpdateState({ busy: false, note: "failed", reason: reason, failedTarget: target, mode: mode, errorCopied: false });
|
|
6918
|
+
/* 失败态一出现就**自动滚过去**:报错块在设置页最底部,页面又长,
|
|
6919
|
+
不滚的话用户得自己往下找 —— 那和"不显示"没什么区别。 */
|
|
6920
|
+
scheduleErrorScroll();
|
|
6921
|
+
/* **静默自动修复**:更新失败后机器上可能留下"清单写新版、实物还是旧版"的
|
|
6922
|
+
矛盾状态。这一步在后台自己做掉,成功失败都不打扰用户 ——
|
|
6923
|
+
用户原话:「不要显示任何呀,你的修复就应该静默修复」。
|
|
6924
|
+
注意它改的是 `lastUpdateFailure` 之外的东西(三份清单 + node_modules),
|
|
6925
|
+
所以失败也不写失败态,只是把界面留在原样。 */
|
|
6926
|
+
autoRepairSilently();
|
|
6791
6927
|
};
|
|
6792
|
-
window.fetch(SELF_UPDATE_URL, {
|
|
6928
|
+
window.fetch(mode === "repair" ? SELF_UPDATE_URL + "?mode=repair" : SELF_UPDATE_URL, {
|
|
6793
6929
|
method: "POST",
|
|
6794
6930
|
headers: { "content-type": "application/json" },
|
|
6795
|
-
body: JSON.stringify({ version: target })
|
|
6931
|
+
body: JSON.stringify(mode === "repair" ? {} : { version: target })
|
|
6796
6932
|
}).then((response) => {
|
|
6797
6933
|
/* fetch 对 4xx/5xx 是 **resolve** 不是 reject:必须自己看状态码,
|
|
6798
6934
|
否则 403(跨站防护)/ 409(正在更新)/ 500 都会被当成"响应解不出来"。 */
|
|
@@ -6807,7 +6943,7 @@ window.__ModuleLoader__.load({
|
|
|
6807
6943
|
if (payload === null || payload === undefined) return;
|
|
6808
6944
|
const ok = payload.ok === true;
|
|
6809
6945
|
if (ok === true) {
|
|
6810
|
-
setUpdateState({ busy: false, note: "done", reason: null, failedTarget: null });
|
|
6946
|
+
setUpdateState({ busy: false, note: "done", reason: null, failedTarget: null, mode: mode, errorCopied: false });
|
|
6811
6947
|
return;
|
|
6812
6948
|
}
|
|
6813
6949
|
/* 宿主明确回了失败原因(release-age / verify-failed / pnpm-failed…):
|
|
@@ -6832,8 +6968,9 @@ window.__ModuleLoader__.load({
|
|
|
6832
6968
|
const phase = updateState.note;
|
|
6833
6969
|
if (updateState.busy === true) return;
|
|
6834
6970
|
if (phase === null) {
|
|
6835
|
-
/* ①
|
|
6836
|
-
|
|
6971
|
+
/* ① 更新中:亮起那三个点。mode 一起摆成 update,
|
|
6972
|
+
否则从「修复」那一路退回来再点,会带着 repair 的文案进忙碌态。 */
|
|
6973
|
+
setUpdateState({ busy: true, note: null, reason: null, latest: DEV_VERSION, mode: "update" });
|
|
6837
6974
|
devTimer = setTimeout(() => {
|
|
6838
6975
|
devTimer = null;
|
|
6839
6976
|
/* ② 已更新 */
|
|
@@ -6842,14 +6979,42 @@ window.__ModuleLoader__.load({
|
|
|
6842
6979
|
return;
|
|
6843
6980
|
}
|
|
6844
6981
|
if (phase === "done") {
|
|
6845
|
-
/* ③
|
|
6846
|
-
|
|
6982
|
+
/* ③ 更新失败:走真实失败那条显示路径。
|
|
6983
|
+
原因在 DEV_UPDATE_FAILURE_REASONS 里轮换,连点就能把每一种分类都看一遍。
|
|
6984
|
+
原文也要一起摆好 —— 界面上那块 `dsb-update-error` 读的是 lastUpdateFailure,
|
|
6985
|
+
不设它就会渲染成空、演示不出真实形态。 */
|
|
6986
|
+
const reason = DEV_UPDATE_FAILURE_REASONS[devFailureScene % DEV_UPDATE_FAILURE_REASONS.length];
|
|
6987
|
+
devFailureScene = (devFailureScene + 1) % DEV_UPDATE_FAILURE_REASONS.length;
|
|
6988
|
+
syncLastUpdateFailure({
|
|
6989
|
+
stage: "host-install",
|
|
6990
|
+
mode: "update",
|
|
6991
|
+
reason: reason,
|
|
6992
|
+
rolledBack: true,
|
|
6993
|
+
at: Date.now(),
|
|
6994
|
+
summary: "演示:" + reason,
|
|
6995
|
+
stdout: "",
|
|
6996
|
+
stderr: DEV_UPDATE_FAILURE_OUTPUT[reason] === undefined ? "" : DEV_UPDATE_FAILURE_OUTPUT[reason],
|
|
6997
|
+
exitCode: 1
|
|
6998
|
+
});
|
|
6999
|
+
setUpdateState({
|
|
7000
|
+
busy: false,
|
|
7001
|
+
note: "failed",
|
|
7002
|
+
reason: reason,
|
|
7003
|
+
failedTarget: DEV_VERSION,
|
|
7004
|
+
mode: "update"
|
|
7005
|
+
});
|
|
7006
|
+
/* 演示也要滚过去 —— 否则开发模式下同样得自己往下找,
|
|
7007
|
+
看不到这块就等于这条界面没被验证过。 */
|
|
7008
|
+
scheduleErrorScroll();
|
|
6847
7009
|
return;
|
|
6848
7010
|
}
|
|
6849
7011
|
/* ④ 回到空闲,可以再点一遍 */
|
|
6850
|
-
setUpdateState({ busy: false, note: null, reason: null, latest: DEV_VERSION });
|
|
7012
|
+
setUpdateState({ busy: false, note: null, reason: null, latest: DEV_VERSION, mode: "update" });
|
|
6851
7013
|
}
|
|
6852
7014
|
|
|
7015
|
+
/* 开发模式下失败原因的轮换游标:只在开发模式里用,退出时归零(见 setDevMode)。 */
|
|
7016
|
+
let devFailureScene = 0;
|
|
7017
|
+
|
|
6853
7018
|
/** 开发模式里「更新中」那一步的定时器;退出开发模式或卸载时要清掉。 */
|
|
6854
7019
|
let devTimer = null;
|
|
6855
7020
|
|
|
@@ -6869,7 +7034,8 @@ window.__ModuleLoader__.load({
|
|
|
6869
7034
|
const target = updateState.failedTarget === null || updateState.failedTarget === undefined
|
|
6870
7035
|
? updateState.latest
|
|
6871
7036
|
: updateState.failedTarget;
|
|
6872
|
-
|
|
7037
|
+
/* mode 一并归位到 update:退回后的下一步是「更新到 X.X.X」,不是修复。 */
|
|
7038
|
+
setUpdateState({ busy: false, note: null, reason: null, latest: target, failedTarget: null, mode: "update" });
|
|
6873
7039
|
}
|
|
6874
7040
|
|
|
6875
7041
|
/**
|
|
@@ -6886,6 +7052,268 @@ window.__ModuleLoader__.load({
|
|
|
6886
7052
|
startPluginUpdate();
|
|
6887
7053
|
}
|
|
6888
7054
|
|
|
7055
|
+
/**
|
|
7056
|
+
* 失败时要摊在按钮下方的那段原文。
|
|
7057
|
+
*
|
|
7058
|
+
* 取 `lastFailure` 的 stdout + stderr(宿主跑 pnpm 失败时带回来的原话),
|
|
7059
|
+
* 两者都空才退回 summary —— summary 是提炼过的中文摘要,能看但不能排查。
|
|
7060
|
+
*
|
|
7061
|
+
* **截断而不是限高**:用户明确要求不要滚动,所以靠减少字符数控制高度,
|
|
7062
|
+
* 取**尾部**(pnpm 的失败结论总在最后几行),并在开头留一行说明。
|
|
7063
|
+
*
|
|
7064
|
+
* @returns {string} 空串表示没有可显示的内容(渲染侧据此整块不出现)
|
|
7065
|
+
*/
|
|
7066
|
+
function updateErrorText(translate) {
|
|
7067
|
+
const tr = typeof translate === "function" ? translate : null;
|
|
7068
|
+
const failure = lastUpdateFailure;
|
|
7069
|
+
if (failure === null || failure === undefined || typeof failure !== "object") return "";
|
|
7070
|
+
const parts = [];
|
|
7071
|
+
const stdout = typeof failure.stdout === "string" ? failure.stdout.trim() : "";
|
|
7072
|
+
const stderr = typeof failure.stderr === "string" ? failure.stderr.trim() : "";
|
|
7073
|
+
if (stderr.length > 0) parts.push(stderr);
|
|
7074
|
+
if (stdout.length > 0) parts.push(stdout);
|
|
7075
|
+
let text = parts.length > 0
|
|
7076
|
+
? parts.join("\n")
|
|
7077
|
+
: (typeof failure.summary === "string" ? failure.summary.trim() : "");
|
|
7078
|
+
if (text.length === 0) return "";
|
|
7079
|
+
if (text.length > UPDATE_ERROR_MAX_CHARS) {
|
|
7080
|
+
text = text.slice(-UPDATE_ERROR_MAX_CHARS);
|
|
7081
|
+
/* 截断提示走调用方传进来的 t;拿不到就退回英文一句 —— 不能因为少个文案
|
|
7082
|
+
就把整块报错吞掉(那正是这次要修的东西)。 */
|
|
7083
|
+
const note = tr === null
|
|
7084
|
+
? "(output is long; showing the last " + UPDATE_ERROR_MAX_CHARS + " characters)"
|
|
7085
|
+
: tr("updateErrorTruncated", { limit: UPDATE_ERROR_MAX_CHARS });
|
|
7086
|
+
text = note + "\n" + text;
|
|
7087
|
+
}
|
|
7088
|
+
return text;
|
|
7089
|
+
}
|
|
7090
|
+
|
|
7091
|
+
/** 失败原文展示的字符上限(尾部保留)。调大会把设置页撑得很长,调小会丢关键行。 */
|
|
7092
|
+
const UPDATE_ERROR_MAX_CHARS = 3000;
|
|
7093
|
+
|
|
7094
|
+
/**
|
|
7095
|
+
* 最近一次更新失败的原始记录(宿主返回的 `lastFailure`)。
|
|
7096
|
+
*
|
|
7097
|
+
* 放在模块级而不是 updateState 里:它是**诊断面**,不参与按钮的可见/禁用判断,
|
|
7098
|
+
* 混进状态机会让「按钮该不该出现」多出一个无关维度。
|
|
7099
|
+
*/
|
|
7100
|
+
let lastUpdateFailure = null;
|
|
7101
|
+
|
|
7102
|
+
/** 宿主自检结果里的 lastFailure 落到本地;没有就清空,避免显示上一次的旧报错。 */
|
|
7103
|
+
function syncLastUpdateFailure(value) {
|
|
7104
|
+
const next = value === null || value === undefined || typeof value !== "object" ? null : value;
|
|
7105
|
+
lastUpdateFailure = next;
|
|
7106
|
+
}
|
|
7107
|
+
|
|
7108
|
+
/** 测试用:直接摆一份失败记录,省得去驱动整条网络路径。 */
|
|
7109
|
+
function setLastUpdateFailure(value) {
|
|
7110
|
+
syncLastUpdateFailure(value);
|
|
7111
|
+
}
|
|
7112
|
+
|
|
7113
|
+
/* ------------------------------------------------- 官方图标(原样复刻)
|
|
7114
|
+
* 下面两个 SVG 的 path / rect 数值**逐字来自 DSH 自己的图标组件**
|
|
7115
|
+
* (`IconCopyOutlineRegular` / `IconCheckOutlineRegular`,取自 app.asar 里的
|
|
7116
|
+
* dsh-web-frontend 打包产物)。不许改任何一个数字 —— 用户明确要求
|
|
7117
|
+
* 「你画的绝对不行,复刻不了」,所以这里就是官方源码的搬运,不是重画。
|
|
7118
|
+
* viewBox / strokeWidth / aria-hidden 也一并照抄,保证视觉完全一致。 */
|
|
7119
|
+
|
|
7120
|
+
/** 官方 `IconCopyOutlineRegular`:两个叠放的方框。 */
|
|
7121
|
+
function IconCopyOutline() {
|
|
7122
|
+
return h("svg", {
|
|
7123
|
+
width: 16, height: 16, viewBox: "0 0 16 16", fill: "none",
|
|
7124
|
+
xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", strokeWidth: 1
|
|
7125
|
+
}, [
|
|
7126
|
+
h("rect", {
|
|
7127
|
+
key: "r", x: "1.52075", y: "4.07373", width: "10.3932", height: "10.3932", rx: "2", stroke: "currentColor"
|
|
7128
|
+
}),
|
|
7129
|
+
h("path", {
|
|
7130
|
+
key: "p",
|
|
7131
|
+
d: "M11.9792 1.53296C13.36 1.53296 14.4792 2.65225 14.4792 4.03296V9.42847C14.4792 10.3756 13.9521 11.1987 13.1755 11.6228V10.3298C13.3652 10.0787 13.4792 9.7674 13.4792 9.42847V4.03296C13.4792 3.20453 12.8077 2.53296 11.9792 2.53296H6.58374C6.27966 2.53301 5.99684 2.6235 5.7605 2.77905H4.42358C4.85652 2.03463 5.66056 1.53304 6.58374 1.53296H11.9792Z",
|
|
7132
|
+
fill: "currentColor"
|
|
7133
|
+
})
|
|
7134
|
+
]);
|
|
7135
|
+
}
|
|
7136
|
+
|
|
7137
|
+
/** 官方 `IconCheckOutlineRegular`:一条对勾。 */
|
|
7138
|
+
function IconCheckOutline() {
|
|
7139
|
+
return h("svg", {
|
|
7140
|
+
width: 16, height: 16, viewBox: "0 0 16 16", fill: "none",
|
|
7141
|
+
xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", strokeWidth: 1
|
|
7142
|
+
}, h("path", {
|
|
7143
|
+
d: "M2.25 8.5L5.49732 11.7473C5.90519 12.1552 6.57263 12.1344 6.95426 11.7018L13.75 4",
|
|
7144
|
+
stroke: "currentColor"
|
|
7145
|
+
}));
|
|
7146
|
+
}
|
|
7147
|
+
|
|
7148
|
+
/** 复制成功后图标保持勾形态的时长 —— 与官方 `setTimeout(..., 1e3)` 同一个值。 */
|
|
7149
|
+
const COPY_FEEDBACK_MS = 1000;
|
|
7150
|
+
|
|
7151
|
+
/**
|
|
7152
|
+
* 写剪贴板。返回 Promise<boolean>,失败不抛。
|
|
7153
|
+
*
|
|
7154
|
+
* 优先 `navigator.clipboard.writeText`(Electron 里有);不可用时退回
|
|
7155
|
+
* 临时 textarea + `document.execCommand('copy')` —— 后者虽已废弃,但它是
|
|
7156
|
+
* 没有 clipboard API 的环境里唯一还能用的路径。
|
|
7157
|
+
*
|
|
7158
|
+
* @param {string} text
|
|
7159
|
+
* @returns {Promise<boolean>}
|
|
7160
|
+
*/
|
|
7161
|
+
function writeClipboardText(text) {
|
|
7162
|
+
const value = typeof text === "string" ? text : String(text);
|
|
7163
|
+
try {
|
|
7164
|
+
if (typeof navigator !== "undefined" && navigator !== null
|
|
7165
|
+
&& navigator.clipboard !== undefined && navigator.clipboard !== null
|
|
7166
|
+
&& typeof navigator.clipboard.writeText === "function") {
|
|
7167
|
+
return navigator.clipboard.writeText(value).then(() => true).catch(() => legacyCopy(value));
|
|
7168
|
+
}
|
|
7169
|
+
} catch (error) {
|
|
7170
|
+
/* 落到下面的老办法 */
|
|
7171
|
+
}
|
|
7172
|
+
return Promise.resolve(legacyCopy(value));
|
|
7173
|
+
}
|
|
7174
|
+
|
|
7175
|
+
/** 老式复制:临时塞一个 textarea,选中,execCommand,然后立刻清掉。 */
|
|
7176
|
+
function legacyCopy(value) {
|
|
7177
|
+
try {
|
|
7178
|
+
if (typeof document === "undefined" || document === null) return false;
|
|
7179
|
+
if (typeof document.createElement !== "function" || typeof document.execCommand !== "function") return false;
|
|
7180
|
+
const area = document.createElement("textarea");
|
|
7181
|
+
area.value = value;
|
|
7182
|
+
area.setAttribute("readonly", "");
|
|
7183
|
+
area.style.position = "fixed";
|
|
7184
|
+
area.style.top = "-9999px";
|
|
7185
|
+
document.body.appendChild(area);
|
|
7186
|
+
area.select();
|
|
7187
|
+
const ok = document.execCommand("copy") === true;
|
|
7188
|
+
document.body.removeChild(area);
|
|
7189
|
+
return ok;
|
|
7190
|
+
} catch (error) {
|
|
7191
|
+
return false;
|
|
7192
|
+
}
|
|
7193
|
+
}
|
|
7194
|
+
|
|
7195
|
+
/**
|
|
7196
|
+
* 复制按钮的点击处理:复制成功后把图标切成勾,`COPY_FEEDBACK_MS` 之后切回来。
|
|
7197
|
+
*
|
|
7198
|
+
* 照官方的三条纪律:
|
|
7199
|
+
* · 已经在「已复制」态或上一次还没回来时,重复点击直接忽略;
|
|
7200
|
+
* · **复制失败不显示勾**(否则用户会以为复制成功了);
|
|
7201
|
+
* · 卸载 / 重新渲染时清掉定时器,避免迟到的 setState。
|
|
7202
|
+
*
|
|
7203
|
+
* @param {string} text 要复制的完整原文
|
|
7204
|
+
*/
|
|
7205
|
+
function onCopyUpdateError(text) {
|
|
7206
|
+
/* 状态**只认 updateState.errorCopied 这一份**:早先还有一个模块级
|
|
7207
|
+
`copyErrorCopied` 与之并存,两处各自维护同一件事,改一处忘另一处就会不同步。
|
|
7208
|
+
`copyErrorPending` 仍然需要(它是"正在写剪贴板"的瞬时锁,不该进状态机)。 */
|
|
7209
|
+
if (updateState.errorCopied === true || copyErrorPending === true) return;
|
|
7210
|
+
copyErrorPending = true;
|
|
7211
|
+
writeClipboardText(text).then((ok) => {
|
|
7212
|
+
copyErrorPending = false;
|
|
7213
|
+
if (ok !== true) return;
|
|
7214
|
+
/* **必须走 setUpdateState 而不是只 notify**:`useSyncExternalStore` 是拿
|
|
7215
|
+
快照对象引用比对的,只发通知而快照还是同一个对象 ⇒ React 认为没变化、
|
|
7216
|
+
不重渲染 ⇒ 勾永远不出现(实测就是这个症状)。把「已复制」放进
|
|
7217
|
+
updateState 才会产生新对象引用,界面才真的重画。 */
|
|
7218
|
+
setUpdateState({ errorCopied: true });
|
|
7219
|
+
if (copyErrorTimer !== null) clearTimeout(copyErrorTimer);
|
|
7220
|
+
copyErrorTimer = setTimeout(() => {
|
|
7221
|
+
copyErrorTimer = null;
|
|
7222
|
+
setUpdateState({ errorCopied: false });
|
|
7223
|
+
}, COPY_FEEDBACK_MS);
|
|
7224
|
+
});
|
|
7225
|
+
}
|
|
7226
|
+
|
|
7227
|
+
/** 复制按钮的计时器;退出时清掉。 */
|
|
7228
|
+
let copyErrorTimer = null;
|
|
7229
|
+
let copyErrorPending = false;
|
|
7230
|
+
|
|
7231
|
+
/**
|
|
7232
|
+
* 复制用的**完整**原文(不截断)。
|
|
7233
|
+
*
|
|
7234
|
+
* 与 `updateErrorText()` 分开:那一份是**显示用**的(截到 3000 字符,为了不让
|
|
7235
|
+
* 设置页无限变长),而用户点复制是为了贴给 AI 排查,截断就没用了。
|
|
7236
|
+
*
|
|
7237
|
+
* @returns {string}
|
|
7238
|
+
*/
|
|
7239
|
+
function updateErrorFullText() {
|
|
7240
|
+
const failure = lastUpdateFailure;
|
|
7241
|
+
if (failure === null || failure === undefined || typeof failure !== "object") return "";
|
|
7242
|
+
const parts = [];
|
|
7243
|
+
const stderr = typeof failure.stderr === "string" ? failure.stderr.trim() : "";
|
|
7244
|
+
const stdout = typeof failure.stdout === "string" ? failure.stdout.trim() : "";
|
|
7245
|
+
if (stderr.length > 0) parts.push(stderr);
|
|
7246
|
+
if (stdout.length > 0) parts.push(stdout);
|
|
7247
|
+
if (parts.length > 0) return parts.join("\n");
|
|
7248
|
+
return typeof failure.summary === "string" ? failure.summary.trim() : "";
|
|
7249
|
+
}
|
|
7250
|
+
|
|
7251
|
+
/** 测试用:把 `.dsb-update-error` 那条 CSS 规则原样取出来,断言"不许滚动"这类约束。 */
|
|
7252
|
+
function updateErrorCss() {
|
|
7253
|
+
/* 直接按规则文本找:`CSS` 是模块顶层的常量数组,用 join 之后再做一次精确匹配,
|
|
7254
|
+
不依赖数组元素类型(注释行里也提到这个类名,所以只认带 `{` 的选择器行)。 */
|
|
7255
|
+
const all = Array.isArray(CSS) ? CSS.join("\n") : String(CSS);
|
|
7256
|
+
const hit = all.match(/\.dsb-update-error\s*\{[^}]*\}/);
|
|
7257
|
+
return hit === null ? "" : hit[0];
|
|
7258
|
+
}
|
|
7259
|
+
|
|
7260
|
+
/**
|
|
7261
|
+
* 静默自动修复:更新失败后在后台把本插件重新对齐一次。
|
|
7262
|
+
*
|
|
7263
|
+
* 为什么自动做:失败后 profile 可能停在「package.json 写新版、node_modules 还是旧版」
|
|
7264
|
+
* 的矛盾态,用户下次点更新会被 pnpm 当成"已经装好了"。这个矛盾**不该让用户
|
|
7265
|
+
* 再点一次按钮去收拾** —— 用户原话:「修复安装其实你安装失败就应该自动修复回去啊,
|
|
7266
|
+
* 而不是让我再点一次」。
|
|
7267
|
+
*
|
|
7268
|
+
* 为什么静默:它是兜底动作,不是用户发起的操作。成功失败都不改界面状态,
|
|
7269
|
+
* 失败也不写失败态(否则会出现"更新失败 → 自动修复 → 又一条失败"的连环提示)。
|
|
7270
|
+
* 只记一条日志,排查时能看到它跑过。
|
|
7271
|
+
*/
|
|
7272
|
+
function autoRepairSilently() {
|
|
7273
|
+
try {
|
|
7274
|
+
window.fetch(SELF_UPDATE_URL + "?mode=repair", {
|
|
7275
|
+
method: "POST",
|
|
7276
|
+
headers: { "content-type": "application/json" },
|
|
7277
|
+
body: "{}"
|
|
7278
|
+
}).then((response) => {
|
|
7279
|
+
if (response.ok !== true) return null;
|
|
7280
|
+
return response.json();
|
|
7281
|
+
}).then((payload) => {
|
|
7282
|
+
/* 静默:不 setUpdateState。宿主侧已经记了日志,这里什么都不用做。 */
|
|
7283
|
+
void payload;
|
|
7284
|
+
}).catch(() => { /* 静默 */ });
|
|
7285
|
+
} catch (error) {
|
|
7286
|
+
/* 静默 */
|
|
7287
|
+
}
|
|
7288
|
+
}
|
|
7289
|
+
|
|
7290
|
+
/**
|
|
7291
|
+
* 失败态出现后把报错块滚进视野。
|
|
7292
|
+
*
|
|
7293
|
+
* 用 `setTimeout(0)` 等一帧再滚:块是这一次渲染才挂上的,同步滚会找不到节点。
|
|
7294
|
+
* 滚动交给 `revealBottom`:它只在底边**真的被裁掉**时才补差值,已经看得见就一动不动。
|
|
7295
|
+
*/
|
|
7296
|
+
function scheduleErrorScroll() {
|
|
7297
|
+
try {
|
|
7298
|
+
setTimeout(() => {
|
|
7299
|
+
/* 沙箱 / 非浏览器环境里 `document` 可能整个不存在或没有 querySelector
|
|
7300
|
+
(测试用的 vm 替身就是这样)。这里必须自己判一次 —— try/catch 包不住
|
|
7301
|
+
定时器回调里的异常,抛出去会直接炸掉整个测试进程。 */
|
|
7302
|
+
if (typeof document === "undefined" || document === null) return;
|
|
7303
|
+
if (typeof document.querySelector !== "function") return;
|
|
7304
|
+
const node = document.querySelector(".dsb-update-error");
|
|
7305
|
+
if (node === null || node === undefined) return;
|
|
7306
|
+
/* **复用 `revealBottom`,不用 `scrollIntoView`**:
|
|
7307
|
+
项目里已经因为 scrollIntoView 只保证顶部对齐、滚不动面板内部可滚容器
|
|
7308
|
+
而把它全线换掉了(见 task-19 与 verify.js 那条禁令)。这里的场景一模一样 ——
|
|
7309
|
+
设置面板自己就是个可滚容器,用 revealBottom 才能把报错块的底边带进视野。 */
|
|
7310
|
+
revealBottom(node);
|
|
7311
|
+
}, 0);
|
|
7312
|
+
} catch (error) {
|
|
7313
|
+
/* 静默:滚不动不影响功能 */
|
|
7314
|
+
}
|
|
7315
|
+
}
|
|
7316
|
+
|
|
6889
7317
|
/** 开发模式当前是否开着(给测试与自检读)。 */
|
|
6890
7318
|
function isDevMode() {
|
|
6891
7319
|
return devMode;
|
|
@@ -6914,15 +7342,21 @@ window.__ModuleLoader__.load({
|
|
|
6914
7342
|
必须立刻生效 / 撤销。 */
|
|
6915
7343
|
publishDev();
|
|
6916
7344
|
if (devTimer !== null) { clearTimeout(devTimer); devTimer = null; }
|
|
7345
|
+
/* 失败原因的轮换游标也归零:下次进开发模式从第一个分类开始看起,
|
|
7346
|
+
不会接着上次停的那个往下走(与字段计数归零同一个理由)。 */
|
|
7347
|
+
devFailureScene = 0;
|
|
7348
|
+
/* 演示用的假报错原文也清掉:否则退出开发模式后,那块报错会继续挂在真实界面上,
|
|
7349
|
+
看起来像真的更新失败过。真实记录由下面那次 loadUpdateFlag 重新取回。 */
|
|
7350
|
+
syncLastUpdateFailure(null);
|
|
6917
7351
|
if (devMode === true) {
|
|
6918
|
-
setUpdateState({ hasUpdate: true, latest: DEV_VERSION, busy: false, note: null, reason: null });
|
|
7352
|
+
setUpdateState({ hasUpdate: true, latest: DEV_VERSION, busy: false, note: null, reason: null, mode: "update" });
|
|
6919
7353
|
} else {
|
|
6920
7354
|
/* 关掉时**同步**把演示相关状态一次清干净:忙碌态、结论、演示版本、按钮可见性。
|
|
6921
7355
|
这几项都先落到「没有更新」,再去问真实的 registry 结果 —— 反过来(先等网络)
|
|
6922
7356
|
会让按钮在关掉之后还多显示一会儿,看起来像没关掉。
|
|
6923
7357
|
清 busy 尤其必要:演示可能正停在「更新中」,只撤按钮不撤 busy,
|
|
6924
7358
|
界面会留在一个永远转下去的「正在更新中」。 */
|
|
6925
|
-
setUpdateState({ hasUpdate: false, latest: null, busy: false, note: null, reason: null });
|
|
7359
|
+
setUpdateState({ hasUpdate: false, latest: null, busy: false, note: null, reason: null, failedTarget: null, mode: "update" });
|
|
6926
7360
|
loadUpdateFlag().then((result) => {
|
|
6927
7361
|
if (result !== null) setUpdateState(result);
|
|
6928
7362
|
});
|
|
@@ -7440,7 +7874,12 @@ window.__ModuleLoader__.load({
|
|
|
7440
7874
|
/* **只有真的拿到余额才覆盖**:某一轮失败(平台临时 5xx / 超时 / 该平台没配 key)
|
|
7441
7875
|
不能把上一次成功的数字换成空,否则底栏会在 ¥12.34 与 ¥- 之间来回跳,
|
|
7442
7876
|
用户每次抬眼看到的都是"查不到"。 */
|
|
7443
|
-
if (alive && data !== null && data !== undefined && data.ok === true)
|
|
7877
|
+
if (alive && data !== null && data !== undefined && data.ok === true) {
|
|
7878
|
+
/* 顺带接住 host 维护的当前汇率(余额折算要用它);没带就保持上一次的值。 */
|
|
7879
|
+
const rate = Number(data.exchangeRate);
|
|
7880
|
+
if (Number.isFinite(rate) === true && rate > 0) liveExchangeRate = rate;
|
|
7881
|
+
setBalance(data);
|
|
7882
|
+
}
|
|
7444
7883
|
})
|
|
7445
7884
|
.catch(() => { /* 网络异常同样保留上一次成功值(首次就一直保持 null = 横杠) */ });
|
|
7446
7885
|
};
|
|
@@ -9134,17 +9573,26 @@ window.__ModuleLoader__.load({
|
|
|
9134
9573
|
disabled: update.busy === true,
|
|
9135
9574
|
onClick: onUpdateClick
|
|
9136
9575
|
}, update.busy === true
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
|
|
9576
|
+
/* 修复进行中时这颗按钮只是被禁用,文案仍是「更新失败」——
|
|
9577
|
+
「修复安装中」由旁边那颗修复按钮自己显示,不在这里重复一遍。 */
|
|
9578
|
+
? (update.mode === "repair"
|
|
9579
|
+
? t("updateFailed")
|
|
9580
|
+
: [t("updateRunning"), h("span", { className: "dsb-dots", key: "__dots" }, [
|
|
9581
|
+
h("span", { key: "__d1" }, "."),
|
|
9582
|
+
h("span", { key: "__d2" }, "."),
|
|
9583
|
+
h("span", { key: "__d3" }, ".")
|
|
9584
|
+
])])
|
|
9142
9585
|
: (update.note === "done"
|
|
9143
9586
|
? t("updateDone")
|
|
9144
9587
|
: (update.note === "failed"
|
|
9145
9588
|
? t("updateFailed")
|
|
9146
9589
|
: t("updateTo", { version: update.latest === null ? "" : update.latest }))))
|
|
9147
9590
|
: null,
|
|
9591
|
+
/* 「修复安装」按钮已删除:修复现在**失败后自动静默执行**(见 autoRepairSilently),
|
|
9592
|
+
用户不需要、也不应该再点一次。用户原话:「修复安装其实你安装失败就应该
|
|
9593
|
+
自动修复回去啊,而不是让我再点一次」「不要显示任何呀,你的修复就应该静默修复」。
|
|
9594
|
+
保留一颗按钮等于把已经自动做完的事再摆到用户面前,只会让人以为还没修。
|
|
9595
|
+
宿主侧的 `?mode=repair` 路由仍然保留(自动修复在用它),只是不再有手动入口。 */
|
|
9148
9596
|
/* 版本标记贴右、与行内底边对齐:这行字让「现在跑的是哪一版」一眼可见 ——
|
|
9149
9597
|
注意**光刷新页面看不出差别**:插件包元数据缓存至重启,刷新拿到的还是旧 bundle;
|
|
9150
9598
|
要换版本必须重启 DSH,重启后这行字才会变成新号。
|
|
@@ -9157,7 +9605,26 @@ window.__ModuleLoader__.load({
|
|
|
9157
9605
|
className: "dsb-version",
|
|
9158
9606
|
key: "__version",
|
|
9159
9607
|
onClick: onVersionClicked
|
|
9160
|
-
}, "dsh-desktop-statusbar " + VERSION)
|
|
9608
|
+
}, "dsh-desktop-statusbar " + VERSION),
|
|
9609
|
+
/* 更新失败时把 pnpm 的原文**直接摊在这一行下方**。
|
|
9610
|
+
用户要求原话:「可以常驻显示,但是不需要我滚动,直接就是滑倒最下面展示全文」——
|
|
9611
|
+
所以这里不折叠、不弹窗、不做成小滚动框,就是一整块跟着页面往下长。
|
|
9612
|
+
超长输出靠 `updateErrorText()` 截到固定字符数,而不是靠容器限高(那样就又变成滚动了)。 */
|
|
9613
|
+
update.note === "failed" && updateErrorText(t) !== ""
|
|
9614
|
+
? h("pre", { className: "dsb-update-error", key: "__updateError" }, [
|
|
9615
|
+
/* 原文与复制按钮同在一个 `pre` 里,但按钮是**绝对定位**(见 CSS),
|
|
9616
|
+
所以它钉在报错块的右下角、绝对靠右,不占文字流的空间。
|
|
9617
|
+
用户原话:「绝对靠右啊」。 */
|
|
9618
|
+
updateErrorText(t),
|
|
9619
|
+
h("button", {
|
|
9620
|
+
type: "button",
|
|
9621
|
+
className: "dsb-update-error-copy",
|
|
9622
|
+
key: "__copy",
|
|
9623
|
+
"aria-label": update.errorCopied === true ? t("updateErrorCopied") : t("updateErrorCopy"),
|
|
9624
|
+
onClick: () => onCopyUpdateError(updateErrorFullText())
|
|
9625
|
+
}, update.errorCopied === true ? IconCheckOutline() : IconCopyOutline())
|
|
9626
|
+
])
|
|
9627
|
+
: null
|
|
9161
9628
|
]));
|
|
9162
9629
|
|
|
9163
9630
|
return h("div", { className: "dsb-settings" }, sections);
|