dsh-folia 4.23.13 → 4.23.15
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 +1022 -36
- package/lib/download-queue.js +91 -2
- package/lib/index.js +10 -1
- package/lib/kernel/host-kernel.js +4 -0
- package/lib/media/transcode.js +176 -6
- package/lib/media-selfheal.js +403 -0
- package/lib/media-verify.js +222 -0
- package/lib/routes/downloads.js +157 -11
- package/lib/routes/inventory.js +11 -0
- package/lib/variant-pick.js +59 -0
- package/package.json +3 -1
package/lib/client.js
CHANGED
|
@@ -859,6 +859,8 @@ window.__ModuleLoader__.load({
|
|
|
859
859
|
// 由 src/local-first.js 的 `dlCardState()`(纯函数,四个页签共用)产出;
|
|
860
860
|
// `idle` / `done` 两个词仍由各页签自己给(安装 / 下载 / 使用中 / 已安装)。
|
|
861
861
|
"正在提交…": "Submitting…",
|
|
862
|
+
// 4.23.14:首帧反馈后 300ms 仍未进入 queued/running 的**占位**(避免慢请求静默)。
|
|
863
|
+
"提交中…(正在准备)": "Submitting… (preparing)",
|
|
862
864
|
"已等待 {s} 秒": "Waiting {s}s",
|
|
863
865
|
"解压/落位中…": "Extracting…",
|
|
864
866
|
// ── 「下载已完成但安装没落地」的自愈(4.23.6)──────────────────────────────
|
|
@@ -945,6 +947,38 @@ window.__ModuleLoader__.load({
|
|
|
945
947
|
"清理失败:{error}": "Cleanup failed: {error}",
|
|
946
948
|
"已清理 {name}:释放 {size}({n} 个文件)": "Cleared {name}: released {size} ({n} files)",
|
|
947
949
|
"已清理 {name}:释放 {size}({n} 个文件);{failed} 个文件被占用,重启 DSH 后彻底生效": "Cleared {name}: released {size} ({n} files); {failed} file(s) in use will be removed after restarting DSH",
|
|
950
|
+
|
|
951
|
+
// ── 4.23.15「本地副本自愈」(播放失败 → 验内容 → 重下 / 换档 / 转码)───────────────
|
|
952
|
+
// 这三句是**给用户看的结论**,不是日志:它们回答"我刚点的那张为什么没出来、现在在干什么"。
|
|
953
|
+
"文件已损坏,已重新下载": "The local file was corrupted — re-downloading it now",
|
|
954
|
+
"已自动切换 1080p(原画超出本机解码上限)": "Switched to 1080p automatically (the original exceeds this machine's decode limit)",
|
|
955
|
+
"原画超出本机解码上限,已生成本机可播放的 1080p 副本": "The original exceeds this machine's decode limit — generated a playable 1080p copy",
|
|
956
|
+
"原画超出本机解码上限,正在生成可播放副本…": "The original exceeds this machine's decode limit — preparing a playable copy…",
|
|
957
|
+
"本机不支持该编码(可换一张跳过此壁纸)": "This machine cannot decode that codec (pick another wallpaper to skip it)",
|
|
958
|
+
"该壁纸分辨率/编码超出本机解码能力(可换一张跳过此壁纸)": "This wallpaper's resolution/codec exceeds this machine's decoding capability (pick another one to skip it)",
|
|
959
|
+
"重新获取失败(可稍后再点一次这张)": "Re-fetch failed (click this wallpaper again in a moment)",
|
|
960
|
+
"转码超时(可稍后再点一次这张,宿主会接着上次的进度)": "Transcoding timed out (click this wallpaper again later; the host resumes from its last progress)",
|
|
961
|
+
"{text} · {label}": "{text} · {label}",
|
|
962
|
+
// ── 4.23.15「本地媒体自检」读数与按钮(系统 → 缓存管理)────────────────────────
|
|
963
|
+
"损坏文件": "Corrupted files",
|
|
964
|
+
"个(已清理 {cleaned} / 待重下 {pending})": "(cleaned {cleaned} / pending re-download {pending})",
|
|
965
|
+
"未校验(进本页签时自动读一次)": "Not checked yet (read automatically when you open this tab)",
|
|
966
|
+
"重新读取校验账本(只读,不触发校验)": "Re-read the verification ledger (read-only, does not start a check)",
|
|
967
|
+
"校验中…": "Checking…",
|
|
968
|
+
"校验并修复本地媒体": "Verify and repair local media",
|
|
969
|
+
"逐个校验已下载的媒体文件(≤20MB 比 sha256,大文件比长度与 mp4 结构);发现坏文件就删掉并排回下载队列": "Verify every downloaded media file one by one (sha256 for files ≤20MB, length + MP4 structure for larger ones); corrupted files are deleted and queued for re-download",
|
|
970
|
+
"已校验 {n} 个文件:发现 {bad} 个损坏,已清理并排回下载队列": "Checked {n} file(s): found {bad} corrupted, cleaned up and re-queued for download",
|
|
971
|
+
"已校验 {n} 个文件:没有发现损坏": "Checked {n} file(s): nothing corrupted",
|
|
972
|
+
"校验失败:{error}": "Verification failed: {error}",
|
|
973
|
+
// ── 4.23.15「已按解码上限选 1080p」(卡片小标)──────────────────────────────
|
|
974
|
+
"已按解码上限选 1080p": "1080p chosen for decode limit",
|
|
975
|
+
"解码上限 · 1080p": "Decode limit · 1080p",
|
|
976
|
+
"已按解码上限选 1080p:原画 {w}×{h} 超出本机解码能力(播放器解不出来),改播 1080p 变体": "1080p chosen because of the decode limit: the original is {w}×{h}, beyond this machine's decoding capability (the player cannot decode it), so the 1080p variant is used",
|
|
977
|
+
// ── 4.23.15「转码进度 / 静态帧兜底」(用户最终目标:最终必须能上屏)───────────────
|
|
978
|
+
"正在生成本机可播放副本 {percent}%": "Preparing a playable copy on this machine… {percent}%",
|
|
979
|
+
"正在生成本机可播放副本 {percent}%(约剩 {eta} 秒)": "Preparing a playable copy on this machine… {percent}% (about {eta}s left)",
|
|
980
|
+
"已降级为静态壁纸(本机不支持该视频解码)": "Fell back to a static wallpaper (this machine cannot decode the video)",
|
|
981
|
+
"无法显示这张壁纸(本机不支持该视频解码,且没有可用的静态帧)": "Cannot display this wallpaper (this machine cannot decode the video and no static frame is available)",
|
|
948
982
|
};
|
|
949
983
|
|
|
950
984
|
// ── 内联模块:src/i18n-copy-picker.js —— 英文词表域:壁纸选择器与快捷面板(picker-* · quick-panel · sidebar-right · theme-follow)(构建期注入;勿手改本段)──
|
|
@@ -5009,6 +5043,22 @@ window.__ModuleLoader__.load({
|
|
|
5009
5043
|
font-size: 12px; line-height: 18px; text-align: center;
|
|
5010
5044
|
}
|
|
5011
5045
|
|
|
5046
|
+
/* ── 4.23.14:首次点击的**同步**反馈(四类入口共用)─────────────────────────
|
|
5047
|
+
真实故障:皮肤卡片「安装」第一下没有任何反馈、第二下才有反应。
|
|
5048
|
+
这两条规则把 dlFirstClickFeedback() 同步加上的 class 变成**看得见**的变化:
|
|
5049
|
+
.we-first-click 挂在卡片上(皮肤/开机动画/桌宠卡带 we-dl-card,壁纸库/快捷面板
|
|
5050
|
+
是 we-picker__card / we-qp__item / we-qp__card),.we-first-click-btn 挂在按钮上。
|
|
5051
|
+
只动 opacity/transform:不动配色,不受主题变量影响;撤销由各自的 restore()/状态机负责。 */
|
|
5052
|
+
.we-first-click {
|
|
5053
|
+
opacity: 0.68;
|
|
5054
|
+
transform: scale(0.985);
|
|
5055
|
+
transition: opacity 120ms linear, transform 120ms ease-out;
|
|
5056
|
+
}
|
|
5057
|
+
.we-first-click-btn { opacity: 0.8; }
|
|
5058
|
+
/* 壁纸快捷面板/选择器原本就在按 pointerdown 时加这个 class(video-switch.js),
|
|
5059
|
+
但 CSS 里一直没有对应规则 ⇒ 按下其实**看不见**。这一条把它补齐(同一观感)。 */
|
|
5060
|
+
.we-qp__item--pressed { opacity: 0.68; }
|
|
5061
|
+
|
|
5012
5062
|
`;
|
|
5013
5063
|
|
|
5014
5064
|
// ── 内联模块:src/styles-quick.js —— 样式域 quick(原 styles.js 2926–3357):Rope dock · 快捷播放面板 QuickPanel(构建期注入;勿手改本段)──
|
|
@@ -14384,6 +14434,9 @@ window.__ModuleLoader__.load({
|
|
|
14384
14434
|
// 播放失败原因(#84): 浏览器解不了的编码 / 解码失败等 —— 给出可读原因,
|
|
14385
14435
|
// 配合下面的「播放」按钮重试(不是静默空白)。
|
|
14386
14436
|
sel.videoError && React.createElement("div", { className: "we-picker__current-error" }, sel.videoError),
|
|
14437
|
+
// 4.23.15:**自愈/本地优先**的信息类提示("已自动切换 1080p""正在下载到本地 45%"…)。
|
|
14438
|
+
// 与上面那条分开:那条是"红了",这条是"正在处理/已经换好了"。
|
|
14439
|
+
sel.mediaNote && React.createElement("div", { className: "we-picker__hint" }, sel.mediaNote),
|
|
14387
14440
|
// 选择被过滤条件排除(#84): 明确指出是哪一项过滤挡住了、怎么恢复
|
|
14388
14441
|
sel.blockedNote && React.createElement("div", { className: "we-picker__current-error" }, sel.blockedNote),
|
|
14389
14442
|
// 实时渲染失败原因(自动回退到旧链时显示):让「为什么黑」可见 ——
|
|
@@ -16044,6 +16097,7 @@ window.__ModuleLoader__.load({
|
|
|
16044
16097
|
*/
|
|
16045
16098
|
function renderCacheManagerBlock(ctx) {
|
|
16046
16099
|
const { sel, onClearCache, onClearCacheSkins, onRefreshCacheUsage, armedConfirm, onDisarmConfirm } = ctx;
|
|
16100
|
+
const { onVerifyMedia, onRefreshMediaHealth } = ctx;
|
|
16047
16101
|
const usage = sel && sel.cacheUsage;
|
|
16048
16102
|
const items = (usage && Array.isArray(usage.items)) ? usage.items : [];
|
|
16049
16103
|
const rowOf = (t) => items.find((x) => x && x.target === t) || null;
|
|
@@ -16070,6 +16124,14 @@ window.__ModuleLoader__.load({
|
|
|
16070
16124
|
);
|
|
16071
16125
|
};
|
|
16072
16126
|
const pendingSkins = String(armedConfirm || "") === "cache:skins";
|
|
16127
|
+
// ── 4.23.15「本地媒体自检」读数:**损坏文件 N 个(已清理/待重下)** ──
|
|
16128
|
+
// 为什么放在缓存区而不新开一节:用户是在"我的缓存怎么了"这个问题下看到它的;
|
|
16129
|
+
// 而「系统」页签的节序列是 `verify-scene-live` 的硬锚,不能为一行统计新开一节。
|
|
16130
|
+
const health = sel && sel.mediaHealth;
|
|
16131
|
+
const bad = health ? Number(health.damaged) || 0 : 0;
|
|
16132
|
+
const cleaned = health ? Number(health.cleaned) || 0 : 0;
|
|
16133
|
+
const pending = health ? Number(health.pending) || 0 : 0;
|
|
16134
|
+
const verifying = Boolean(sel && sel.mediaVerifyBusy);
|
|
16073
16135
|
return React.createElement(React.Fragment, null,
|
|
16074
16136
|
// ⚠️ 这一行**故意不用** `we-picker__section-label`:那会把「缓存管理」算成第八个"节",
|
|
16075
16137
|
// 改掉 `verify-scene-live` 的节序列锚(见上面"为什么放在同一个节里")。
|
|
@@ -16093,6 +16155,22 @@ window.__ModuleLoader__.load({
|
|
|
16093
16155
|
line("skins-zip", weT("皮肤包")),
|
|
16094
16156
|
line("skins", weT("已装皮肤")),
|
|
16095
16157
|
line("electron", weT("Electron 缓存"), weT("需重启 DSH")),
|
|
16158
|
+
// ── 本地媒体自检(4.23.15)──────────────────────────────────────────────
|
|
16159
|
+
// 读数口径与宿主 `/folia/local-check` 逐字一致:`damaged` 是**累计发现**的坏文件,
|
|
16160
|
+
// `cleaned` 是其中已删并排回下载队列的,`pending` 是还没修好的(还在队列里等重下)。
|
|
16161
|
+
React.createElement("div", { className: "we-picker__row", key: "media-health" },
|
|
16162
|
+
React.createElement("span", { className: "we-picker__hint we-picker__label" }, weT("损坏文件")),
|
|
16163
|
+
React.createElement("span", { className: "we-picker__uploads-path" },
|
|
16164
|
+
health
|
|
16165
|
+
? String(bad) + " " + weT("个(已清理 {cleaned} / 待重下 {pending})", { cleaned, pending })
|
|
16166
|
+
: weT("未校验(进本页签时自动读一次)")),
|
|
16167
|
+
React.createElement("button", {
|
|
16168
|
+
key: "media-health-refresh", type: "button", className: "we-picker__btn",
|
|
16169
|
+
disabled: verifying,
|
|
16170
|
+
title: weT("重新读取校验账本(只读,不触发校验)"),
|
|
16171
|
+
onClick: () => { try { onRefreshMediaHealth(); } catch { /* ignore */ } },
|
|
16172
|
+
}, weT("刷新")),
|
|
16173
|
+
),
|
|
16096
16174
|
React.createElement("div", { className: "we-picker__row", key: "cache-mgr-actions" },
|
|
16097
16175
|
btn("clear-library", weT("清空媒体"), ["library"], weT("删除已下载的壁纸 / 开机动画 / 桌宠(可重新下载)")),
|
|
16098
16176
|
btn("clear-site-media", weT("清空站点媒体"), ["site-media"]),
|
|
@@ -16118,7 +16196,17 @@ window.__ModuleLoader__.load({
|
|
|
16118
16196
|
btn("clear-electron", weT("清空 Electron 缓存"), ["electron"], weT("清的是 Electron 自己的 Cache / GPUCache;占用中的文件请重启 DSH 后彻底生效")),
|
|
16119
16197
|
btn("clear-all-but-skins", weT("一键清理(不含皮肤)"),
|
|
16120
16198
|
["library", "site-media", "skins-zip", "electron"], weT("清掉除「已装皮肤」以外的全部缓存")),
|
|
16199
|
+
// 「校验并修复本地媒体」(4.23.15)= **启动自检的全量版**:逐条比 size / sha256 /
|
|
16200
|
+
// mp4 结构,坏的删掉并排回下载队列。它不是"清理"(不清好文件),所以单独一颗。
|
|
16201
|
+
React.createElement("button", {
|
|
16202
|
+
key: "verify-media", type: "button", className: "we-picker__btn",
|
|
16203
|
+
disabled: verifying,
|
|
16204
|
+
title: weT("逐个校验已下载的媒体文件(≤20MB 比 sha256,大文件比长度与 mp4 结构);发现坏文件就删掉并排回下载队列"),
|
|
16205
|
+
onClick: () => { try { onVerifyMedia(); } catch { /* ignore */ } },
|
|
16206
|
+
}, verifying ? weT("校验中…") : weT("校验并修复本地媒体")),
|
|
16121
16207
|
),
|
|
16208
|
+
sel && sel.mediaVerifyNote
|
|
16209
|
+
&& React.createElement("div", { className: "we-picker__hint", key: "media-verify-note" }, sel.mediaVerifyNote),
|
|
16122
16210
|
sel && sel.cacheNote
|
|
16123
16211
|
&& React.createElement("div", { className: "we-picker__hint", key: "cache-mgr-note" }, sel.cacheNote),
|
|
16124
16212
|
sel && sel.cacheError
|
|
@@ -16797,6 +16885,20 @@ window.__ModuleLoader__.load({
|
|
|
16797
16885
|
const PICKER_CARD_GAP = 8; // .we-picker__grid 的 gap
|
|
16798
16886
|
const PICKER_VP_FIRST = 30; // 还没量到窗口时的首帧条目数(关闭卡在内;量完立刻收窄)
|
|
16799
16887
|
|
|
16888
|
+
/**
|
|
16889
|
+
* 4.23.14:壁纸库卡片的**同步**点击反馈("第一次点击必然有可见变化")。
|
|
16890
|
+
*
|
|
16891
|
+
* 壁纸卡点击 = 应用当前壁纸 + 首次下载入口:`applySelection` 之后要等媒体准备/下载,
|
|
16892
|
+
* 之前这一整段没有任何按下反馈。这里只调 `dlFirstClickFeedback`(纯 DOM:卡片 pressed +
|
|
16893
|
+
* aria-busy),不 await、不发网络;卡片没有状态机来摘 pressed,所以 700ms 后自动复位。
|
|
16894
|
+
*/
|
|
16895
|
+
function pickerPressFeedback(el) {
|
|
16896
|
+
try {
|
|
16897
|
+
const release = typeof dlFirstClickFeedback === "function" ? dlFirstClickFeedback(el) : null;
|
|
16898
|
+
if (typeof release === "function" && typeof setTimeout === "function") setTimeout(release, 700);
|
|
16899
|
+
} catch { /* 反馈是增强:失败不影响点击本身 */ }
|
|
16900
|
+
}
|
|
16901
|
+
|
|
16800
16902
|
function renderPickerModal(ctx) {
|
|
16801
16903
|
const { sel, playableList, hiddenList, cdMode, vwin } = ctx;
|
|
16802
16904
|
// ── 库视图虚拟滚动(用户口径:**不要分页**)────────────────────
|
|
@@ -16903,7 +17005,9 @@ window.__ModuleLoader__.load({
|
|
|
16903
17005
|
role: "button",
|
|
16904
17006
|
tabIndex: 0,
|
|
16905
17007
|
title: w.title,
|
|
16906
|
-
onClick
|
|
17008
|
+
// 4.23.14:按下即反馈(同步 DOM),onClick 第一行再补一次 —— 点击/按下之间不给静默窗口。
|
|
17009
|
+
onPointerDown: (ev) => pickerPressFeedback(ev && ev.currentTarget),
|
|
17010
|
+
onClick: (ev) => { pickerPressFeedback(ev && ev.currentTarget); onPickCard(w); },
|
|
16907
17011
|
onKeyDown: cardKeyDown,
|
|
16908
17012
|
},
|
|
16909
17013
|
w.preview
|
|
@@ -16917,6 +17021,14 @@ window.__ModuleLoader__.load({
|
|
|
16917
17021
|
!sel.batchMode && !draft && CARD_TYPE_LABELS[w.type]
|
|
16918
17022
|
&& React.createElement("span", { className: "we-picker__card-type" }, CARD_TYPE_LABELS[w.type]),
|
|
16919
17023
|
React.createElement("span", { className: "we-picker__card-title" }, w.title),
|
|
17024
|
+
// 4.23.15:**已按解码上限选 1080p**。真实案例「原神 绫华」原画 5916×2530 ——
|
|
17025
|
+
// Chromium 根本解不出来。选档阶段避开它之后必须让用户**看得见**为什么下的是 1080p,
|
|
17026
|
+
// 否则他只会以为"画质被偷偷降了"。
|
|
17027
|
+
w.variantReason === "decode-limit"
|
|
17028
|
+
&& React.createElement("span", {
|
|
17029
|
+
className: "we-picker__card-badge",
|
|
17030
|
+
title: weT("已按解码上限选 1080p:原画 {w}×{h} 超出本机解码能力(播放器解不出来),改播 1080p 变体", { w: w.width || "?", h: w.height || "?" }),
|
|
17031
|
+
}, weT("已按解码上限选 1080p")),
|
|
16920
17032
|
w.type === "scene" && React.createElement("span", { className: "we-picker__card-badge" }, w.sceneLive ? weT("实时渲染") : weT("静态帧")),
|
|
16921
17033
|
w.type === "web" && React.createElement("span", { className: "we-picker__card-badge" }, w.webLive ? weT("实时渲染") : weT("兼容模式")),
|
|
16922
17034
|
(draft || sel.batchMode)
|
|
@@ -16969,7 +17081,9 @@ window.__ModuleLoader__.load({
|
|
|
16969
17081
|
tabIndex: 0,
|
|
16970
17082
|
title: w.title,
|
|
16971
17083
|
"aria-label": weT("恢复并应用 {name}", { name: w.title }),
|
|
16972
|
-
|
|
17084
|
+
// 4.23.14:与正常卡片同一套同步按下反馈(恢复=应用,也是"点了要有变化"的入口)。
|
|
17085
|
+
onPointerDown: (ev) => pickerPressFeedback(ev && ev.currentTarget),
|
|
17086
|
+
onClick: (ev) => { pickerPressFeedback(ev && ev.currentTarget); applySelection(w.id); },
|
|
16973
17087
|
// 键盘可达性:正常列表卡片一直有 Enter/Space 处理,
|
|
16974
17088
|
// 已隐藏卡片漏了 —— 补上(共享 cardKeyDown)。
|
|
16975
17089
|
onKeyDown: cardKeyDown,
|
|
@@ -17431,6 +17545,10 @@ window.__ModuleLoader__.load({
|
|
|
17431
17545
|
// 4.23.4:**卡片级**状态机(四页签共用,见 src/local-first.js 的 `dlCardState`)——
|
|
17432
17546
|
// 点击瞬间就有「正在提交…」,随后 排队 / 进度 / 解压 / 失败原因+重试,四模块同一套。
|
|
17433
17547
|
const cards = useDlCards(dl);
|
|
17548
|
+
// 4.23.14:300ms 占位要知道队列里是否已有这张卡片的 queued/running(闭包会读到点击瞬间的旧
|
|
17549
|
+
// 快照 ⇒ 用 ref 跟住最新值)。
|
|
17550
|
+
const jobsRef = React.useRef([]);
|
|
17551
|
+
jobsRef.current = dl.jobs;
|
|
17434
17552
|
// 只有这两个词属于本页签的口径。
|
|
17435
17553
|
const bootDlLabels = { idle: weT("下载"), done: weT("使用中"), failed: weT("重试") };
|
|
17436
17554
|
|
|
@@ -17496,7 +17614,7 @@ window.__ModuleLoader__.load({
|
|
|
17496
17614
|
}, [state, dl.jobs]);
|
|
17497
17615
|
|
|
17498
17616
|
|
|
17499
|
-
async function act(kind, payload, label) {
|
|
17617
|
+
async function act(kind, payload, label, ev, jobUrl) {
|
|
17500
17618
|
if (busy) return;
|
|
17501
17619
|
// 只有结构性操作(下载 / 选择 / 删除)才锁 UI;开关与参数是幂等的,锁了反而闪。
|
|
17502
17620
|
const structural = kind === "download" || kind === "select" || kind === "remove";
|
|
@@ -17505,11 +17623,27 @@ window.__ModuleLoader__.load({
|
|
|
17505
17623
|
// 4.23.3:**下载走队列后不再锁整页** —— 进度落在卡片上(dlBusyLabel),锁住反而让人
|
|
17506
17624
|
// 以为面板卡了。structural 的判据保持原样,只是在"真的 setBusy 吗"这一步把下载排除。
|
|
17507
17625
|
if (structural && kind !== "download") setBusy(payload && payload.id ? payload.id : kind);
|
|
17508
|
-
//
|
|
17509
|
-
if (isDownload
|
|
17510
|
-
setNote(null);
|
|
17626
|
+
// 非下载类沿用旧口径:先清上一轮提示。下载类交给 dlInstallClick(它先写即时反馈)。
|
|
17627
|
+
if (!isDownload) setNote(null);
|
|
17511
17628
|
try {
|
|
17512
|
-
|
|
17629
|
+
let resp;
|
|
17630
|
+
if (isDownload) {
|
|
17631
|
+
// 4.23.14:与皮肤页签**同一个**实现 —— 第一行同步反馈(按钮「正在提交…」+ 卡片 pressed +
|
|
17632
|
+
// aria-busy),再进卡片状态机,最后才发请求;300ms 没进队列就出「提交中…(正在准备)」。
|
|
17633
|
+
const click = await dlInstallClick({
|
|
17634
|
+
el: ev && ev.currentTarget,
|
|
17635
|
+
btnText: weT("正在提交…"),
|
|
17636
|
+
installed: false,
|
|
17637
|
+
begin: () => { cards.begin(cardId); },
|
|
17638
|
+
onSubmitting: () => { setNote({ ok: true, text: weT("正在提交…") }); },
|
|
17639
|
+
onPreparing: (text) => { setNote({ ok: true, text }); },
|
|
17640
|
+
jobActive: () => dlJobActive(dlJobForCard(jobsRef.current, "boot", jobUrl)),
|
|
17641
|
+
submit: () => apiPostJson("/boot/download", payload || {}, { parse: "always" }),
|
|
17642
|
+
});
|
|
17643
|
+
resp = click.resp;
|
|
17644
|
+
} else {
|
|
17645
|
+
resp = await apiPostJson("/boot/" + kind, payload || {}, { parse: "always" });
|
|
17646
|
+
}
|
|
17513
17647
|
const r = (resp && resp.data) || null;
|
|
17514
17648
|
if (resp && resp.ok && r && r.ok) {
|
|
17515
17649
|
if (kind === "download") {
|
|
@@ -17696,14 +17830,15 @@ window.__ModuleLoader__.load({
|
|
|
17696
17830
|
const actions = [];
|
|
17697
17831
|
if (!c.installed) {
|
|
17698
17832
|
// 只禁**这一张**卡片(提交中/排队/在下/解压);别的卡片在动不影响它。
|
|
17699
|
-
|
|
17833
|
+
// 4.23.14:把事件(被点的按钮)与本条 url 交给 act ⇒ 同步反馈 + 300ms 占位判定。
|
|
17834
|
+
actions.push(btn(label, (ev) => act("download", { id: c.id }, c.title, ev, c.url), st.disabled, true));
|
|
17700
17835
|
} else if (!isActive) {
|
|
17701
17836
|
actions.push(btn(weT("使用"), () => act("select", { id: c.id }, c.title), false, true));
|
|
17702
17837
|
actions.push(btn(weT("删除"), () => act("remove", { id: c.id }, c.title), isBusy, false));
|
|
17703
17838
|
} else {
|
|
17704
17839
|
actions.push(btn(weT("使用中"), () => {}, true, false));
|
|
17705
17840
|
}
|
|
17706
|
-
return React.createElement("div", { key: c.id, style: BOOT_STYLE.card },
|
|
17841
|
+
return React.createElement("div", { key: c.id, className: "we-dl-card", style: BOOT_STYLE.card },
|
|
17707
17842
|
// 封面:站点给了真正的缩略图才显示;老条目没有就留空(不显示破图)。
|
|
17708
17843
|
c.cover
|
|
17709
17844
|
? React.createElement("img", {
|
|
@@ -17797,6 +17932,10 @@ window.__ModuleLoader__.load({
|
|
|
17797
17932
|
// 4.23.4:**卡片级**状态机(四页签共用,见 src/local-first.js 的 `dlCardState`)——
|
|
17798
17933
|
// 点击瞬间就有「正在提交…」,随后 排队 / 进度 / 解压 / 失败原因+重试,四模块同一套。
|
|
17799
17934
|
const cards = useDlCards(dl);
|
|
17935
|
+
// 4.23.14:300ms 占位要知道队列里是否已有这张卡片的 queued/running(闭包会读到点击瞬间的旧
|
|
17936
|
+
// 快照 ⇒ 用 ref 跟住最新值)。
|
|
17937
|
+
const jobsRef = React.useRef([]);
|
|
17938
|
+
jobsRef.current = dl.jobs;
|
|
17800
17939
|
// 只有这两个词属于本页签的口径。
|
|
17801
17940
|
const petDlLabels = { idle: weT("安装"), done: weT("已安装"), failed: weT("重试") };
|
|
17802
17941
|
|
|
@@ -17866,7 +18005,7 @@ window.__ModuleLoader__.load({
|
|
|
17866
18005
|
}, [state, dl.jobs]);
|
|
17867
18006
|
|
|
17868
18007
|
|
|
17869
|
-
const act = async (kind, payload, label) => {
|
|
18008
|
+
const act = async (kind, payload, label, ev, jobUrl) => {
|
|
17870
18009
|
// 只有安装/卸载/导入这类**结构性**操作才锁 UI;开关与大小是幂等的。
|
|
17871
18010
|
const structural = kind === "install" || kind === "remove" || kind === "import";
|
|
17872
18011
|
const cardId = String((payload && payload.id) || "");
|
|
@@ -17874,11 +18013,28 @@ window.__ModuleLoader__.load({
|
|
|
17874
18013
|
// 4.23.3:安装走下载队列(payload.queue)时不锁整页 —— 进度落在卡片上,切页签回来仍在。
|
|
17875
18014
|
const lockUi = structural && !(kind === "install" && payload && payload.queue === true);
|
|
17876
18015
|
if (lockUi) setBusy(kind + ":" + cardId);
|
|
17877
|
-
//
|
|
17878
|
-
if (isInstall
|
|
17879
|
-
setNote(null);
|
|
18016
|
+
// 非安装类沿用旧口径:先清上一轮提示。安装类交给 dlInstallClick(它先写即时反馈)。
|
|
18017
|
+
if (!isInstall) setNote(null);
|
|
17880
18018
|
try {
|
|
17881
|
-
|
|
18019
|
+
let resp;
|
|
18020
|
+
if (isInstall) {
|
|
18021
|
+
// 4.23.14:与皮肤/开机动画**同一个**实现 —— 第一行同步反馈(按钮「正在提交…」+ 卡片
|
|
18022
|
+
// pressed + aria-busy),再进卡片状态机,最后才发请求;300ms 没进队列就出「提交中…
|
|
18023
|
+
// (正在准备)」。桌宠的清单接口 `/pets/list` 因此不再挡在点击与请求之间。
|
|
18024
|
+
const click = await dlInstallClick({
|
|
18025
|
+
el: ev && ev.currentTarget,
|
|
18026
|
+
btnText: weT("正在提交…"),
|
|
18027
|
+
installed: false,
|
|
18028
|
+
begin: () => { cards.begin(cardId); },
|
|
18029
|
+
onSubmitting: () => { setNote({ ok: true, text: weT("正在提交…") }); },
|
|
18030
|
+
onPreparing: (text) => { setNote({ ok: true, text }); },
|
|
18031
|
+
jobActive: () => dlJobActive(dlJobForCard(jobsRef.current, "pet", jobUrl)),
|
|
18032
|
+
submit: () => apiPostJson("/pets/install", payload || {}, { parse: "always" }),
|
|
18033
|
+
});
|
|
18034
|
+
resp = click.resp;
|
|
18035
|
+
} else {
|
|
18036
|
+
resp = await apiPostJson("/pets/" + kind, payload || {}, { parse: "always" });
|
|
18037
|
+
}
|
|
17882
18038
|
const r = (resp && resp.data) || null;
|
|
17883
18039
|
if (resp && resp.ok && r && r.ok) {
|
|
17884
18040
|
if (kind === "install") {
|
|
@@ -18103,7 +18259,7 @@ window.__ModuleLoader__.load({
|
|
|
18103
18259
|
const st = cards.stateOf({ id: s.id, job, done: false, labels: petDlLabels });
|
|
18104
18260
|
// running 沿用 4.23.3 的紧凑文案(`下载中… 42% · 多连接(8)`),MB/剩余时间在下面那行明细里。
|
|
18105
18261
|
const label = st.phase === "running" ? dlBusyLabel(job) : st.label;
|
|
18106
|
-
return React.createElement("div", { key: "site:" + s.id, style: PET_STYLE.card },
|
|
18262
|
+
return React.createElement("div", { key: "site:" + s.id, className: "we-dl-card", style: PET_STYLE.card },
|
|
18107
18263
|
s.cover
|
|
18108
18264
|
? React.createElement("img", {
|
|
18109
18265
|
src: s.cover, alt: "", loading: "lazy", decoding: "async",
|
|
@@ -18115,7 +18271,8 @@ window.__ModuleLoader__.load({
|
|
|
18115
18271
|
React.createElement("div", { style: PET_STYLE.meta }, petFmtBytes(s.bytes)),
|
|
18116
18272
|
React.createElement("div", { style: PET_STYLE.row },
|
|
18117
18273
|
// 只禁**这一张**卡片(提交中/排队/在下/解压);别的卡片在动不影响它。
|
|
18118
|
-
|
|
18274
|
+
// 4.23.14:事件与本条 url 一并交给 act ⇒ 同步反馈 + 300ms 占位判定。
|
|
18275
|
+
btn(label, (ev) => act("install", { id: s.id, queue: true }, s.title || s.id, ev, s.url), st.disabled)),
|
|
18119
18276
|
// 进度 / 原因明细:`12.3/16.6 MB · 约剩 41 秒`、`排队中:前面还有 2 个任务`、
|
|
18120
18277
|
// 或失败原因(红字)。失败时按钮上是「重试」,点它立刻重新提交。
|
|
18121
18278
|
st.detail
|
|
@@ -18847,6 +19004,11 @@ window.__ModuleLoader__.load({
|
|
|
18847
19004
|
// 4.23.4:**卡片级**状态机(四页签共用,见 src/local-first.js 的 `dlCardState`)——
|
|
18848
19005
|
// idle→submitting→queued→running→installing→done,失败带原因 +「重试」。
|
|
18849
19006
|
const cards = useDlCards(dl);
|
|
19007
|
+
// 4.23.14:300ms 占位要知道"队列里是不是已经有这张卡片的 queued/running"。
|
|
19008
|
+
// 直接用渲染闭包里的 `dl.jobs` 会读到**点击那一刻**的旧快照(定时器触发时不会重渲染),
|
|
19009
|
+
// 所以用一个 ref 跟住最新值(与 busyRef 同一手法)。
|
|
19010
|
+
const jobsRef = React.useRef([]);
|
|
19011
|
+
jobsRef.current = dl.jobs;
|
|
18850
19012
|
// 状态机里只有两个词是"本模块自己的口径":空闲时按什么、完成后叫什么。
|
|
18851
19013
|
// 其余(正在提交… / 排队中:前面还有 N 个 / 下载中… x% / 解压/落位中… / 重试 / 失败原因)
|
|
18852
19014
|
// 全部来自共用函数,四个页签逐字一致。
|
|
@@ -19000,7 +19162,7 @@ window.__ModuleLoader__.load({
|
|
|
19000
19162
|
// 依赖只放"清单"与"队列快照":两者变了才需要重新判断该不该补装。
|
|
19001
19163
|
}, [state, dl.jobs]);
|
|
19002
19164
|
|
|
19003
|
-
const act = async (kind, payload, label) => {
|
|
19165
|
+
const act = async (kind, payload, label, ev) => {
|
|
19004
19166
|
// 结构性操作才锁整块 UI;`activate` 是幂等的、而且要让人能连点换皮肤,所以不锁。
|
|
19005
19167
|
const structural = kind === "install" || kind === "remove";
|
|
19006
19168
|
const cardId = String((payload && payload.id) || "");
|
|
@@ -19013,18 +19175,9 @@ window.__ModuleLoader__.load({
|
|
|
19013
19175
|
// 界面什么都不发生 —— 这就是用户报的「鲸鱼娘·雨夜 点了没反应」的直接形态。
|
|
19014
19176
|
// 现在安装的可见性由**这张卡片自己**的 submitting/queued/running 承担(只禁它自己)。
|
|
19015
19177
|
if (busyKey && !isInstall) { setBusy(busyKey); busyRef.current = busyKey; }
|
|
19016
|
-
|
|
19017
|
-
setNote(null);
|
|
19178
|
+
// 非安装类操作沿用旧口径:先把上一轮的提示清掉。安装类**不清** —— 见下面 dlInstallClick。
|
|
19179
|
+
if (!isInstall) setNote(null);
|
|
19018
19180
|
try {
|
|
19019
|
-
// 4.23.6:**先问列表,再发请求** —— 已经装好就别再触发一次解压。
|
|
19020
|
-
// 这是"装了两遍"的客户端半边:202 轮询到 done 会再打一次安装,而宿主那边
|
|
19021
|
-
// `scheduleFinishInstall()` 也会打一次;两条路都不问现状的话就会把刚装好的目录删掉重写。
|
|
19022
|
-
if (isInstall && cardId && await skinInstalledNow(cardId)) {
|
|
19023
|
-
cards.markOk(cardId);
|
|
19024
|
-
setNote({ ok: true, text: weT("已装过:{name}", { name: label || "" }) });
|
|
19025
|
-
await load(true);
|
|
19026
|
-
return;
|
|
19027
|
-
}
|
|
19028
19181
|
if (kind === "activate") {
|
|
19029
19182
|
const wantId = (payload && payload.id) || null;
|
|
19030
19183
|
// ⚠️ 这里写入的必须是**皮肤中心自己认识的 id**(= skin.json 里的原始 id),
|
|
@@ -19084,7 +19237,41 @@ window.__ModuleLoader__.load({
|
|
|
19084
19237
|
return;
|
|
19085
19238
|
}
|
|
19086
19239
|
|
|
19087
|
-
|
|
19240
|
+
/**
|
|
19241
|
+
* 4.23.14:安装的**第一行**是同步视觉反馈(`dlInstallClick` 里先改 DOM 再发请求)。
|
|
19242
|
+
*
|
|
19243
|
+
* 旧顺序(`cards.begin` → `await skinInstalledNow`)在冷启动时那次 `/skins/list` 要
|
|
19244
|
+
* **555.7 ms**(热态 41.9–44.0 ms,实测 5 采样):这段时间用户只等 React 的一次提交,
|
|
19245
|
+
* 卡片明细还是空的 ⇒ 第一击像"没反应"。现在:
|
|
19246
|
+
* · 反馈与点击同一个 tick(pressed / aria-busy / 按钮「正在提交…」);
|
|
19247
|
+
* · 预检查**只在清单已 installed===true** 时做,且 1.5s 超时后照常发请求;
|
|
19248
|
+
* · 300ms 还没进入 queued/running ⇒ 提示行先出「提交中…(正在准备)」。
|
|
19249
|
+
*/
|
|
19250
|
+
let resp;
|
|
19251
|
+
if (isInstall) {
|
|
19252
|
+
const click = await dlInstallClick({
|
|
19253
|
+
el: ev && ev.currentTarget,
|
|
19254
|
+
btnText: weT("正在提交…"),
|
|
19255
|
+
installed: Boolean(payload && payload.installed === true),
|
|
19256
|
+
begin: () => { cards.begin(cardId); },
|
|
19257
|
+
onSubmitting: () => { setNote({ ok: true, text: weT("正在提交…") }); },
|
|
19258
|
+
onPreparing: (text) => { setNote({ ok: true, text }); },
|
|
19259
|
+
jobActive: () => dlJobActive(dlJobForCard(jobsRef.current, "skin", payload && payload.url)),
|
|
19260
|
+
precheck: () => skinInstalledNow(cardId),
|
|
19261
|
+
precheckMs: DL_PRECHECK_TIMEOUT_MS,
|
|
19262
|
+
submit: () => apiPostJson("/skins/install", payload || {}, { parse: "always" }),
|
|
19263
|
+
});
|
|
19264
|
+
// 清单已装且预检查命中:一次网络都不发(这是唯一允许"先查再发"的分支)。
|
|
19265
|
+
if (click.skipped) {
|
|
19266
|
+
cards.markOk(cardId);
|
|
19267
|
+
setNote({ ok: true, text: weT("已装过:{name}", { name: label || "" }) });
|
|
19268
|
+
await load(true);
|
|
19269
|
+
return;
|
|
19270
|
+
}
|
|
19271
|
+
resp = click.resp;
|
|
19272
|
+
} else {
|
|
19273
|
+
resp = await apiPostJson("/skins/" + kind, payload || {}, { parse: "always" });
|
|
19274
|
+
}
|
|
19088
19275
|
const r = (resp && resp.data) || null;
|
|
19089
19276
|
// 4.23.6:宿主说"同一套**正在装**"(`scheduleFinishInstall` 的自调用与客户端 202 轮询撞上了)。
|
|
19090
19277
|
// 这不是失败、也**不是完成**:保持当前卡片状态(后面的 90 秒上界兜底),只把清单刷新一遍 ——
|
|
@@ -19527,7 +19714,8 @@ window.__ModuleLoader__.load({
|
|
|
19527
19714
|
// 而皮肤中心只认 skin.json 里的原始 id ⇒ 写之前必须换成**本机那个 id**,
|
|
19528
19715
|
// 否则它的 activePostHandler 会回 404 skin-not-found(实测报错 skin-center-404)。
|
|
19529
19716
|
const localId = localIdOf(s);
|
|
19530
|
-
|
|
19717
|
+
// 4.23.14:`we-dl-card` 是同步反馈的**卡片级**锚点(pressed 态挂它,见 styles-panel.js)。
|
|
19718
|
+
return React.createElement("div", { key: s.id, className: "we-dl-card", style: SKIN_STYLE.card },
|
|
19531
19719
|
s.thumbUrl
|
|
19532
19720
|
? React.createElement("div", {
|
|
19533
19721
|
style: { ...SKIN_STYLE.thumb, backgroundImage: "url(" + JSON.stringify(s.thumbUrl) + ")" },
|
|
@@ -19563,7 +19751,9 @@ window.__ModuleLoader__.load({
|
|
|
19563
19751
|
disabled: st.disabled,
|
|
19564
19752
|
title: st.phase === "failed" ? st.reason
|
|
19565
19753
|
: (skinCenter === "absent" ? weT("先装皮肤中心,否则皮肤装好也没法启用") : undefined),
|
|
19566
|
-
|
|
19754
|
+
// 4.23.14:把被点的元素交给 act ⇒ 第一行就能同步做视觉反馈。`installed` 随行带给
|
|
19755
|
+
// 预检查门:只有清单说已装时才允许先查(否则直接发安装请求)。
|
|
19756
|
+
onClick: (ev) => act("install", { id: s.id, url: s.url, installed: Boolean(s.installed) }, s.title, ev),
|
|
19567
19757
|
}, label),
|
|
19568
19758
|
),
|
|
19569
19759
|
// 进度 / 原因明细:`12.3/16.6 MB · 约剩 41 秒`、`排队中:前面还有 2 个任务`、
|
|
@@ -20185,6 +20375,13 @@ window.__ModuleLoader__.load({
|
|
|
20185
20375
|
title: weT("已在本地缓存(原画或 1080p 任一档已落地),点它不必等网络"),
|
|
20186
20376
|
}, weT("已缓存"))
|
|
20187
20377
|
: null,
|
|
20378
|
+
// 4.23.15:**已按解码上限选 1080p**(与库视图同一句话、同一个判据源 `variantReason`)。
|
|
20379
|
+
w.variantReason === "decode-limit"
|
|
20380
|
+
? React.createElement("span", {
|
|
20381
|
+
className: "we-qp__item-cached",
|
|
20382
|
+
title: weT("已按解码上限选 1080p:原画 {w}×{h} 超出本机解码能力(播放器解不出来),改播 1080p 变体", { w: w.width || "?", h: w.height || "?" }),
|
|
20383
|
+
}, weT("解码上限 · 1080p"))
|
|
20384
|
+
: null,
|
|
20188
20385
|
w.id === sel.id
|
|
20189
20386
|
? React.createElement("span", { className: "we-qp__item-badge" }, weT("当前"))
|
|
20190
20387
|
: React.createElement("span", { className: "we-qp__item-type" }, CARD_TYPE_LABELS[w.type] || weT("壁纸")),
|
|
@@ -22512,10 +22709,16 @@ window.__ModuleLoader__.load({
|
|
|
22512
22709
|
// ② 点了、请求还没回来、也还没有 job 可看 ⇒ 立刻置灰 +「正在提交…」。
|
|
22513
22710
|
// 这一格是"点了没反应"的直接解药:它出现在点击的同一帧。
|
|
22514
22711
|
if (o.sub && String(o.sub.id || "") === String(o.id || "")) {
|
|
22515
|
-
const
|
|
22516
|
-
|
|
22517
|
-
|
|
22518
|
-
|
|
22712
|
+
const elapsed = Math.max(0, now - (Number(o.sub.at) || now));
|
|
22713
|
+
const waited = Math.round(elapsed / 1000);
|
|
22714
|
+
if (elapsed >= timeout) return fail('submit-timeout');
|
|
22715
|
+
// 4.23.14:首帧反馈之后 **300ms** 还没有 queued/running ⇒ 出「提交中…(正在准备)」占位。
|
|
22716
|
+
// 为什么必须有:预检查/请求在冷启动或弱网下可以是几百毫秒到几秒,而旧实现这一格只有空
|
|
22717
|
+
// 明细行(`已等待 N 秒` 要等到 3 秒才出现)⇒ 用户看到的就是"点了没反应"。
|
|
22718
|
+
const detail = waited >= 3
|
|
22719
|
+
? weT("已等待 {s} 秒", { s: waited })
|
|
22720
|
+
: (elapsed >= DL_FIRST_CLICK_PLACEHOLDER_MS ? weT("提交中…(正在准备)") : "");
|
|
22721
|
+
return make(DL_PHASES.SUBMITTING, weT("正在提交…"), detail, true, false, "");
|
|
22519
22722
|
}
|
|
22520
22723
|
// ②b 本卡片有一次**明确的失败**(提交失败 / 自动补装失败)⇒ 立刻给原因 +「重试」。
|
|
22521
22724
|
//
|
|
@@ -22598,6 +22801,510 @@ window.__ModuleLoader__.load({
|
|
|
22598
22801
|
});
|
|
22599
22802
|
}
|
|
22600
22803
|
|
|
22804
|
+
/* ── 「第一下就必须有反应」(4.23.14)────────────────────────────────────────
|
|
22805
|
+
*
|
|
22806
|
+
* 真实故障(用户实测):皮肤卡片的「安装」**第一下点击没有任何反馈**,第二下才有反应。
|
|
22807
|
+
*
|
|
22808
|
+
* 定因(三条,都能测):
|
|
22809
|
+
* ① 旧顺序是 `cards.begin(id)` 后**立刻** `await skinInstalledNow(id)` —— 一次
|
|
22810
|
+
* `/folia/skins/list` 往返。本机实测:冷启动 **555.7 ms**、热态 **41.9–44.0 ms**
|
|
22811
|
+
* (5 次采样,见交付报告)。可这期间用户能看到的**唯一**变化是 React 的一次提交。
|
|
22812
|
+
* ② 那一次提交不是"同一 tick"的 DOM 变化:`begin()` 只是排了 `setSub` / `setNonce`,
|
|
22813
|
+
* 要等 React 在事件回调让出后重渲染、浏览器再画一帧。请求再慢一点(冷启动/弱网),
|
|
22814
|
+
* 用户的第一印象就是"我点了,但屏幕没动"。
|
|
22815
|
+
* ③ 300ms 后仍没有 queued/running 时,卡片明细行本来就是空的(`已等待 N 秒` 要到 3 秒
|
|
22816
|
+
* 才出现)⇒ 慢请求 = 完全静默。
|
|
22817
|
+
*
|
|
22818
|
+
* 三条修法(四类入口共用,见下面三个函数 + `dlInstallClick`):
|
|
22819
|
+
* · `dlFirstClickFeedback()`:点击的**第一行**就改 DOM(卡片 pressed / `aria-busy` /
|
|
22820
|
+
* 按钮文案「正在提交…」),不 await、不发网络、不依赖 React 提交;
|
|
22821
|
+
* · `dlInstallPrecheckPlan()`:预检查**只在清单说已 installed===true** 时才做(其余情况
|
|
22822
|
+
* 直接发安装请求);真做时也走 `dlPrecheckWithTimeout()`,**1.5s 超时后照常发请求**;
|
|
22823
|
+
* · `DL_FIRST_CLICK_PLACEHOLDER_MS`(300ms)后仍未进入队列 ⇒ 出「提交中…(正在准备)」。
|
|
22824
|
+
*/
|
|
22825
|
+
const DL_PRECHECK_TIMEOUT_MS = 1500;
|
|
22826
|
+
const DL_FIRST_CLICK_PLACEHOLDER_MS = 300;
|
|
22827
|
+
|
|
22828
|
+
/**
|
|
22829
|
+
* 点击瞬间的**纯视觉**反馈:卡片 pressed + `aria-busy` + 按钮文案(可选)。
|
|
22830
|
+
*
|
|
22831
|
+
* 只碰 DOM:没有 await、没有网络、没有 React 提交 —— 所以第一处视觉变化与点击同一个 tick。
|
|
22832
|
+
* 返回 `restore()`(幂等):撤掉本次加上的 class / aria-busy。**不撤文案与 disabled**:
|
|
22833
|
+
* 那两项随后由 React 的重渲染接管(若在这里恢复,会把 React 刚写上的新文案/新禁用态盖回去)。
|
|
22834
|
+
*
|
|
22835
|
+
* @param {any} el 被点的元素(事件里的 `currentTarget` 即可;也可以是卡片本身)
|
|
22836
|
+
* @param {string} [text] 按钮要立即变成的文案(不传就只做 pressed / aria-busy)
|
|
22837
|
+
* @returns {null | (() => void)}
|
|
22838
|
+
*/
|
|
22839
|
+
function dlFirstClickFeedback(el, text) {
|
|
22840
|
+
const node = (el && typeof el === "object") ? el : null;
|
|
22841
|
+
if (!node) return null;
|
|
22842
|
+
const saved = { node, card: null, cardCls: false, aria: null, hasAria: false, btn: null, btnCls: false, btnTextNode: null, btnText: null, btnDisabled: false };
|
|
22843
|
+
try {
|
|
22844
|
+
// 卡片级 pressed:从按钮往上找**这张卡**(皮肤/开机动画/桌宠卡带 we-dl-card;
|
|
22845
|
+
// 壁纸库/快捷面板是 we-picker__card / we-qp__item / we-qp__card)。
|
|
22846
|
+
let card = null;
|
|
22847
|
+
try {
|
|
22848
|
+
if (typeof node.closest === "function") card = node.closest(".we-dl-card, .we-picker__card, .we-qp__item, .we-qp__card");
|
|
22849
|
+
} catch { card = null; }
|
|
22850
|
+
if (!card && node.classList && typeof node.classList.contains === "function") {
|
|
22851
|
+
for (const cls of ["we-dl-card", "we-picker__card", "we-qp__item", "we-qp__card"]) {
|
|
22852
|
+
if (node.classList.contains(cls)) { card = node; break; }
|
|
22853
|
+
}
|
|
22854
|
+
}
|
|
22855
|
+
const target = card || node;
|
|
22856
|
+
if (target.classList && typeof target.classList.add === "function") {
|
|
22857
|
+
target.classList.add("we-first-click");
|
|
22858
|
+
saved.card = target;
|
|
22859
|
+
saved.cardCls = true;
|
|
22860
|
+
}
|
|
22861
|
+
if (typeof node.setAttribute === "function") {
|
|
22862
|
+
saved.hasAria = true;
|
|
22863
|
+
saved.aria = typeof node.getAttribute === "function" ? node.getAttribute("aria-busy") : null;
|
|
22864
|
+
node.setAttribute("aria-busy", "true");
|
|
22865
|
+
}
|
|
22866
|
+
// 按钮:如果被点的就是按钮,直接用它;否则在卡片里找第一颗按钮。
|
|
22867
|
+
let btn = null;
|
|
22868
|
+
try {
|
|
22869
|
+
if (String(node.tagName || "").toUpperCase() === "BUTTON") btn = node;
|
|
22870
|
+
else if (typeof node.querySelector === "function") btn = node.querySelector("button");
|
|
22871
|
+
} catch { btn = null; }
|
|
22872
|
+
if (btn) {
|
|
22873
|
+
saved.btn = btn;
|
|
22874
|
+
saved.btnDisabled = Boolean(btn.disabled);
|
|
22875
|
+
if (typeof text === "string" && text) {
|
|
22876
|
+
const first = btn.firstChild;
|
|
22877
|
+
// ⚠️ 必须改**React 持有的那个文本节点**(firstChild.nodeValue),不能用 textContent:
|
|
22878
|
+
// 后者会把整颗文本节点换掉,React 之后更新的是旧节点 ⇒ 文案会永远卡在「正在提交…」。
|
|
22879
|
+
if (first && first.nodeType === 3 && typeof first.nodeValue === "string") {
|
|
22880
|
+
saved.btnTextNode = first;
|
|
22881
|
+
saved.btnText = first.nodeValue;
|
|
22882
|
+
first.nodeValue = text;
|
|
22883
|
+
} else if (typeof btn.textContent === "string") {
|
|
22884
|
+
btn.textContent = text;
|
|
22885
|
+
}
|
|
22886
|
+
}
|
|
22887
|
+
if (btn.classList && typeof btn.classList.add === "function") {
|
|
22888
|
+
btn.classList.add("we-first-click-btn");
|
|
22889
|
+
saved.btnCls = true;
|
|
22890
|
+
}
|
|
22891
|
+
btn.disabled = true;
|
|
22892
|
+
}
|
|
22893
|
+
} catch { return null; }
|
|
22894
|
+
let restored = false;
|
|
22895
|
+
return function restore() {
|
|
22896
|
+
if (restored) return;
|
|
22897
|
+
restored = true;
|
|
22898
|
+
try { if (saved.card && saved.cardCls && saved.card.classList && saved.card.classList.remove) saved.card.classList.remove("we-first-click"); } catch { /* ignore */ }
|
|
22899
|
+
try {
|
|
22900
|
+
if (saved.hasAria) {
|
|
22901
|
+
if (saved.aria == null) { if (typeof saved.node.removeAttribute === "function") saved.node.removeAttribute("aria-busy"); }
|
|
22902
|
+
else if (typeof saved.node.setAttribute === "function") saved.node.setAttribute("aria-busy", saved.aria);
|
|
22903
|
+
}
|
|
22904
|
+
} catch { /* ignore */ }
|
|
22905
|
+
try { if (saved.btn && saved.btnCls && saved.btn.classList && saved.btn.classList.remove) saved.btn.classList.remove("we-first-click-btn"); } catch { /* ignore */ }
|
|
22906
|
+
// 不恢复 `btnTextNode.nodeValue` / `btn.disabled`:React 随后会用真实状态覆盖它们,
|
|
22907
|
+
// 在这里抢着写回去反而会盖掉「已安装 / 重试 / 已禁用」这些新事实。
|
|
22908
|
+
};
|
|
22909
|
+
}
|
|
22910
|
+
|
|
22911
|
+
/**
|
|
22912
|
+
* 预检查**要不要做**(纯函数,负对照直接喂)。
|
|
22913
|
+
*
|
|
22914
|
+
* 口径(4.23.14):只有清单已经说这套 **installed === true** 时才做 —— 那种情况下"再发一次
|
|
22915
|
+
* 安装请求"确实可能把刚装好的目录删了重写。清单说没装(绝大多数首次点击)时**不做**:
|
|
22916
|
+
* 那一次 `/skins/list` 往返正是第一击"没反应"的来源,而宿主 `/skins/install` 自己对
|
|
22917
|
+
* `exists` 是幂等的(目录已有 skin.json 直接回 `exists:true`),没有必须前置查的理由。
|
|
22918
|
+
*
|
|
22919
|
+
* @param {boolean} installed
|
|
22920
|
+
* @returns {{ precheck: boolean }}
|
|
22921
|
+
*/
|
|
22922
|
+
function dlInstallPrecheckPlan(installed) {
|
|
22923
|
+
return { precheck: installed === true };
|
|
22924
|
+
}
|
|
22925
|
+
|
|
22926
|
+
/**
|
|
22927
|
+
* 带**硬超时**的预检查。返回 `'hit' | 'miss' | 'timeout'`(timeout 之后调用方**照常发请求**)。
|
|
22928
|
+
* `timers` 只为测试注入(默认全局 setTimeout/clearTimeout);生产路径不传。
|
|
22929
|
+
*/
|
|
22930
|
+
function dlPrecheckWithTimeout(fn, timeoutMs, timers) {
|
|
22931
|
+
const ms = Math.max(0, Number(timeoutMs) || DL_PRECHECK_TIMEOUT_MS);
|
|
22932
|
+
if (typeof fn !== "function") return Promise.resolve("miss");
|
|
22933
|
+
const t = timers || {};
|
|
22934
|
+
const setT = typeof t.setTimeout === "function" ? t.setTimeout : setTimeout;
|
|
22935
|
+
const clearT = typeof t.clearTimeout === "function" ? t.clearTimeout : clearTimeout;
|
|
22936
|
+
return new Promise((resolve) => {
|
|
22937
|
+
let done = false;
|
|
22938
|
+
let timer = null;
|
|
22939
|
+
const finish = (verdict) => {
|
|
22940
|
+
if (done) return;
|
|
22941
|
+
done = true;
|
|
22942
|
+
if (timer !== null) { try { clearT(timer); } catch { /* ignore */ } }
|
|
22943
|
+
resolve(verdict);
|
|
22944
|
+
};
|
|
22945
|
+
try { timer = setT(() => finish("timeout"), ms); } catch { timer = null; }
|
|
22946
|
+
Promise.resolve()
|
|
22947
|
+
.then(() => fn())
|
|
22948
|
+
.then((v) => finish(v === true ? "hit" : "miss"))
|
|
22949
|
+
.catch(() => finish("miss"));
|
|
22950
|
+
});
|
|
22951
|
+
}
|
|
22952
|
+
|
|
22953
|
+
/**
|
|
22954
|
+
* 「提交中…(正在准备)」占位的**唯一判断**:首帧反馈后 300ms,仍没有 queued/running ⇒ 出这句。
|
|
22955
|
+
* @param {{waitedMs?:number, jobActive?:boolean}} [o]
|
|
22956
|
+
* @returns {string} 占位文案(空串 = 不显示)
|
|
22957
|
+
*/
|
|
22958
|
+
function dlPreparingHint(o) {
|
|
22959
|
+
const x = o || {};
|
|
22960
|
+
if (x.jobActive === true) return "";
|
|
22961
|
+
const waited = Math.max(0, Number(x.waitedMs) || 0);
|
|
22962
|
+
if (waited < DL_FIRST_CLICK_PLACEHOLDER_MS) return "";
|
|
22963
|
+
return weT("提交中…(正在准备)");
|
|
22964
|
+
}
|
|
22965
|
+
|
|
22966
|
+
/**
|
|
22967
|
+
* **安装/下载按钮的统一点击流程**(皮肤 / 开机动画 / 桌宠共用一个实现)。
|
|
22968
|
+
*
|
|
22969
|
+
* 顺序是判据,不是风格:**先同步视觉反馈** → 再交给卡片状态机(submitting)→ 再预检查
|
|
22970
|
+
* (只在 `installed === true` 时)→ 最后才发请求。把"先 await 预检查再反馈"写回来,第一击
|
|
22971
|
+
* 就又会静默(`test/verify-first-click-feedback.mjs` 的负对照钉着这一点)。
|
|
22972
|
+
*
|
|
22973
|
+
* @param {object} o
|
|
22974
|
+
* @param {any} [o.el] 被点的元素(`ev.currentTarget`)
|
|
22975
|
+
* @param {string} [o.btnText] 按钮立即变成的文案(缺省「正在提交…」)
|
|
22976
|
+
* @param {boolean} [o.installed] 清单里是否已装(决定要不要预检查)
|
|
22977
|
+
* @param {() => void} [o.begin] 卡片状态机入口(`cards.begin(id)`)
|
|
22978
|
+
* @param {() => void} [o.onSubmitting] 立即写一句提示(可选)
|
|
22979
|
+
* @param {(text:string) => void} [o.onPreparing] 300ms 占位(可选)
|
|
22980
|
+
* @param {() => boolean} [o.jobActive] 300ms 时队列里已有本卡片的 queued/running 吗
|
|
22981
|
+
* @param {() => Promise<boolean>} [o.precheck] 预检查(只在 installed===true 时调用)
|
|
22982
|
+
* @param {number} [o.precheckMs] 预检查超时(默认 1.5s)
|
|
22983
|
+
* @param {() => Promise<any>} [o.submit] 真正的安装/下载请求
|
|
22984
|
+
* @param {object} [o.timers] 测试注入的定时器
|
|
22985
|
+
* @returns {Promise<{precheck:string, skipped:boolean, resp:any, placeholder:string, startedAt:number}>}
|
|
22986
|
+
*/
|
|
22987
|
+
async function dlInstallClick(o) {
|
|
22988
|
+
const x = o || {};
|
|
22989
|
+
const timers = x.timers || {};
|
|
22990
|
+
const setT = typeof timers.setTimeout === "function" ? timers.setTimeout : setTimeout;
|
|
22991
|
+
const clearT = typeof timers.clearTimeout === "function" ? timers.clearTimeout : clearTimeout;
|
|
22992
|
+
const startedAt = Date.now();
|
|
22993
|
+
// ① **同步**视觉反馈:第一行,纯 DOM,不 await、不网络。
|
|
22994
|
+
const restore = dlFirstClickFeedback(x.el, typeof x.btnText === "string" ? x.btnText : weT("正在提交…"));
|
|
22995
|
+
// ② 卡片状态机:submitting(React 的提交在下一次让出时,晚于上面那一行)。
|
|
22996
|
+
if (typeof x.begin === "function") { try { x.begin(); } catch { /* 状态层失败不挡住提交 */ } }
|
|
22997
|
+
if (typeof x.onSubmitting === "function") { try { x.onSubmitting(); } catch { /* 提示失败不影响提交 */ } }
|
|
22998
|
+
let settled = false;
|
|
22999
|
+
let placeholderText = "";
|
|
23000
|
+
let timer = null;
|
|
23001
|
+
try {
|
|
23002
|
+
// ③ 300ms 还没进入 queued/running ⇒ 出占位(慢请求不许静默)。
|
|
23003
|
+
try {
|
|
23004
|
+
timer = setT(() => {
|
|
23005
|
+
if (settled) return;
|
|
23006
|
+
let jobActive;
|
|
23007
|
+
try { jobActive = typeof x.jobActive === "function" ? x.jobActive() === true : false; } catch { jobActive = false; }
|
|
23008
|
+
// 这一枪本来就是 300ms 那一拍 ⇒ 用「至少 300ms」参与判断:测试换可控定时器时时间不会真的走,
|
|
23009
|
+
// 而生产路径上 Date.now()-startedAt 也必然 ≥ 300(定时器不会提前触发)。
|
|
23010
|
+
const hint = dlPreparingHint({ waitedMs: Math.max(Date.now() - startedAt, DL_FIRST_CLICK_PLACEHOLDER_MS), jobActive });
|
|
23011
|
+
if (!hint) return;
|
|
23012
|
+
placeholderText = hint;
|
|
23013
|
+
try { if (typeof x.onPreparing === "function") x.onPreparing(hint); } catch { /* ignore */ }
|
|
23014
|
+
}, DL_FIRST_CLICK_PLACEHOLDER_MS);
|
|
23015
|
+
} catch { timer = null; }
|
|
23016
|
+
// ④ 预检查(只有清单说已装才做;1.5s 超时后照常发请求)。
|
|
23017
|
+
const plan = dlInstallPrecheckPlan(x.installed);
|
|
23018
|
+
let precheck = "skipped";
|
|
23019
|
+
if (plan.precheck) {
|
|
23020
|
+
precheck = await dlPrecheckWithTimeout(x.precheck, x.precheckMs, timers);
|
|
23021
|
+
if (precheck === "hit") {
|
|
23022
|
+
return { precheck, skipped: true, resp: null, placeholder: placeholderText, startedAt };
|
|
23023
|
+
}
|
|
23024
|
+
}
|
|
23025
|
+
// ⑤ 真正的请求。
|
|
23026
|
+
const resp = typeof x.submit === "function" ? await x.submit() : null;
|
|
23027
|
+
return { precheck, skipped: false, resp, placeholder: placeholderText, startedAt };
|
|
23028
|
+
} finally {
|
|
23029
|
+
settled = true;
|
|
23030
|
+
if (timer !== null) { try { clearT(timer); } catch { /* ignore */ } }
|
|
23031
|
+
try { if (typeof restore === "function") restore(); } catch { /* ignore */ }
|
|
23032
|
+
}
|
|
23033
|
+
}
|
|
23034
|
+
|
|
23035
|
+
/* ── 播放失败自愈(4.23.15):本地副本坏了吗?还是本机解不了? ──────────────────
|
|
23036
|
+
*
|
|
23037
|
+
* 真实故障(另一台机器):壁纸显示「视频解码失败(文件可能已损坏)」/「浏览器无法解码这段
|
|
23038
|
+
* 视频」,而面板同时说"缓存命中 4/5"。播放路径直接读本地文件、**没有任何自检** ——
|
|
23039
|
+
* 4.23.6 之前 ranged 静默损坏遗留的坏成品会永久留在 library 里,每次点都是那句错误。
|
|
23040
|
+
*
|
|
23041
|
+
* 这一族只做客户端这一半:**判"要不要惊动宿主"** + **把宿主结论翻成人话**。
|
|
23042
|
+
* 真正的取证(sha256 / 结构 / 重下 / 换档 / 转码)在宿主 `lib/media-selfheal.js`,
|
|
23043
|
+
* 因为浏览器没有磁盘、也没有站点清单。
|
|
23044
|
+
*
|
|
23045
|
+
* 为什么客户端能判断"要不要惊动宿主":只有**本地副本**才值得验。远端字节我们既不能证明
|
|
23046
|
+
* 坏、也不能替站点重下(那只会让用户白等一次同样的解码失败)。
|
|
23047
|
+
*/
|
|
23048
|
+
|
|
23049
|
+
/** 每条壁纸最多自愈几次。超过就只提示 —— 防"每次 error 都重下"的死循环。 */
|
|
23050
|
+
const LF_HEAL_MAX_TRIES = 2;
|
|
23051
|
+
/** 轮询救援产物/重下的间隔与上限(转码是几十秒级的,给 3 分钟)。 */
|
|
23052
|
+
const LF_HEAL_POLL_MS = 1500;
|
|
23053
|
+
const LF_HEAL_POLL_MAX_MS = 3 * 60 * 1000;
|
|
23054
|
+
|
|
23055
|
+
/** 每个壁纸 id 已经自愈过几次(会话内;刷新页面重新计数是合理的)。 */
|
|
23056
|
+
const LF_HEAL_TRIES = new Map();
|
|
23057
|
+
|
|
23058
|
+
/** 自愈要用到的两个宿主动作:提示位(面板那一行)与"重挂播放"(把新地址装回 <video>)。 */
|
|
23059
|
+
const LF_HEAL_HOOKS = { note: null, mount: null };
|
|
23060
|
+
|
|
23061
|
+
/**
|
|
23062
|
+
* client.js 注入:`note(text, ok)` 写面板提示;`mount(url)` 把播放器重挂到新地址(返回是否成功)。
|
|
23063
|
+
*
|
|
23064
|
+
* 为什么是注入而不是直接调:`local-first.js` 是**内联进同一个工厂作用域**的片段,
|
|
23065
|
+
* 但"提示位"与"哪个 <video> 在屏上"都只有 `src/client.js` 的正文知道;
|
|
23066
|
+
* 硬编码调用会把这条依赖变成隐式的循环(client.js ← local-first.js ← client.js)。
|
|
23067
|
+
*/
|
|
23068
|
+
function setSelfHealHooks(note, mount) {
|
|
23069
|
+
LF_HEAL_HOOKS.note = typeof note === "function" ? note : null;
|
|
23070
|
+
LF_HEAL_HOOKS.mount = typeof mount === "function" ? mount : null;
|
|
23071
|
+
}
|
|
23072
|
+
|
|
23073
|
+
function lfHealSay(text, ok) {
|
|
23074
|
+
try { if (LF_HEAL_HOOKS.note) LF_HEAL_HOOKS.note(text, ok !== false); } catch { /* 提示失败不影响自愈 */ }
|
|
23075
|
+
}
|
|
23076
|
+
|
|
23077
|
+
/**
|
|
23078
|
+
* 这个播放地址是不是**本地副本**(`/folia/local-media/<id>` 或 library 目录直出)。
|
|
23079
|
+
*
|
|
23080
|
+
* 只认本地:远端 URL 的自愈没有意义(见上面那段"为什么客户端能判断")。
|
|
23081
|
+
*/
|
|
23082
|
+
function lfIsLocalMediaUrl(url) {
|
|
23083
|
+
const s = String(url || "");
|
|
23084
|
+
if (!s) return false;
|
|
23085
|
+
if (/\/folia\/local-media\//.test(s)) return true;
|
|
23086
|
+
// 直出形态(旧宿主 / 排障时手工拼的地址):`.../library/<kind>/<hash>.mp4`
|
|
23087
|
+
return /\/library\/[^/]+\/[0-9a-f]{16,}\./i.test(s);
|
|
23088
|
+
}
|
|
23089
|
+
|
|
23090
|
+
/**
|
|
23091
|
+
* **要不要惊动宿主**(纯函数;判据见 `test/verify-media-selfheal.mjs`)。
|
|
23092
|
+
*
|
|
23093
|
+
* 只处理两件事都成立的那一格:① 播的是**本地副本**;② 错误码是**解码/源不支持**
|
|
23094
|
+
* (3 = DECODE,4 = SRC_NOT_SUPPORTED)。网络类(2 NETWORK)与中断类(1 ABORTED)
|
|
23095
|
+
* **不走自愈** —— 它们是"这一下没传完",重下只会把一份好文件换掉。
|
|
23096
|
+
*
|
|
23097
|
+
* 返回 `'heal'`(去验)/ `'skip'`(不动)。
|
|
23098
|
+
* @param {{ isVideo?: boolean, url?: string, code?: number, tries?: number, maxTries?: number }} [inp]
|
|
23099
|
+
* @returns {'heal' | 'skip'}
|
|
23100
|
+
*/
|
|
23101
|
+
function dlHealPlan(inp) {
|
|
23102
|
+
const o = inp || {};
|
|
23103
|
+
if (o.isVideo === false) return "skip";
|
|
23104
|
+
if (!lfIsLocalMediaUrl(o.url)) return "skip";
|
|
23105
|
+
const code = Number(o.code) || 0;
|
|
23106
|
+
if (code !== 3 && code !== 4) return "skip";
|
|
23107
|
+
const max = Number(o.maxTries) > 0 ? Number(o.maxTries) : LF_HEAL_MAX_TRIES;
|
|
23108
|
+
if ((Number(o.tries) || 0) >= max) return "skip";
|
|
23109
|
+
return "heal";
|
|
23110
|
+
}
|
|
23111
|
+
|
|
23112
|
+
/**
|
|
23113
|
+
* 宿主的处置结论 → 一句**具体**的人话(纯函数)。
|
|
23114
|
+
*
|
|
23115
|
+
* 为什么每个结论一句不同的话:用户看到的三种情况看起来一模一样(都停在首帧/报错),
|
|
23116
|
+
* 但该做的事完全不同 —— 「已重新下载」是等它,「已切换 1080p」是等它,「本机不支持该编码」
|
|
23117
|
+
* 是**换一张**。用同一句"视频无法播放"会让用户反复点同一张。
|
|
23118
|
+
*
|
|
23119
|
+
* @param {string} verdict
|
|
23120
|
+
* @returns {string}
|
|
23121
|
+
*/
|
|
23122
|
+
function dlHealNote(verdict) {
|
|
23123
|
+
const v = String(verdict || "");
|
|
23124
|
+
if (v === "corrupt") return weT("文件已损坏,已重新下载");
|
|
23125
|
+
if (v === "variant") return weT("已自动切换 1080p(原画超出本机解码上限)");
|
|
23126
|
+
if (v === "transcoded") return weT("原画超出本机解码上限,已生成本机可播放的 1080p 副本");
|
|
23127
|
+
if (v === "transcoding") return weT("原画超出本机解码上限,正在生成可播放副本…");
|
|
23128
|
+
if (v === "undecodable") return weT("本机不支持该编码(可换一张跳过此壁纸)");
|
|
23129
|
+
if (v === "undecodable-no-variant") return weT("该壁纸分辨率/编码超出本机解码能力(可换一张跳过此壁纸)");
|
|
23130
|
+
return "";
|
|
23131
|
+
}
|
|
23132
|
+
|
|
23133
|
+
/** 这个结论是不是"还在路上"(要轮询),还是已经到达终态。 */
|
|
23134
|
+
function dlHealPending(verdict) {
|
|
23135
|
+
const v = String(verdict || "");
|
|
23136
|
+
return v === "corrupt" || v === "variant" || v === "transcoding";
|
|
23137
|
+
}
|
|
23138
|
+
|
|
23139
|
+
/**
|
|
23140
|
+
* 转码进度 → 一句**带数字**的话(用户明确要求:「转码期间必须有可见进度,不许静默」)。
|
|
23141
|
+
*
|
|
23142
|
+
* 为什么必须有 percent:整片重编码是几十秒到几分钟级,而此刻屏上是黑的 ——
|
|
23143
|
+
* **没有数字的等待与卡死没有区别**。eta 拿不到就只说百分比(不编数字)。
|
|
23144
|
+
* 也绝不报 100%:最后那一下是 rename + 校验,说满了却还没出画会让人更不信。
|
|
23145
|
+
*
|
|
23146
|
+
* @param {{ percent?: number, eta?: number | null } | null} [progress]
|
|
23147
|
+
* @returns {string}
|
|
23148
|
+
*/
|
|
23149
|
+
function dlHealProgressNote(progress) {
|
|
23150
|
+
const pct = Math.max(0, Math.min(99, Math.round(Number(progress && progress.percent) || 0)));
|
|
23151
|
+
const eta = Number(progress && progress.eta);
|
|
23152
|
+
if (eta > 0 && isFinite(eta)) {
|
|
23153
|
+
return weT("正在生成本机可播放副本 {percent}%(约剩 {eta} 秒)", { percent: pct, eta: Math.max(1, Math.round(eta)) });
|
|
23154
|
+
}
|
|
23155
|
+
return weT("正在生成本机可播放副本 {percent}%", { percent: pct });
|
|
23156
|
+
}
|
|
23157
|
+
|
|
23158
|
+
/**
|
|
23159
|
+
* **"这张壁纸最终怎么上屏"的最后一级**(纯函数):转码也救不回来时,静态帧兜底。
|
|
23160
|
+
*
|
|
23161
|
+
* 需求原文(用户最终目标):**任何一张壁纸,只要站点上有可用文件,最终都必须能上屏** ——
|
|
23162
|
+
* 「只有连静态帧都没有,才允许显示无法显示」。所以这里是两级,不是一级:
|
|
23163
|
+
* `static-frame` —— 有缩略图/首帧 ⇒ 拿它当静态壁纸(画面是那张图,能看见)
|
|
23164
|
+
* `cannot-display` —— 连图都没有 ⇒ 这时才允许说"无法显示"
|
|
23165
|
+
* `''` —— 这个结论不归它管(corrupt/variant/transcoded 都还有得救)
|
|
23166
|
+
*
|
|
23167
|
+
* @param {{ verdict?: string, hasPreview?: boolean }} [inp]
|
|
23168
|
+
* @returns {'' | 'static-frame' | 'cannot-display'}
|
|
23169
|
+
*/
|
|
23170
|
+
function dlHealFallbackPlan(inp) {
|
|
23171
|
+
const o = inp || {};
|
|
23172
|
+
const v = String(o.verdict || "");
|
|
23173
|
+
if (v !== "undecodable" && v !== "undecodable-no-variant") return "";
|
|
23174
|
+
return o.hasPreview === true ? "static-frame" : "cannot-display";
|
|
23175
|
+
}
|
|
23176
|
+
|
|
23177
|
+
/**
|
|
23178
|
+
* 等一条 job 落地(**只回答"盘上有这份成品了吗"**)。
|
|
23179
|
+
* 复用 `dlAwaitJob` 的轮询口径:done ⇒ true;failed/cancelled/消失 ⇒ false。
|
|
23180
|
+
* @param {string} jobId
|
|
23181
|
+
* @param {(n: number) => void} [onTick] 每次轮询回调(界面显示进度用)
|
|
23182
|
+
* @returns {Promise<boolean>}
|
|
23183
|
+
*/
|
|
23184
|
+
async function lfAwaitHealJobP(jobId, onTick) {
|
|
23185
|
+
const id = String(jobId || "");
|
|
23186
|
+
if (!id) return false;
|
|
23187
|
+
const startedAt = Date.now();
|
|
23188
|
+
for (;;) {
|
|
23189
|
+
if (Date.now() - startedAt > LF_HEAL_POLL_MAX_MS) return false;
|
|
23190
|
+
let job = null;
|
|
23191
|
+
try {
|
|
23192
|
+
const resp = await apiJson("/downloads/list");
|
|
23193
|
+
const jobs = (resp && resp.data && Array.isArray(resp.data.jobs)) ? resp.data.jobs
|
|
23194
|
+
: (Array.isArray(resp && resp.jobs) ? resp.jobs : []);
|
|
23195
|
+
job = jobs.find((j) => j && j.id === id) || null;
|
|
23196
|
+
} catch { /* 网络抖动:下一拍再试 */ }
|
|
23197
|
+
if (job) {
|
|
23198
|
+
if (job.status === "done") return true;
|
|
23199
|
+
if (job.status === "failed" || job.status === "cancelled") return false;
|
|
23200
|
+
if (typeof onTick === "function") { try { onTick(Number(job.percent) || 0); } catch { /* ignore */ } }
|
|
23201
|
+
}
|
|
23202
|
+
await new Promise((r) => { const t = setTimeout(r, LF_HEAL_POLL_MS); try { if (t && t.unref) t.unref(); } catch { /* ignore */ } });
|
|
23203
|
+
}
|
|
23204
|
+
}
|
|
23205
|
+
|
|
23206
|
+
/**
|
|
23207
|
+
* **播放失败自愈的客户端入口**(`<video>` 报 error → 这里)。
|
|
23208
|
+
*
|
|
23209
|
+
* 流程:判要不要去 → `POST /folia/local-heal` → 按结论:
|
|
23210
|
+
* corrupt / variant ⇒ 拿新 jobId 等它落地 ⇒ 重挂播放(同一张壁纸的下一次播就是好的)
|
|
23211
|
+
* transcoding ⇒ 轮询同一个接口直到出片(宿主在后台转,重复调用会命中同一份在途任务)
|
|
23212
|
+
* transcoded ⇒ 立刻重挂到 `?playable=1`
|
|
23213
|
+
* undecodable* ⇒ 只提示(+ 建议换一张),不再重试
|
|
23214
|
+
*
|
|
23215
|
+
* 返回最终结论(供调用点写 `selection.videoError`)。**不抛**:自愈失败也只是一句提示,
|
|
23216
|
+
* 绝不把"播放已经坏了"的现场升级成"连界面都炸了"。
|
|
23217
|
+
*
|
|
23218
|
+
* @param {{ id?: string, url?: string, code?: number, isVideo?: boolean,
|
|
23219
|
+
* originUrl?: string, sha256?: string, variants?: any[], base?: string,
|
|
23220
|
+
* title?: string, playing1080p?: boolean }} [fail]
|
|
23221
|
+
* @returns {Promise<{ verdict: string, message: string, mounted: boolean }>}
|
|
23222
|
+
*/
|
|
23223
|
+
async function lfHealPlayback(fail) {
|
|
23224
|
+
const f = fail || {};
|
|
23225
|
+
const key = String(f.id || f.url || "");
|
|
23226
|
+
const tried = Number(LF_HEAL_TRIES.get(key) || 0);
|
|
23227
|
+
const plan = dlHealPlan({ isVideo: f.isVideo !== false, url: f.url, code: f.code, tries: tried });
|
|
23228
|
+
if (plan === "skip") return { verdict: "skip", message: "", mounted: false };
|
|
23229
|
+
LF_HEAL_TRIES.set(key, tried + 1);
|
|
23230
|
+
const label = String(f.title || f.id || "");
|
|
23231
|
+
const mount = LF_HEAL_HOOKS.mount;
|
|
23232
|
+
/**
|
|
23233
|
+
* 结论 + 这张壁纸的标题(一句整话,交给词表插值)。
|
|
23234
|
+
* ⚠️ 不能写成 `text + ":" + label`:那会被 i18n 门禁判成"半句话"(模板/拼接),
|
|
23235
|
+
* 而且英文语序里那个全角冒号本来就是错的。
|
|
23236
|
+
*/
|
|
23237
|
+
const withLabel = (text) => (label ? weT("{text} · {label}", { text: String(text || ""), label }) : String(text || ""));
|
|
23238
|
+
/** 把本体结论写成人话并试着重挂。 */
|
|
23239
|
+
const finish = async (res) => {
|
|
23240
|
+
const verdict = String((res && res.verdict) || "");
|
|
23241
|
+
if (verdict === "transcoding") {
|
|
23242
|
+
// 带数字的那一句(percent/eta 由宿主的 `transcodePlayableProgress` 给)。
|
|
23243
|
+
lfHealSay(withLabel(dlHealProgressNote(res && res.progress)), true);
|
|
23244
|
+
return { verdict, message: dlHealNote(verdict), mounted: false };
|
|
23245
|
+
}
|
|
23246
|
+
const message = dlHealNote(verdict);
|
|
23247
|
+
if (verdict === "corrupt" || verdict === "variant") {
|
|
23248
|
+
// 等它(单流重下 / 1080p 变体)落地,再重挂播放。
|
|
23249
|
+
const ok = await lfAwaitHealJobP(res.jobId);
|
|
23250
|
+
if (!ok) {
|
|
23251
|
+
const t = weT("重新获取失败(可稍后再点一次这张)");
|
|
23252
|
+
lfHealSay(t, false);
|
|
23253
|
+
return { verdict: "failed", message: t, mounted: false };
|
|
23254
|
+
}
|
|
23255
|
+
const url = res.url || (res.jobId ? "/folia/local-media/" + encodeURIComponent(String(res.jobId)) : "");
|
|
23256
|
+
const done = Boolean(url && mount && mount(url));
|
|
23257
|
+
lfHealSay(withLabel(message), true);
|
|
23258
|
+
return { verdict, message, mounted: done };
|
|
23259
|
+
}
|
|
23260
|
+
if (verdict === "transcoded") {
|
|
23261
|
+
const done = Boolean(res.url && mount && mount(res.url));
|
|
23262
|
+
lfHealSay(withLabel(message), true);
|
|
23263
|
+
return { verdict, message, mounted: done };
|
|
23264
|
+
}
|
|
23265
|
+
lfHealSay(withLabel(message), false);
|
|
23266
|
+
return { verdict: verdict || "error", message, mounted: false };
|
|
23267
|
+
};
|
|
23268
|
+
try {
|
|
23269
|
+
let res = await apiPostJson("/local-heal", {
|
|
23270
|
+
id: String(f.id || ""),
|
|
23271
|
+
localUrl: String(f.url || ""),
|
|
23272
|
+
originUrl: String(f.originUrl || ""),
|
|
23273
|
+
sha256: String(f.sha256 || ""),
|
|
23274
|
+
variants: Array.isArray(f.variants) ? f.variants : [],
|
|
23275
|
+
base: String(f.base || ""),
|
|
23276
|
+
title: label,
|
|
23277
|
+
playing1080p: f.playing1080p === true,
|
|
23278
|
+
}, { parse: "always" });
|
|
23279
|
+
let doc = (res && res.data) || res || {};
|
|
23280
|
+
let out = await finish(doc);
|
|
23281
|
+
// 转码是几十秒级的:宿主先回 `transcoding`,这里按它给的间隔继续问同一个接口,
|
|
23282
|
+
// 直到出片或超过上限。每次调用都命中宿主那份**在途**任务,不会重复起 ffmpeg。
|
|
23283
|
+
let waited = 0;
|
|
23284
|
+
while (out.verdict === "transcoding" && waited < LF_HEAL_POLL_MAX_MS) {
|
|
23285
|
+
const step = Math.max(500, Number(doc && doc.retryAfterMs) || LF_HEAL_POLL_MS);
|
|
23286
|
+
await new Promise((r) => { const t = setTimeout(r, step); try { if (t && t.unref) t.unref(); } catch { /* ignore */ } });
|
|
23287
|
+
waited += step;
|
|
23288
|
+
res = await apiPostJson("/local-heal", {
|
|
23289
|
+
id: String(f.id || ""), localUrl: String(f.url || ""), sha256: String(f.sha256 || ""),
|
|
23290
|
+
variants: Array.isArray(f.variants) ? f.variants : [], base: String(f.base || ""),
|
|
23291
|
+
title: label, playing1080p: f.playing1080p === true,
|
|
23292
|
+
}, { parse: "always" });
|
|
23293
|
+
doc = (res && res.data) || res || {};
|
|
23294
|
+
out = await finish(doc);
|
|
23295
|
+
}
|
|
23296
|
+
if (out.verdict === "transcoding") {
|
|
23297
|
+
const t = weT("转码超时(可稍后再点一次这张,宿主会接着上次的进度)");
|
|
23298
|
+
lfHealSay(t, false);
|
|
23299
|
+
return { verdict: "timeout", message: t, mounted: false };
|
|
23300
|
+
}
|
|
23301
|
+
return out;
|
|
23302
|
+
} catch (err) {
|
|
23303
|
+
// 老宿主没有这条路由 / 网络问题:只说一句,播放器照旧留着那句原始错误。
|
|
23304
|
+
return { verdict: "error", message: String((err && err.message) || err || ""), mounted: false };
|
|
23305
|
+
}
|
|
23306
|
+
}
|
|
23307
|
+
|
|
22601
23308
|
/**
|
|
22602
23309
|
* React:订阅下载队列(三个页签共用)。
|
|
22603
23310
|
* 挂载先拉一次;有未结束 job 才每 1.5s 拉;**卸载即清定时器**(切页签不泄漏)。
|
|
@@ -22764,6 +23471,13 @@ window.__ModuleLoader__.load({
|
|
|
22764
23471
|
return n;
|
|
22765
23472
|
});
|
|
22766
23473
|
setSub({ id: k, at: Date.now() });
|
|
23474
|
+
// 4.23.14:让「提交中…(正在准备)」在**300ms**准时出现。常驻秒表是 1 秒一拍,
|
|
23475
|
+
// 单靠它最快也要 ~1s;这里补一拍,与 `dlInstallClick` 的占位是同一个常量、同一句话。
|
|
23476
|
+
setNowMs(Date.now());
|
|
23477
|
+
try {
|
|
23478
|
+
const timer = setTimeout(() => setNowMs(Date.now()), DL_FIRST_CLICK_PLACEHOLDER_MS);
|
|
23479
|
+
if (timer && typeof timer.unref === "function") timer.unref();
|
|
23480
|
+
} catch { /* 定时器失败不影响提交 */ }
|
|
22767
23481
|
api.refresh();
|
|
22768
23482
|
},
|
|
22769
23483
|
/** 请求返回(成功/失败/超时):退出 submitting。 */
|
|
@@ -30686,6 +31400,14 @@ window.__ModuleLoader__.load({
|
|
|
30686
31400
|
cacheBusy: "",
|
|
30687
31401
|
cacheNote: "",
|
|
30688
31402
|
cacheError: "",
|
|
31403
|
+
// 「本地媒体自检」(4.23.15,transient):`GET /folia/local-check` 的账本
|
|
31404
|
+
// (损坏 / 已清理 / 待重下 / 最近发现清单)、全量校验的在途标记、一次校验的结果一句话。
|
|
31405
|
+
// 与 cacheUsage 同款:不落盘 —— 它是"这台机器此刻的体检读数",重启后重测即可。
|
|
31406
|
+
mediaHealth: null,
|
|
31407
|
+
mediaVerifyBusy: "",
|
|
31408
|
+
mediaVerifyNote: "",
|
|
31409
|
+
// 本地优先/自愈的一句提示(信息类;失败类走 videoError 的红色行)。
|
|
31410
|
+
mediaNote: "",
|
|
30689
31411
|
// WE 官方资源路径编辑器(transient):开态 + 草稿路径 + 上次错误。
|
|
30690
31412
|
// 生效状态(目录/可用性)由 inventory 携带(host 是唯一真相)。
|
|
30691
31413
|
editingWeAssetsDir: false,
|
|
@@ -31954,6 +32676,54 @@ window.__ModuleLoader__.load({
|
|
|
31954
32676
|
clearCacheTargets(["skins"]);
|
|
31955
32677
|
}
|
|
31956
32678
|
|
|
32679
|
+
/* ── 本地媒体自检(4.23.15)─────────────────────────────────────────────────
|
|
32680
|
+
*
|
|
32681
|
+
* 面板只做两件事:**把账本画出来**、**把"校验并修复"发过去**。判据与动作全在宿主
|
|
32682
|
+
* (`lib/media-selfheal.js`):客户端既没有磁盘也没有站点清单,任何"自己判一下"的写法
|
|
32683
|
+
* 都会变成第二份会漂的实现。
|
|
32684
|
+
*/
|
|
32685
|
+
const MEDIA_HEALTH_URL = "/folia/local-check";
|
|
32686
|
+
const MEDIA_VERIFY_URL = "/folia/local-verify";
|
|
32687
|
+
|
|
32688
|
+
/** 拉一次体检账本(只读:宿主不建目录、不改盘、不触发校验)。 */
|
|
32689
|
+
async function loadMediaHealth() {
|
|
32690
|
+
try {
|
|
32691
|
+
const res = await apiJson(MEDIA_HEALTH_URL);
|
|
32692
|
+
const doc = (res && res.data) || res || null;
|
|
32693
|
+
const health = doc && doc.health ? doc.health : null;
|
|
32694
|
+
if (health) setTransient("mediaHealth", health);
|
|
32695
|
+
} catch { /* 老宿主没有这条路由:面板就显示"未校验",不报错 */ }
|
|
32696
|
+
}
|
|
32697
|
+
|
|
32698
|
+
/**
|
|
32699
|
+
* 「校验并修复本地媒体」= 第 2 步的**全量版**(同一条判据、同一段代码路径)。
|
|
32700
|
+
* 完成后刷新账本与清单:坏文件已被删掉并排回下载队列 ⇒ 卡片上的「已缓存」角标会跟着变。
|
|
32701
|
+
*/
|
|
32702
|
+
async function verifyLocalMedia() {
|
|
32703
|
+
if (selection.mediaVerifyBusy) return;
|
|
32704
|
+
setTransient("mediaVerifyBusy", "verify");
|
|
32705
|
+
setTransient("mediaVerifyNote", "");
|
|
32706
|
+
emit();
|
|
32707
|
+
try {
|
|
32708
|
+
const res = await apiPostJson(MEDIA_VERIFY_URL, {}, { parse: "always" });
|
|
32709
|
+
const d = (res && res.data) || {};
|
|
32710
|
+
const checked = Number(d.checked) || 0;
|
|
32711
|
+
const damaged = Number(d.damaged) || 0;
|
|
32712
|
+
if (d && d.health) setTransient("mediaHealth", d.health);
|
|
32713
|
+
setTransient("mediaVerifyNote", damaged
|
|
32714
|
+
? weT("已校验 {n} 个文件:发现 {bad} 个损坏,已清理并排回下载队列", { n: checked, bad: damaged })
|
|
32715
|
+
: weT("已校验 {n} 个文件:没有发现损坏", { n: checked }));
|
|
32716
|
+
// 坏文件被删 ⇒ inventory 的 localReady/local 会变,清单必须重拉(同一份结论处处一致)。
|
|
32717
|
+
if (damaged) { try { await loadInventory(); } catch { /* 清单刷新失败不影响"已清理"这个事实 */ } }
|
|
32718
|
+
} catch (err) {
|
|
32719
|
+
setTransient("mediaVerifyNote", weT("校验失败:{error}", {
|
|
32720
|
+
error: String((err && err.message) || err || ""),
|
|
32721
|
+
}));
|
|
32722
|
+
}
|
|
32723
|
+
setTransient("mediaVerifyBusy", "");
|
|
32724
|
+
emit();
|
|
32725
|
+
}
|
|
32726
|
+
|
|
31957
32727
|
const WE_ASSETS_DIR_URL = "/folia/we-assets-dir";
|
|
31958
32728
|
|
|
31959
32729
|
// Set / clear the WE official-assets directory (host-persisted). Scene live
|
|
@@ -32240,6 +33010,197 @@ window.__ModuleLoader__.load({
|
|
|
32240
33010
|
setTransient("videoError", reason);
|
|
32241
33011
|
emit();
|
|
32242
33012
|
}
|
|
33013
|
+
/* ── 播放失败自愈(4.23.15)────────────────────────────────────────────────────
|
|
33014
|
+
*
|
|
33015
|
+
* 用户实测(另一台机器):「视频解码失败(文件可能已损坏)」/「浏览器无法解码这段视频」,
|
|
33016
|
+
* 而面板同时说"缓存命中 4/5"。播放路径直接读本地文件、**没有任何自检** —— 4.23.6 之前
|
|
33017
|
+
* ranged 静默损坏遗留的坏成品会永久留在 library 里,每次点都是同一句错误。
|
|
33018
|
+
*
|
|
33019
|
+
* 这一层的职责只有三件(判据与动作都在宿主与 local-first.js,这里只接线):
|
|
33020
|
+
* ① 认出"**在屏那个** <video> 报了**解码/源不支持**错误"(预热元素/探测元素不参与);
|
|
33021
|
+
* ② 把当前壁纸的证据(id / 本地地址 / 站点 sha256 / 变体 / 是否 1080p)交给 `lfHealPlayback`;
|
|
33022
|
+
* ③ 提供 `mount(url)`:把修好的地址重挂到**在屏元素**上(同一张壁纸、同一个元素,
|
|
33023
|
+
* 不重建解码器之外的任何东西 —— 换 src 就是一次新的资源选择)。
|
|
33024
|
+
*
|
|
33025
|
+
* 为什么必须"同一个元素重挂"而不是重新 applySelection:重建层会把整条切换四段式再跑一遍
|
|
33026
|
+
*(淡入淡出、首帧预算、池领养),代价是数秒的黑屏;而此刻用户要的是"这张图赶紧出来"。
|
|
33027
|
+
*/
|
|
33028
|
+
/** 同一张壁纸只允许一条自愈在飞(`error` 事件会连发好几颗)。 */
|
|
33029
|
+
let selfHealInflightKey = "";
|
|
33030
|
+
|
|
33031
|
+
/** 当前选择对应的 inventory 条目(站点条目带 sha256 / variants;本机条目没有也能用)。 */
|
|
33032
|
+
function selfHealItemOf(id) {
|
|
33033
|
+
try {
|
|
33034
|
+
const pools = [
|
|
33035
|
+
selection.inventory && selection.inventory.wallpapers,
|
|
33036
|
+
selection.inventory && selection.inventory.items,
|
|
33037
|
+
];
|
|
33038
|
+
for (const pool of pools) {
|
|
33039
|
+
if (!Array.isArray(pool)) continue;
|
|
33040
|
+
const hit = pool.find((w) => w && w.id === id);
|
|
33041
|
+
if (hit) return hit;
|
|
33042
|
+
}
|
|
33043
|
+
} catch { /* 清单形状意外:当作没有条目(宿主仍能按 job 自己判) */ }
|
|
33044
|
+
return null;
|
|
33045
|
+
}
|
|
33046
|
+
|
|
33047
|
+
/** 在屏的那一个 `<video>`(层内或池的可见元素);都不是就 null。 */
|
|
33048
|
+
function onScreenVideo(node) {
|
|
33049
|
+
const v = node || null;
|
|
33050
|
+
if (!v) return null;
|
|
33051
|
+
try {
|
|
33052
|
+
const layer = document.getElementById(LAYER_ID);
|
|
33053
|
+
if (layer && typeof layer.contains === "function" && layer.contains(v)) return v;
|
|
33054
|
+
} catch { /* ignore */ }
|
|
33055
|
+
try { if (typeof weSwitchVisibleEl !== "undefined" && weSwitchVisibleEl && weSwitchVisibleEl === v) return v; } catch { /* ignore */ }
|
|
33056
|
+
return null;
|
|
33057
|
+
}
|
|
33058
|
+
|
|
33059
|
+
/**
|
|
33060
|
+
* `<video>` 报错 → 要不要自愈(并把证据交给 `lfHealPlayback`)。
|
|
33061
|
+
* 幂等:同一 (id, 地址) 同时只有一条在飞;连续 error 不会连开多条重下。
|
|
33062
|
+
*/
|
|
33063
|
+
function maybeSelfHealVideo(video) {
|
|
33064
|
+
const el = onScreenVideo(video);
|
|
33065
|
+
if (!el) return;
|
|
33066
|
+
const code = Number((el.error && el.error.code) || 0);
|
|
33067
|
+
const srcUrl = String(el.currentSrc || el.src || selection.url || "");
|
|
33068
|
+
const selUrl = String(selection.url || "");
|
|
33069
|
+
// 只认**当前这张**的地址:池里可能留着上一张的 src(预热对手),那不是本次的故障。
|
|
33070
|
+
const url = srcUrl || selUrl;
|
|
33071
|
+
if (!url) return;
|
|
33072
|
+
if (selUrl && srcUrl && srcUrl.indexOf(selUrl.split("?")[0]) < 0 && srcUrl.indexOf("/local-media/") < 0) return;
|
|
33073
|
+
const id = String(selection.id || "");
|
|
33074
|
+
const key = id + "|" + url;
|
|
33075
|
+
if (selfHealInflightKey === key) return;
|
|
33076
|
+
if (dlHealPlan({ isVideo: selection.type === "video", url, code, tries: 0 }) !== "heal") return;
|
|
33077
|
+
const item = selfHealItemOf(id);
|
|
33078
|
+
const variants = item && Array.isArray(item.variants) ? item.variants : [];
|
|
33079
|
+
const sha256 = String((item && item.sha256) || "");
|
|
33080
|
+
const playing1080p = Boolean(item && item.chosenVariant === "1080p");
|
|
33081
|
+
selfHealInflightKey = key;
|
|
33082
|
+
liveLog("media-selfheal", "code=" + code + " url=" + url + " ⇒ 交给宿主取证");
|
|
33083
|
+
Promise.resolve()
|
|
33084
|
+
.then(() => lfHealPlayback({
|
|
33085
|
+
id, url, code, isVideo: selection.type === "video",
|
|
33086
|
+
originUrl: String((item && item.media) || selection.originUrl || ""),
|
|
33087
|
+
sha256, variants, title: String(selection.title || id),
|
|
33088
|
+
playing1080p,
|
|
33089
|
+
}))
|
|
33090
|
+
.then((res) => {
|
|
33091
|
+
if (res && res.mounted) { liveLog("media-selfheal", "已重挂播放:" + res.message); return; }
|
|
33092
|
+
// 没挂上 ⇒ 走**最后一级**:静态帧兜底。需求原文是"只要站点上有可用文件,最终都必须能上屏",
|
|
33093
|
+
// 所以只有连一张静态图都没有时,才允许说"无法显示"。
|
|
33094
|
+
const still = staticFallbackUrlOf();
|
|
33095
|
+
const plan = dlHealFallbackPlan({ verdict: res && res.verdict, hasPreview: Boolean(still) });
|
|
33096
|
+
if (plan === "static-frame" && mountStaticFrameFallback(still)) {
|
|
33097
|
+
liveLog("media-selfheal", "静态帧兜底:" + still);
|
|
33098
|
+
try {
|
|
33099
|
+
setTransient("videoError", "");
|
|
33100
|
+
setTransient("mediaNote", weT("已降级为静态壁纸(本机不支持该视频解码)"));
|
|
33101
|
+
emit();
|
|
33102
|
+
} catch { /* ignore */ }
|
|
33103
|
+
return;
|
|
33104
|
+
}
|
|
33105
|
+
if (plan === "cannot-display" || (plan === "static-frame" && !still)) {
|
|
33106
|
+
try {
|
|
33107
|
+
setTransient("videoError", weT("无法显示这张壁纸(本机不支持该视频解码,且没有可用的静态帧)"));
|
|
33108
|
+
emit();
|
|
33109
|
+
} catch { /* ignore */ }
|
|
33110
|
+
return;
|
|
33111
|
+
}
|
|
33112
|
+
if (res && res.message) { try { setTransient("videoError", res.message); emit(); } catch { /* ignore */ } }
|
|
33113
|
+
})
|
|
33114
|
+
.catch(() => { /* 自愈失败不改写原始错误 */ })
|
|
33115
|
+
.then(() => { if (selfHealInflightKey === key) selfHealInflightKey = ""; });
|
|
33116
|
+
}
|
|
33117
|
+
|
|
33118
|
+
/**
|
|
33119
|
+
* **静态帧兜底**(4.23.15 的最后一级):视频解不了时,把这张壁纸的缩略图/首帧当静态壁纸铺上去。
|
|
33120
|
+
*
|
|
33121
|
+
* 为什么必须有这一级(用户的最终目标:"任何一张壁纸,只要站点上有可用文件,最终都必须能上屏"):
|
|
33122
|
+
* 站点的视频条目几乎都带 `thumbUrl` / 宿主抽的首帧(`/video-preview/…`)。一张能看的静态图
|
|
33123
|
+
* 远好过一句"无法显示" —— 用户要的是**有壁纸**,不是"播放器没报错"。
|
|
33124
|
+
*
|
|
33125
|
+
* 实现:**不拆 `<video>`、不重建层**,只在同一层里追加一个 `.we-media` 的 `<img>`
|
|
33126
|
+
*(绝对定位、与视频同一套 fit 规则,后插入的兄弟节点画在上面)。坏掉的视频元素本来就不出像素,
|
|
33127
|
+
* 留着不碍事;拆它反而会把池的"谁在屏上"弄乱(那是 4.23.8 的账)。
|
|
33128
|
+
*
|
|
33129
|
+
* @param {string} url 静态帧地址(缩略图 / 首帧)
|
|
33130
|
+
* @returns {boolean} true = 已经铺上去
|
|
33131
|
+
*/
|
|
33132
|
+
function mountStaticFrameFallback(url) {
|
|
33133
|
+
const u = String(url || "");
|
|
33134
|
+
if (!u) return false;
|
|
33135
|
+
let layer;
|
|
33136
|
+
try { layer = document.getElementById(LAYER_ID); } catch { layer = null; }
|
|
33137
|
+
if (!layer) return false;
|
|
33138
|
+
try {
|
|
33139
|
+
const found = (typeof layer.querySelector === "function") ? layer.querySelector("img.we-media--static") : null;
|
|
33140
|
+
let img = found;
|
|
33141
|
+
if (!img) {
|
|
33142
|
+
img = document.createElement("img");
|
|
33143
|
+
img.className = "we-media we-media--static";
|
|
33144
|
+
img.setAttribute("alt", "");
|
|
33145
|
+
img.setAttribute("aria-hidden", "true");
|
|
33146
|
+
layer.appendChild(img);
|
|
33147
|
+
}
|
|
33148
|
+
img.src = u;
|
|
33149
|
+
img.dataset.weStatic = "1";
|
|
33150
|
+
return true;
|
|
33151
|
+
} catch { return false; }
|
|
33152
|
+
}
|
|
33153
|
+
|
|
33154
|
+
/** 这张壁纸能用来兜底的静态图(首帧优先,其次站点缩略图)。取不到 ⇒ ""。 */
|
|
33155
|
+
function staticFallbackUrlOf() {
|
|
33156
|
+
const item = selfHealItemOf(String(selection.id || ""));
|
|
33157
|
+
const cands = [
|
|
33158
|
+
selection.previewUrl,
|
|
33159
|
+
item && item.preview,
|
|
33160
|
+
item && item.thumbUrl,
|
|
33161
|
+
selection.frameUrl,
|
|
33162
|
+
];
|
|
33163
|
+
for (const c of cands) {
|
|
33164
|
+
const s = String(c || "");
|
|
33165
|
+
if (s) return s;
|
|
33166
|
+
}
|
|
33167
|
+
return "";
|
|
33168
|
+
}
|
|
33169
|
+
|
|
33170
|
+
/**
|
|
33171
|
+
* 把某个地址**重挂到在屏元素**上(自愈成功后调用)。返回 true = 已开始加载。
|
|
33172
|
+
*
|
|
33173
|
+
* 不变量:
|
|
33174
|
+
* · 只用**已确认可播**的地址(宿主回的 `?playable=1` 或新 job 的 `/local-media/<id>`);
|
|
33175
|
+
* · 清掉上一轮的 `weTranscoded` 标记 —— 否则 `maybeUpgradeToTranscoded` 会以为"已经在抽帧版上";
|
|
33176
|
+
* · 重挂前把面板那句错误清掉:新一轮要么成功(syncVideoState 自己会清),要么再报一次。
|
|
33177
|
+
*/
|
|
33178
|
+
function remountLayerVideo(url) {
|
|
33179
|
+
const u = String(url || "");
|
|
33180
|
+
if (!u) return false;
|
|
33181
|
+
let el;
|
|
33182
|
+
try { el = onScreenVideo(null) || (typeof weSwitchVisibleEl !== "undefined" ? weSwitchVisibleEl : null); } catch { el = null; }
|
|
33183
|
+
if (!el) {
|
|
33184
|
+
try {
|
|
33185
|
+
const layer = document.getElementById(LAYER_ID);
|
|
33186
|
+
el = layer && typeof layer.querySelector === "function" ? layer.querySelector("video") : null;
|
|
33187
|
+
} catch { el = null; }
|
|
33188
|
+
}
|
|
33189
|
+
if (!el) return false;
|
|
33190
|
+
try {
|
|
33191
|
+
delete el.dataset.weTranscoded;
|
|
33192
|
+
el.src = u;
|
|
33193
|
+
if (typeof el.load === "function") el.load();
|
|
33194
|
+
const p = el.play();
|
|
33195
|
+
if (p && typeof p.catch === "function") p.catch(() => { /* 静音自动播放被拒:loadeddata 会再试 */ });
|
|
33196
|
+
} catch { return false; }
|
|
33197
|
+
try { el.__weUrl = u; } catch { /* ignore */ }
|
|
33198
|
+
try { setTransient("videoError", ""); emit(); } catch { /* ignore */ }
|
|
33199
|
+
// 新一轮允许再自愈一次(坏文件被换掉之后再失败,是"另一个问题")。
|
|
33200
|
+
selfHealInflightKey = "";
|
|
33201
|
+
return true;
|
|
33202
|
+
}
|
|
33203
|
+
|
|
32243
33204
|
// 每个元素只挂一次状态监听(切壁纸会新建 <video>,故标记挂在元素上)。
|
|
32244
33205
|
function watchVideoState(video) {
|
|
32245
33206
|
if (!video || !video.dataset || video.dataset.weStateWatched === "1") return;
|
|
@@ -32247,6 +33208,9 @@ window.__ModuleLoader__.load({
|
|
|
32247
33208
|
for (const t of ["play", "playing", "pause", "ended", "error", "emptied"]) {
|
|
32248
33209
|
try { video.addEventListener(t, () => syncVideoState(video)); } catch { /* ignore */ }
|
|
32249
33210
|
}
|
|
33211
|
+
// 4.23.15:**播放失败自愈**(本地副本坏了 / 原画超出本机解码上限)。
|
|
33212
|
+
// 与 syncVideoState 并行挂:那一颗负责"把错误显示出来",这一颗负责"把它修好"。
|
|
33213
|
+
try { video.addEventListener("error", () => { maybeSelfHealVideo(video); }); } catch { /* ignore */ }
|
|
32250
33214
|
// 「当前视频播完就换下一张」(issue #230 后续诉求):轮播组选了 `trigger: 'videoEnd'`
|
|
32251
33215
|
// 时,壁纸视频的 ended 就是轮换信号 —— 与计时器二选一(syncRotationTimer 在该档不计时)。
|
|
32252
33216
|
// 只认**当前层**那个 <video>:预热 / 探测元素也走 watchVideoState,它们播完不代表壁纸播完。
|
|
@@ -34754,7 +35718,12 @@ window.__ModuleLoader__.load({
|
|
|
34754
35718
|
// 4.23.7「缓存管理」:进「系统」页签时拉一次用量(宿主那条路由**只读**,不建目录不改盘)。
|
|
34755
35719
|
// 只在切到这个页签时拉 —— 不跟着轮询走,免得为一份"几分钟都不变"的读数每分钟多发请求;
|
|
34756
35720
|
// 用户在面板里按「刷新」或清完一轮时会各自再拉一次(`loadCacheUsage` / `clearCacheTargets`)。
|
|
34757
|
-
|
|
35721
|
+
// 4.23.15:同一次进页签也拉一次**本地媒体体检账本**(`/folia/local-check`,同样只读)。
|
|
35722
|
+
React.useEffect(() => {
|
|
35723
|
+
if (activeTab !== "system") return;
|
|
35724
|
+
loadCacheUsage();
|
|
35725
|
+
loadMediaHealth();
|
|
35726
|
+
}, [activeTab]);
|
|
34758
35727
|
|
|
34759
35728
|
// 页签安全(ADR-0013 D3①):可见页签表变了(组件行状态随 inventory 轮询回到本地)而当前
|
|
34760
35729
|
// 页签不在表里 ⇒ 回落到第一个可见页签,自愈、不用用户自己点走。表为空(今天不可能,空表
|
|
@@ -34813,6 +35782,21 @@ window.__ModuleLoader__.load({
|
|
|
34813
35782
|
if (activeTab === "appearance" && pickerFontOpen && sel.fontCustom) ensureSystemFonts(false);
|
|
34814
35783
|
}, [activeTab, pickerFontOpen, sel.fontCustom]);
|
|
34815
35784
|
|
|
35785
|
+
// 4.23.15:**播放失败自愈**的两处接线(`src/local-first.js` 的两个注入位)。
|
|
35786
|
+
//
|
|
35787
|
+
// 为什么必须有这一个 effect(而不是让 local-first 直接调):那个文件是内联片段,
|
|
35788
|
+
// 它不知道"往哪写提示、哪个 <video> 在屏上"。在此之前 `setLocalFirstNote` **从来没有
|
|
35789
|
+
// 被调用过** —— 于是 `lfSay()` 全部静默("正在下载到本地 45%"这类话一句都没显示过)。
|
|
35790
|
+
// 顺手把它接上:信息类进 `mediaNote`(面板提示行),失败类进 `videoError`(红色错误行)。
|
|
35791
|
+
React.useEffect(() => {
|
|
35792
|
+
const say = (text, ok) => {
|
|
35793
|
+
const t = String(text || "");
|
|
35794
|
+
try { setTransient(ok === false ? "videoError" : "mediaNote", t); emit(); } catch { /* ignore */ }
|
|
35795
|
+
};
|
|
35796
|
+
try { if (typeof setLocalFirstNote === "function") setLocalFirstNote(say); } catch { /* ignore */ }
|
|
35797
|
+
try { if (typeof setSelfHealHooks === "function") setSelfHealHooks(say, remountLayerVideo); } catch { /* ignore */ }
|
|
35798
|
+
}, []);
|
|
35799
|
+
|
|
34816
35800
|
// 侧栏深链(快捷播放面板底栏的「更多外观设置 ›」/「更多播放设置 ›」):请求"打开
|
|
34817
35801
|
// 设置页后停在哪一页"。打开对话框由 src/sidebar-right.js 的 DOM 路径负责,这里只管
|
|
34818
35802
|
// 落地 —— 走**同一个 switchTab**(清待确认 / 退出下钻 / 写 localStorage 这些副作用
|
|
@@ -35018,6 +36002,8 @@ window.__ModuleLoader__.load({
|
|
|
35018
36002
|
// 4.23.7「缓存管理」:用量 / 刷新 / 五目标清理(`skins` 走两段式确认,令牌 "cache:skins")。
|
|
35019
36003
|
onClearCache: clearCacheTargets, onClearCacheSkins: onCacheClearSkins,
|
|
35020
36004
|
onRefreshCacheUsage: loadCacheUsage, armedConfirm: sel.armedConfirm, onDisarmConfirm: disarmConfirm,
|
|
36005
|
+
// 4.23.15「本地媒体自检」:账本刷新 / 全量校验并修复(= 启动采样那套判据的全量版)。
|
|
36006
|
+
onVerifyMedia: verifyLocalMedia, onRefreshMediaHealth: loadMediaHealth,
|
|
35021
36007
|
}),
|
|
35022
36008
|
);
|
|
35023
36009
|
return renderWallpaperTab({
|