dsh-dpharness 0.4.4 → 0.6.0

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 CHANGED
@@ -62,18 +62,34 @@ window.__ModuleLoader__.load({
62
62
  ".dph_bestItem{display:flex;flex-direction:column;gap:4px}",
63
63
  ".dph_bestRank{font-size:10px;font-weight:700;color:var(--dsw-alias-state-business-primary)}",
64
64
  ".dph_bestReason{font-size:10px;color:var(--dsw-alias-label-tertiary);padding-left:2px}",
65
+ /* 套装:槽位行 = 职责(这个位置干什么)→ 插件名 → 必要性标签 → 星标/已装。
66
+ 职责用等宽小字、与名字左对齐两栏,扫一眼能看出"这套配了哪些岗位"。 */
67
+ ".dph_setRow{display:flex;align-items:baseline;gap:8px;flex-wrap:wrap;padding:2px 0}",
68
+ ".dph_setRole{flex:none;min-width:74px;max-width:110px;font-size:11px;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
69
+ ".dph_setName{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}",
70
+ ".dph_cmdBlock{white-space:pre-wrap;word-break:break-all;max-height:132px;overflow:auto}",
65
71
  ".dph_cmd{flex:1;min-width:200px;box-sizing:border-box;background:var(--dsw-alias-bg-layer-3);border-radius:6px;padding:6px 10px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--dsw-alias-label-primary);overflow-x:auto;white-space:nowrap}",
66
72
  ".dph_cmdMissing{font-size:12px;color:var(--dsw-alias-label-tertiary)}",
67
73
  ".dph_notice{border:1px solid var(--dsw-alias-border-l2);border-radius:10px;padding:14px;font-size:13px;color:var(--dsw-alias-label-secondary)}",
68
74
  ".dph_noticeBad{border-color:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-state-error-primary)}",
69
75
  ".dph_footer{font-size:12px;color:var(--dsw-alias-label-tertiary);line-height:1.6}",
70
76
  ".dph_tel{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--dsw-alias-label-tertiary);cursor:pointer;user-select:none}",
71
- ".dph_lb{box-sizing:border-box;display:flex;align-items:center;justify-content:flex-start;gap:8px;width:calc(100% + 8px);height:34px;margin:4px -4px;color:var(--dsw-alias-label-primary);background:transparent;border:none;border-radius:12px;padding:6px 2px 6px 10px;font:inherit;font-size:14px;line-height:22px;text-align:left;cursor:pointer;transition:background .12s}",
77
+ /* 与自研三件套(归档/官网/重启)同一套原生行规格 */
78
+ ".dph_lbWide{display:flex;width:100%;align-self:stretch;min-width:0}",
79
+ ".dph_lbOff{display:flex;justify-content:center;width:100%;align-self:stretch;min-width:0}",
80
+ ".dph_lb{box-sizing:border-box;display:flex;align-items:center;justify-content:flex-start;gap:8px;width:100%;height:40px;margin:2px 0;color:var(--dsw-alias-label-primary);background:transparent;border:none;border-radius:12px;padding:0 10px 0 8px;font:inherit;font-size:14px;line-height:22px;text-align:left;cursor:pointer;transition:background .12s}",
81
+ ".dph_lb:focus-visible{outline:2px solid var(--dsw-specific-accent-primary,#4f46e5);outline-offset:1px}",
72
82
  ".dph_lb:hover{background:var(--dsw-alias-interactive-bg-hover)}",
73
- ".dph_lbLabel{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
83
+ ".dph_lbLabel{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:left}",
74
84
  ".dph_lbOff .dph_lb{justify-content:center;width:36px;height:36px;margin:2px 0;border-radius:50%;padding:0;gap:0}",
75
- ".dph_lbMark{font-size:13px;font-weight:600;color:var(--dsw-alias-state-business-primary)}",
76
- "div:has(> [data-slot=\"sidebar.footer.action\"]){flex-direction:column}",
85
+ ".dph_lbMark{flex:none;display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:13px;font-weight:600;line-height:1;color:var(--dsw-alias-state-business-primary)}",
86
+ /* 「上劲」态:浮窗被用户关掉后,点一下侧边栏按钮不恢复,只进入待确认——
87
+ 必须给可见反馈(描边 + 标记脉冲),否则用户以为点击又没生效
88
+ (2026-10-13 实测:纯无反馈的按钮直接被当成坏的)。5 秒不跟进自动解除。 */
89
+ ".dph_lbArmed{background:var(--dsw-alias-interactive-bg-hover);box-shadow:inset 0 0 0 1px var(--dsw-alias-state-business-primary)}",
90
+ ".dph_lbArmed .dph_lbMark{animation:dphArmPulse 1s ease-in-out infinite}",
91
+ "@keyframes dphArmPulse{50%{opacity:.4}}",
92
+ "div:has(> [data-slot=\"sidebar.footer.action\"]){flex-direction:column;align-items:stretch}",
77
93
  ".dph_ovWrap{position:fixed;right:16px;bottom:16px;z-index:2147483000;display:flex;flex-direction:column;align-items:flex-end;gap:8px}",
78
94
  ".dph_pillWrap{position:relative;display:flex}",
79
95
  /* 右侧多留 16px 给关闭按钮(padding-right 由 14 改 30) */
@@ -96,6 +112,7 @@ window.__ModuleLoader__.load({
96
112
  ".dph_close:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}",
97
113
  ".dph_cardSm{padding:10px 12px;gap:6px}",
98
114
  ".dph_instRow{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
115
+ ".dph_instCol{flex-direction:column;align-items:flex-start;gap:4px}",
99
116
  ".dph_btnPrimary{border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-state-business-primary);font-weight:600}",
100
117
  ".dph_btn:disabled{opacity:.55;cursor:not-allowed}",
101
118
  ".dph_instMsg{font-size:12px;color:var(--dsw-alias-label-secondary)}",
@@ -108,6 +125,61 @@ window.__ModuleLoader__.load({
108
125
  ".dph_raw{color:var(--dsw-alias-label-tertiary)}",
109
126
  ".dph_drag{cursor:grab;touch-action:none;user-select:none}",
110
127
  ".dph_drag:active{cursor:grabbing}",
128
+ /* 每日推荐:顶部卡片与专用视图。沿用严选卡片的规格,只加一层「今日」标识,
129
+ 边框用 business 色 —— 它是当天唯一一条,视觉上要和普通列表区分开。 */
130
+ ".dph_daily{display:flex;flex-direction:column;gap:6px;flex:none}",
131
+ ".dph_dailyHead{display:flex;align-items:baseline;gap:8px;flex-wrap:wrap}",
132
+ ".dph_dailyTag{flex:none;border:1px solid var(--dsw-alias-state-business-primary);color:var(--dsw-alias-state-business-primary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:600;line-height:16px}",
133
+ ".dph_dailyDate{font-size:12px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
134
+ ".dph_dailyPath{font-size:11px;color:var(--dsw-alias-label-tertiary)}",
135
+ ".dph_dailyWhy{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary);margin:0}",
136
+ /* 待重启横幅:本地通道安装/升级后跨视图常驻(2026-10-13)。
137
+ 用 business 色描边 —— 它是一条"待办",不是错误;生效确认态退回普通边框。 */
138
+ ".dph_restart{display:flex;align-items:center;gap:8px;flex-wrap:wrap;flex:none;padding:8px 12px;border:1px solid var(--dsw-alias-state-business-primary);border-radius:10px;background:var(--dsw-alias-interactive-bg-hover)}",
139
+ ".dph_restartOk{border-color:var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1)}",
140
+ ".dph_restartText{flex:1;min-width:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-primary)}",
141
+ /* 对比:入口条 + 并排事实表。列用 flex 等分,2 列/3 列都自适应(上限 3 见 COMPARE_MAX)。 */
142
+ ".dph_cmpBar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:6px 10px;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}",
143
+ ".dph_cmp{display:flex;flex-direction:column;gap:6px;padding:8px 10px;border:1px solid var(--dsw-alias-state-business-primary);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}",
144
+ ".dph_cmpRow{display:flex;gap:6px;align-items:flex-start}",
145
+ ".dph_cmpCell{flex:1;min-width:0;font-size:11px;line-height:1.5;color:var(--dsw-alias-label-primary);word-break:break-word}",
146
+ ".dph_cmpLabel{flex:none;width:56px;color:var(--dsw-alias-label-tertiary)}",
147
+ ".dph_cmpName{font-weight:600}",
148
+ /* 设置页(settings.plugins.tab)与设置行(settings.general.item) */
149
+ ".dph_set{display:flex;flex-direction:column;gap:12px}",
150
+ ".dph_setTitle{font-size:14px;font-weight:600;color:var(--dsw-alias-label-primary)}",
151
+ ".dph_setGroup{display:flex;flex-direction:column;gap:12px;border-top:1px solid var(--dsw-alias-border-l2);padding-top:12px}",
152
+ ".dph_setRow{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}",
153
+ ".dph_setCol{display:flex;flex-direction:column;gap:2px;min-width:0}",
154
+ ".dph_setLabel{font-size:13px;color:var(--dsw-alias-label-primary)}",
155
+ ".dph_setHint{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}",
156
+ ".dph_setState{flex:none;font-size:12px;color:var(--dsw-alias-label-secondary)}",
157
+ /* 更新日志:版本折叠列表。复用 details/summary(与分类精选同一手法)——
158
+ 原生折叠无需自己管状态,键盘可达性也白送。 */
159
+ ".dph_log{flex:none;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}",
160
+ ".dph_logHead{display:flex;align-items:baseline;gap:8px;padding:7px 10px;cursor:pointer;list-style:none;font-size:12px}",
161
+ ".dph_logHead::-webkit-details-marker{display:none}",
162
+ ".dph_logVer{flex:none;font-weight:600;color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums}",
163
+ ".dph_logDate{flex:none;font-size:11px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
164
+ ".dph_logTitle{font-size:11px;color:var(--dsw-alias-label-secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
165
+ ".dph_logItems{margin:0;padding:0 12px 10px 26px;display:flex;flex-direction:column;gap:4px}",
166
+ ".dph_logItems li{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary)}",
167
+ /* 「更新日志」块(浮窗「更新」视图):外层收起成一行,展开后内层仍是各版本的折叠项 */
168
+ ".dph_logNest{display:flex;flex-direction:column;gap:6px;padding:0 10px 10px}",
169
+ ".dph_logCmd{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
170
+ /* 更新红点。只有颜色没有文字,对读屏用户等于不存在 —— 所以点里塞一段视觉隐藏文案。 */
171
+ ".dph_dotWrap{position:relative;display:inline-flex;flex:none}",
172
+ ".dph_dot{position:absolute;top:-2px;right:-2px;width:7px;height:7px;border-radius:50%;background:var(--dsw-alias-state-error-primary);box-shadow:0 0 0 1.5px var(--dsw-alias-bg-layer-1)}",
173
+ ".dph_sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}",
174
+ /* 「更新」视图的行:第一行 = 谁 + 版本 + 操作;第二行 = 这是什么 + 包名 */
175
+ ".dph_updItem{display:flex;flex-direction:column;gap:5px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-1);padding:8px 10px;flex:none}",
176
+ ".dph_updOn{border-color:var(--dsw-alias-state-error-primary)}",
177
+ ".dph_upd{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
178
+ ".dph_updSub{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}",
179
+ ".dph_updName{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}",
180
+ ".dph_updVer{font-size:12px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}",
181
+ ".dph_updNote{font-size:11px;color:var(--dsw-alias-label-tertiary)}",
182
+ ".dph_updList{display:flex;flex-direction:column;gap:6px}",
111
183
  ].join("");
112
184
  const tagId = "dsh-dpharness/client.css";
113
185
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
@@ -135,12 +207,188 @@ window.__ModuleLoader__.load({
135
207
  "action.copy": "复制命令",
136
208
  "action.copied": "已复制",
137
209
  "action.open": "严选插件",
210
+ "action.show": "显示浮窗",
138
211
  "action.close": "收起",
139
212
  "action.drag": "可拖动调整位置",
140
213
  "action.hide": "隐藏浮窗",
141
- "action.hideHint": "隐藏后:侧边栏底部「严选插件」可再次打开,或在「严选插件」页底部重新勾选",
214
+ "action.hideHint": "隐藏后不会自动回来,误点也不会:连点两下侧边栏「严选插件」可恢复(第二下才生效),或在「严选插件」页底部重新勾选、设置 → 通用 打开开关",
215
+ "action.closedHint": "浮窗已关闭 —— 点这里不会把它叫回来;在「严选插件」页底部重新勾选,或在 设置 → 通用 打开「右下角浮窗」",
216
+ "action.armRestore": "再点一次恢复浮窗",
217
+ "action.expand": "展开面板",
142
218
  "action.showFloat": "显示右下角浮窗",
219
+ "settings.tab": "严选插件",
220
+ "settings.title": "严选插件",
221
+ "settings.float": "右下角浮窗",
222
+ "settings.floatHint": "关闭后不再自动出现,误点也不会叫回来。想恢复:连点两下侧边栏「严选插件」(第二下生效),或在「严选插件」页底部重新勾选。",
223
+ "settings.daily": "每日推荐",
224
+ "settings.dailyHint": "每天推荐一个插件,按自然日轮换(同一自然日对所有用户一致)。",
225
+ "settings.check": "自动检查插件更新",
226
+ "settings.checkHint": "打开 dsh 时向 npm 镜像查询已装插件的最新版(每台机器约 20 次只读请求,最多 10 分钟一次)。关掉后红点不再提醒,仍可手动「检查更新」。",
227
+ "settings.telemetry": "匿名统计",
228
+ "settings.on": "已开启",
229
+ "settings.off": "已关闭",
230
+ "settings.reset": "恢复默认",
231
+ "settings.resetHint": "清除浮窗显示、浮窗位置与每日推荐的本地偏好。",
232
+ "settings.resetDone": "已恢复默认。",
233
+ "settings.about": "以上偏好只保存在本机(localStorage),不会上传;匿名统计的开关同样在本页。",
234
+ "daily.tab": "每日推荐",
235
+ "daily.title": "今日推荐",
236
+ "daily.loading": "正在取今日推荐…",
237
+ "daily.empty": "今日推荐暂不可用(榜单数据未就绪)",
238
+ "daily.why": "为什么是它",
239
+ "daily.hint": "每天 00:00(北京时间)换一条,当天对所有用户一致。",
240
+ "daily.expand": "展开",
241
+ "daily.collapse": "收起",
242
+ "changelog.title": "更新日志",
243
+ "changelog.current": "当前版本 v{v}",
244
+ "changelog.loading": "正在读取更新日志…",
245
+ "changelog.failed": "更新日志读取失败(本机 host 未响应)",
246
+ "changelog.newAvailable": "有新版本 v{v}",
247
+ "changelog.upToDate": "已是最新版",
248
+ "changelog.copyUpgrade": "复制升级命令",
249
+ "changelog.hint": "升级后需要重启 dsh 才会生效;命令里的 profile 已按你本机填好。",
250
+ "changelog.noItems": "该版本没有留下说明。",
251
+ "updates.tab": "我的插件",
252
+ "updates.title": "我的插件",
253
+ "updates.dot": "有可用更新",
254
+ "updates.check": "检查更新",
255
+ "updates.checking": "检查中…",
256
+ "updates.self": "本插件",
257
+ "updates.installed": "已安装的插件",
258
+ "updates.outdated": "可升级",
259
+ "updates.upToDate": "已是最新",
260
+ "updates.unknown": "查不到最新版",
261
+ "updates.none": "已安装的插件都是最新版。",
262
+ "updates.summary": "已检查 {n} 个插件 · 可升级 {m} 个",
263
+ "updates.unknownNote": "另有 {k} 个查不到最新版(多半是没发布到 npm 的本地插件),不下结论。",
264
+ "updates.copyCmd": "复制升级命令",
265
+ "updates.failed": "更新检查失败",
266
+ "updates.loading": "正在检查更新…",
267
+ "updates.note": "最新版来自 npmmirror;这里只发只读请求,不会替你安装任何东西。",
268
+ "updates.remove": "卸载",
269
+ "updates.removeConfirm": "确认卸载?",
270
+ "updates.removing": "正在卸载…",
271
+ "updates.removed": "已卸载",
272
+ "updates.removedRestart": "重启 dsh 后彻底移除",
273
+ "updates.nothingToRemove": "本来就没装",
274
+ "updates.ignore": "忽略此版本",
275
+ "updates.ignored": "已忽略 v{v}",
276
+ "updates.unignore": "取消忽略",
277
+ "updates.ignoreHint": "升到 v{v} 之前不再提醒",
278
+ "sets.installAll": "一键安装整套({n})",
279
+ "sets.installAllConfirm": "将逐个安装 {n} 个插件(会改本机 profile、需要重启 dsh 才生效)—— 再点一次开始。",
280
+ "sets.installing": "安装中 {done}/{total} · {name}",
281
+ "compare.pick": "对比",
282
+ "compare.picked": "已选",
283
+ "compare.toggle": "加入对比(最多 {max} 个)",
284
+ "compare.selected": "已选 {n}/{max}",
285
+ "compare.needTwo": "至少选 2 个才能对比",
286
+ "compare.show": "开始对比",
287
+ "compare.hide": "收起对比",
288
+ "compare.clear": "清空",
289
+ "compare.stars": "星标",
290
+ "compare.verify": "实装验证",
291
+ "compare.tested": "人工实测通过",
292
+ "compare.verified": "通过安装校验",
293
+ "compare.unverified": "未验证",
294
+ "compare.installed": "本机",
295
+ "compare.notInstalled": "未安装",
296
+ "compare.cat": "分类",
297
+ "compare.sell": "卖点",
298
+ "compare.install": "安装命令",
299
+ "fav.toggle": "收藏待装",
300
+ "fav.add": "收藏",
301
+ "fav.added": "已藏",
302
+ "fav.title": "收藏待装",
303
+ "fav.count": "收藏待装({n})",
304
+ "fav.hint": "先攒着,之后再一起装;只存本机,不会上传。",
305
+ "fav.remove": "移除",
306
+ "fav.installAll": "一键安装全部({n})",
307
+ "fav.installConfirm": "将逐个安装 {n} 个收藏(会改本机 profile、需要重启 dsh 才生效)—— 再点一次开始。",
308
+ "fav.empty": "还没有收藏。在「严选推荐」的卡片上点「收藏」就会放到这里。",
309
+ "benefits.title": "福利专区",
310
+ "benefits.body": "全网大模型新用户免费额度与限时活动,每周人工更新。",
311
+ "updates.ackNote": "红点在你打开本页后熄灭,只有再出现更新的版本才会重新亮。",
312
+ "updates.restartConfirm": "确认重启 dsh?重启后当前会话会中断。",
313
+ "updates.upgrade": "升级",
314
+ "updates.upgradeConfirm": "确认升级到最新版?",
315
+ "updates.upgradeHint": "升级会在本机执行 dsh plugin add <包名>@latest,改的是你的 profile,装完需要重启 dsh。",
316
+ "updates.upgradeAll": "全部升级({n})",
317
+ "updates.upgradeAllHint": "逐个串行执行(宿主同一时刻只允许一个安装任务),可随时中止;未轮到的项保持原状。",
318
+ "updates.upgradeAllConfirm": "将逐个升级 {n} 个插件(会改写本机 profile、需要重启 dsh)—— 再点一次开始。",
319
+ "updates.batchProgress": "升级中 {done}/{total} · {name}",
320
+ "updates.stop": "中止",
321
+ "updates.batchDone": "已处理 {done} 个 · 失败 {failed} 个",
322
+ "updates.restartNeeded": "有项目经本地通道安装,需要重启 dsh 才生效。",
323
+ "updates.blocked": "dsh 不兼容",
324
+ "updates.blockedTitle": "dsh 不接受这个版本",
325
+ "updates.blockedBody": "「{spec}」声明只兼容更早的 dsh,而你本机是 {dsh}。这是 dsh 自己的保护机制(它的原话:可能崩溃或数据损坏),要显式放行才能装。",
326
+ "updates.blockedHow": "放行通道见 dsh 自己的说明(dsh plugin allow-version,或插件管理器里的「精确版本豁免」)。本插件不代你放行。",
327
+ "updates.releaseAge": "供应链策略暂停",
328
+ "updates.releaseAgeTitle": "供应链策略暂停了这次安装",
329
+ "updates.releaseAgeBody": "pnpm 默认拒绝「发布不满 24 小时」的版本,本次被拦下 {n} 条:{list}。",
330
+ "updates.releaseAgeHow": "两条路:① 等 —— 最新一条约 {h} 小时后自动可装;② 在本机 profile 的 pnpm-workspace.yaml 里给这些包加 minimumReleaseAgeExclude 豁免(同一个包要写成一条规则,多条 name@version 只有第一条生效)。",
331
+ "updates.copyRaw": "复制 dsh 原始说明",
332
+ "updates.batchBlocked": "(其中 {k} 个被 dsh 兼容性闸门拦下)",
333
+ "updates.locals": "另有 {n} 个插件是本地链接,不参与更新检查",
334
+ "updates.localsNote": "它们的版本来自本机源码(不是 npm),升级会去装 npm 版本并替换掉你的链接,所以这里不提供升级。",
335
+ "updates.pinned": "清单锁定",
336
+ "updates.pinnedNote": "清单里写死为 v{v};plugin add 不会把它挪走,要升请先改成范围。",
337
+ "updates.noChangeTitle": "dsh 报告成功,但什么都没装",
338
+ "updates.noChange": "安装目录里的版本仍是 v{v},且本次操作 dsh 没有任何输出 —— 插件可能已经就是这个版本,或 dsh 的 plugin add 对它不生效。",
339
+ "updates.alreadyTitle": "已经装的就是这个版本",
340
+ "updates.alreadyHint": "当前 v{v} —— 无需重新安装。",
341
+ "card.installed": "已安装 v{v}",
342
+ "install.reinstall": "重新安装",
343
+ "install.reinstallConfirm": "确认重新安装?",
344
+ "updates.batchNoop": "(其中 {k} 个 dsh 报告成功但版本没变)",
345
+ "usage.summary": "近 {d} 天:核心 {a} · 常用 {b} · 偶尔 {c} · 可考虑清理 {e} · 无法度量 {f}",
346
+ "usage.core": "核心在用",
347
+ "usage.common": "常用",
348
+ "usage.occasional": "偶尔用",
349
+ "usage.silent": "可考虑清理",
350
+ "usage.disabled": "已停用",
351
+ "usage.unmeasurable": "无法度量",
352
+ "usage.unknown": "使用数据不可用",
353
+ "usage.calls30d": "近30天 {n} 次",
354
+ "usage.stats": "近30天 {n} 次 · 上次使用 {d}",
355
+ "usage.today": "今天",
356
+ "usage.yesterday": "昨天",
357
+ "usage.daysAgo": "{d} 天前",
358
+ "usage.silentNote": "近 30 天没有可观测的调用记录",
359
+ "usage.unmeasurableNote": "该插件不产生可观测的调用(被动型),是否保留请人工判断",
360
+ "usage.unknownNote": "暂时读不到使用数据(宿主未提供统计)",
361
+ "usage.keep": "保留",
362
+ "usage.kept": "已保留",
363
+ "usage.keepHint": "标为保留后,不会再出现在清理建议里(只存本机,不上传)",
364
+ "usage.onlySuggest": "只看建议清理",
365
+ "usage.sortUsage": "按使用频率",
366
+ "usage.sortUsageOn": "恢复默认排序",
367
+ "usage.noneSuggest": "没有建议清理的插件(已保留的不会出现在这里)。",
368
+ "usage.disable": "禁用",
369
+ "usage.enable": "启用",
370
+ "usage.disableConfirm": "确认禁用?",
371
+ "usage.enableConfirm": "确认启用?",
372
+ "usage.toggleHint": "禁用/启用即时生效、随时可恢复(改的是本机 profile patch,不动依赖清单)",
373
+ "usage.toggling": "处理中…",
374
+ "usage.disabledDone": "已禁用",
375
+ "usage.enabledDone": "已启用",
376
+ "usage.toggleFailed": "操作失败",
377
+ "usage.toggleOverridden": "未能生效(被更高优先级的层覆盖)",
378
+ "usage.toggleSelf": "不能禁用它自己(管理界面会一起消失)",
379
+ "usage.toggleReadonly": "该行由 dsh 管理,不能在这里启停",
380
+ "usage.toggleUnaddressable": "该行定位不到(刷新后重试)",
381
+ "usage.toggleUnsupported": "当前宿主不支持启停(需要较新的 dsh)",
382
+ "usage.batchDisable": "批量禁用({n})",
383
+ "usage.batchConfirm": "将逐个禁用 {n} 个启用中的候选(可随时恢复)—— 再点一次开始。",
384
+ "usage.batchProgress": "禁用中 {done}/{total} · {name}",
385
+ "usage.batchDone": "已禁用 {done} 个 · 失败 {failed} 个",
386
+ "usage.batchHint": "只处理启用中的候选;已停用的请在行内卸载",
387
+ "host.stale": "本机 host 还没提供这个接口 —— 通常是 dsh 未重启。重启 dsh 后再试。",
388
+ "host.skew": "宿主进程是旧版本:本页需要更新的接口字段(重启后正常)。",
143
389
  "count.summary": "共 {n} 条结果",
390
+ "count.partial": "已显示前 {m} 条",
391
+ "count.searching": "搜索中…",
144
392
  "state.loading": "正在读取插件目录…",
145
393
  "state.empty": "没有匹配的插件。换个关键词试试。",
146
394
  "state.failed": "读取失败",
@@ -156,7 +404,19 @@ window.__ModuleLoader__.load({
156
404
  "best.month": "{m} 期 · 每小类 2~3 个",
157
405
  "best.loading": "正在取当期榜单…",
158
406
  "best.empty": "当期榜单还没有数据(每月 1 日重算)",
159
- "footer.hint": "网页无法自动安装:复制命令到终端执行,装完重启 dsh 才会生效。命令里的 --profile web 不可省略。",
407
+ "sets.tab": "套装",
408
+ "sets.count": "{n} 套方案",
409
+ "sets.itemCount": "{n} 个插件",
410
+ "sets.loading": "正在取套装方案…",
411
+ "sets.empty": "暂时没有可用的套装方案",
412
+ "sets.batchHint": "按上面的顺序执行;命令里的 --profile 已按你本机填好。",
413
+ "sets.conflict": "注意",
414
+ "sets.synced": "{m} 期精选已核对 {s} 个跟随位",
415
+ "sets.detail": "看方案详情",
416
+ "need.required": "必备",
417
+ "need.enhance": "增强",
418
+ "need.optional": "可选",
419
+ "footer.hint": "网页无法自动安装:复制命令到终端执行,装完重启 dsh 才会生效。命令里的 --profile 已按你本机填好,别改成别的。",
160
420
  "telemetry.on": "匿名统计(不含搜索内容)",
161
421
  "install.action": "安装",
162
422
  "install.confirm": "确认安装?",
@@ -167,8 +427,17 @@ window.__ModuleLoader__.load({
167
427
  "install.okMarket": "已安装,无需重启",
168
428
  "install.okLocal": "已安装,重启 dsh 后生效",
169
429
  "install.restart": "立即重启",
430
+ "install.pendingTag": "待重启",
431
+ "install.pendingBody": "{n}:重启 dsh 后生效",
432
+ "install.effective": "已生效",
433
+ "install.effectiveBody": "{n}:改动已生效",
434
+ "install.dismiss": "知道了",
435
+ "install.restartFailed": "重启接口不可用,请手动重启 dsh",
170
436
  "install.failed": "安装失败",
171
437
  "install.busy": "已有安装任务在进行",
438
+ "install.busySince": "已有安装任务在进行(已 {n} 秒)—— 等它结束再试,或重启 dsh",
439
+ "install.timeout": "安装超时(3 分钟没有结束)—— 已停掉这次安装,可以重试",
440
+ "install.timeoutChanged": "安装超时,但版本已从 {from} 变成 {to} —— 多半是装上了,重启 dsh 后确认",
172
441
  "install.hint": "安装会在你的 dsh 里执行 dsh plugin add,来源为下方命令中的包名。",
173
442
  };
174
443
  const en = {
@@ -183,12 +452,188 @@ window.__ModuleLoader__.load({
183
452
  "action.copy": "Copy command",
184
453
  "action.copied": "Copied",
185
454
  "action.open": "Curated",
455
+ "action.show": "Show the panel",
186
456
  "action.close": "Collapse",
187
457
  "action.drag": "Drag to reposition",
188
458
  "action.hide": "Hide widget",
189
- "action.hideHint": "Reopen it from “Curated” at the bottom of the sidebar, or re-tick the toggle at the bottom of the Curated tab",
459
+ "action.hideHint": "Once closed it never comes back on its own, and a stray click will not bring it back: click the “Curated” sidebar button twice to restore (the second click does it), or re-tick the toggle at the bottom of the Curated tab / flip the switch in Settings → General",
460
+ "action.closedHint": "Closed — clicking here will not bring it back; re-enable it in the Curated tab footer or Settings → General",
461
+ "action.armRestore": "Click again to restore the widget",
462
+ "action.expand": "Expand panel",
190
463
  "action.showFloat": "Show the floating widget",
464
+ "settings.tab": "Curated",
465
+ "settings.title": "Curated plugins",
466
+ "settings.float": "Floating widget (bottom right)",
467
+ "settings.floatHint": "Once closed it never comes back on its own, and a stray click will not bring it back. To restore: click the “Curated” sidebar button twice (the second click does it), or re-tick the toggle at the bottom of the Curated tab.",
468
+ "settings.daily": "Daily pick",
469
+ "settings.dailyHint": "One plugin per day, rotated by calendar day (identical for everyone on a given day).",
470
+ "settings.check": "Check plugin updates automatically",
471
+ "settings.checkHint": "Asks the npm mirror for the latest version of every installed plugin when dsh opens (about 20 read-only requests per machine, at most once every 10 minutes). Turning it off stops the red dot; the manual \"Check for updates\" still works.",
472
+ "settings.telemetry": "Anonymous stats",
473
+ "settings.on": "On",
474
+ "settings.off": "Off",
475
+ "settings.reset": "Reset",
476
+ "settings.resetHint": "Clears the widget visibility, widget position and daily-pick preferences stored on this machine.",
477
+ "settings.resetDone": "Reset done.",
478
+ "settings.about": "These preferences live only on this machine (localStorage) and are never uploaded. The anonymous-stats switch is on this page too.",
479
+ "daily.tab": "Daily",
480
+ "daily.title": "Today's pick",
481
+ "daily.loading": "Loading today's pick…",
482
+ "daily.empty": "Today's pick is unavailable (catalogue data not ready)",
483
+ "daily.why": "Why this one",
484
+ "daily.hint": "Rotates at 00:00 (UTC+8); identical for everyone that day.",
485
+ "daily.expand": "Expand",
486
+ "daily.collapse": "Collapse",
487
+ "changelog.title": "Changelog",
488
+ "changelog.current": "Installed v{v}",
489
+ "changelog.loading": "Loading the changelog…",
490
+ "changelog.failed": "Could not read the changelog (local host not responding)",
491
+ "changelog.newAvailable": "v{v} available",
492
+ "changelog.upToDate": "Up to date",
493
+ "changelog.copyUpgrade": "Copy upgrade command",
494
+ "changelog.hint": "A restart is needed after upgrading; the profile in the command is already set to this machine's.",
495
+ "changelog.noItems": "No notes recorded for this version.",
496
+ "updates.tab": "My plugins",
497
+ "updates.title": "My plugins",
498
+ "updates.dot": "Update available",
499
+ "updates.check": "Check for updates",
500
+ "updates.checking": "Checking…",
501
+ "updates.self": "This plugin",
502
+ "updates.installed": "Installed plugins",
503
+ "updates.outdated": "Update available",
504
+ "updates.upToDate": "Up to date",
505
+ "updates.unknown": "Latest version unknown",
506
+ "updates.none": "Every installed plugin is up to date.",
507
+ "updates.summary": "Checked {n} plugins · {m} have updates",
508
+ "updates.unknownNote": "{k} more could not be resolved (usually local plugins never published to npm); no conclusion is drawn for them.",
509
+ "updates.copyCmd": "Copy command",
510
+ "updates.failed": "Update check failed",
511
+ "updates.loading": "Checking for updates…",
512
+ "updates.note": "Latest versions come from npmmirror; these are read-only requests and nothing is installed for you.",
513
+ "updates.remove": "Uninstall",
514
+ "updates.removeConfirm": "Confirm uninstall?",
515
+ "updates.removing": "Uninstalling…",
516
+ "updates.removed": "Uninstalled",
517
+ "updates.removedRestart": "Restart dsh to finish removing it",
518
+ "updates.nothingToRemove": "It was not installed",
519
+ "updates.ignore": "Ignore this version",
520
+ "updates.ignored": "Ignoring v{v}",
521
+ "updates.unignore": "Stop ignoring",
522
+ "updates.ignoreHint": "No nagging until v{v}",
523
+ "sets.installAll": "Install the whole set ({n})",
524
+ "sets.installAllConfirm": "Installs {n} plugins one by one (rewrites your profile, needs a dsh restart) — click again to start.",
525
+ "sets.installing": "Installing {done}/{total} · {name}",
526
+ "compare.pick": "Compare",
527
+ "compare.picked": "Picked",
528
+ "compare.toggle": "Add to comparison (up to {max})",
529
+ "compare.selected": "Picked {n}/{max}",
530
+ "compare.needTwo": "Pick at least 2 to compare",
531
+ "compare.show": "Compare",
532
+ "compare.hide": "Hide comparison",
533
+ "compare.clear": "Clear",
534
+ "compare.stars": "Stars",
535
+ "compare.verify": "Verified",
536
+ "compare.tested": "Hands-on tested",
537
+ "compare.verified": "Install-check passed",
538
+ "compare.unverified": "Unverified",
539
+ "compare.installed": "On this machine",
540
+ "compare.notInstalled": "Not installed",
541
+ "compare.cat": "Category",
542
+ "compare.sell": "Pitch",
543
+ "compare.install": "Install command",
544
+ "fav.toggle": "Save for later",
545
+ "fav.add": "Save",
546
+ "fav.added": "Saved",
547
+ "fav.title": "Saved for later",
548
+ "fav.count": "Saved for later ({n})",
549
+ "fav.hint": "Collect them first, install together later; stored on this machine only.",
550
+ "fav.remove": "Remove",
551
+ "fav.installAll": "Install all saved ({n})",
552
+ "fav.installConfirm": "Installs {n} saved plugins one by one (rewrites your profile, needs a dsh restart) — click again to start.",
553
+ "fav.empty": "Nothing saved yet. Hit “Save” on a card under Recommend to collect it here.",
554
+ "benefits.title": "Perks",
555
+ "benefits.body": "Free tiers and new-user credits across LLM platforms, hand-updated weekly.",
556
+ "updates.ackNote": "The dot clears once you open this page, and returns only when a newer version shows up.",
557
+ "updates.restartConfirm": "Restart dsh? The current session will be interrupted.",
558
+ "updates.upgrade": "Upgrade",
559
+ "updates.upgradeConfirm": "Upgrade to the latest version?",
560
+ "updates.upgradeHint": "This runs dsh plugin add <pkg>@latest against your profile; a restart is needed afterwards.",
561
+ "updates.upgradeAll": "Upgrade all ({n})",
562
+ "updates.upgradeAllHint": "Runs one at a time (the host allows a single install job) and can be stopped; items not reached keep their current state.",
563
+ "updates.upgradeAllConfirm": "This will upgrade {n} plugins one by one (it rewrites this machine's profile and needs a restart) — click again to start.",
564
+ "updates.batchProgress": "Upgrading {done}/{total} · {name}",
565
+ "updates.stop": "Stop",
566
+ "updates.batchDone": "Processed {done} · failed {failed}",
567
+ "updates.restartNeeded": "Some items were installed through the local CLI — restart dsh to activate them.",
568
+ "updates.blocked": "Incompatible with dsh",
569
+ "updates.blockedTitle": "dsh rejected this version",
570
+ "updates.blockedBody": "“{spec}” only declares compatibility with an earlier dsh, while this machine runs {dsh}. This is dsh's own guard (in its words: may cause crashes or data loss) — installing it needs an explicit exemption.",
571
+ "updates.blockedHow": "The exemption path is documented by dsh itself (dsh plugin allow-version, or the exact-version exemption in the plugin manager). This plugin will not grant it for you.",
572
+ "updates.releaseAge": "Supply-chain policy hold",
573
+ "updates.releaseAgeTitle": "A supply-chain policy paused this install",
574
+ "updates.releaseAgeBody": "pnpm refuses versions published less than 24 hours ago by default. Blocked this time ({n}): {list}.",
575
+ "updates.releaseAgeHow": "Two ways out: (1) wait — the newest entry becomes installable in about {h}h; (2) add these packages to minimumReleaseAgeExclude in your profile's pnpm-workspace.yaml (one rule per package — multiple name@version lines only the first one counts).",
576
+ "updates.copyRaw": "Copy dsh's own message",
577
+ "updates.batchBlocked": "({k} were stopped by dsh's compatibility gate)",
578
+ "updates.locals": "{n} more plugins are local links and are skipped",
579
+ "updates.localsNote": "Their version comes from local source, not npm; upgrading would install the npm build and replace your link — so no upgrade is offered here.",
580
+ "updates.pinned": "Pinned",
581
+ "updates.pinnedNote": "The manifest pins v{v}; plugin add will not move it — widen the range first.",
582
+ "updates.noChangeTitle": "dsh reported success, but nothing was installed",
583
+ "updates.noChange": "The installed version is still v{v} and dsh produced no output at all — the plugin may already be that version, or dsh's plugin add does not take effect for it.",
584
+ "updates.alreadyTitle": "This version is already installed",
585
+ "updates.alreadyHint": "Currently v{v} — nothing to reinstall.",
586
+ "card.installed": "Installed v{v}",
587
+ "install.reinstall": "Reinstall",
588
+ "install.reinstallConfirm": "Reinstall?",
589
+ "updates.batchNoop": "({k} reported success but kept the same version)",
590
+ "usage.summary": "Last {d} days: {a} core · {b} regular · {c} occasional · {e} consider-removing · {f} undetectable",
591
+ "usage.core": "Core",
592
+ "usage.common": "Regular",
593
+ "usage.occasional": "Occasional",
594
+ "usage.silent": "Consider removing",
595
+ "usage.disabled": "Disabled",
596
+ "usage.unmeasurable": "Undetectable",
597
+ "usage.unknown": "Usage data unavailable",
598
+ "usage.calls30d": "{n} calls in 30d",
599
+ "usage.stats": "{n} calls in 30d · last used {d}",
600
+ "usage.today": "today",
601
+ "usage.yesterday": "yesterday",
602
+ "usage.daysAgo": "{d} days ago",
603
+ "usage.silentNote": "No observed calls in the last 30 days",
604
+ "usage.unmeasurableNote": "This plugin produces no observable calls (passive) — keep or remove manually",
605
+ "usage.unknownNote": "Usage data is unavailable from this host",
606
+ "usage.keep": "Keep",
607
+ "usage.kept": "Kept",
608
+ "usage.keepHint": "Kept plugins are excluded from removal suggestions (stored locally only)",
609
+ "usage.onlySuggest": "Suggestions only",
610
+ "usage.sortUsage": "By usage",
611
+ "usage.sortUsageOn": "Default order",
612
+ "usage.noneSuggest": "Nothing flagged for removal (kept plugins are excluded).",
613
+ "usage.disable": "Disable",
614
+ "usage.enable": "Enable",
615
+ "usage.disableConfirm": "Confirm disable?",
616
+ "usage.enableConfirm": "Confirm enable?",
617
+ "usage.toggleHint": "Enable/disable applies to the live session immediately and is fully reversible (edits the local profile patch, not dependencies).",
618
+ "usage.toggling": "Working…",
619
+ "usage.disabledDone": "Disabled",
620
+ "usage.enabledDone": "Enabled",
621
+ "usage.toggleFailed": "Failed",
622
+ "usage.toggleOverridden": "Not applied (overridden by a higher-priority layer)",
623
+ "usage.toggleSelf": "Cannot disable the hub itself",
624
+ "usage.toggleReadonly": "This row is managed by dsh and cannot be toggled here",
625
+ "usage.toggleUnaddressable": "This row cannot be addressed (refresh and retry)",
626
+ "usage.toggleUnsupported": "This host does not support enable/disable (needs a newer dsh)",
627
+ "usage.batchDisable": "Disable all ({n})",
628
+ "usage.batchConfirm": "Disable {n} enabled candidates one by one (fully reversible) — click again to start.",
629
+ "usage.batchProgress": "Disabling {done}/{total} · {name}",
630
+ "usage.batchDone": "Disabled {done} · failed {failed}",
631
+ "usage.batchHint": "Only enabled candidates are handled; uninstall disabled ones individually",
632
+ "host.stale": "This build of the local host does not serve that route yet — usually dsh has not been restarted. Restart dsh and try again.",
633
+ "host.skew": "The local host process is older than this UI: this page needs newer response fields (a restart fixes it).",
191
634
  "count.summary": "{n} results",
635
+ "count.partial": "showing the first {m}",
636
+ "count.searching": "searching…",
192
637
  "state.loading": "Loading the catalog…",
193
638
  "state.empty": "No matching plugin. Try another keyword.",
194
639
  "state.failed": "Failed to load",
@@ -204,7 +649,19 @@ window.__ModuleLoader__.load({
204
649
  "best.month": "{m} · 2-3 per group",
205
650
  "best.loading": "Loading this month's picks…",
206
651
  "best.empty": "No picks for the current month yet (recomputed on the 1st)",
207
- "footer.hint": "A web page cannot install plugins: copy the command into a terminal, then restart dsh. The --profile web flag is mandatory.",
652
+ "sets.tab": "Setups",
653
+ "sets.count": "{n} setups",
654
+ "sets.itemCount": "{n} plugins",
655
+ "sets.loading": "Loading setups…",
656
+ "sets.empty": "No setups available yet",
657
+ "sets.batchHint": "Run them in this order; the --profile is already filled for your machine.",
658
+ "sets.conflict": "Note",
659
+ "sets.synced": "Checked against {m} picks ({s} rolling slots)",
660
+ "sets.detail": "View on site",
661
+ "need.required": "Core",
662
+ "need.enhance": "Enhance",
663
+ "need.optional": "Optional",
664
+ "footer.hint": "A web page cannot install plugins: copy the command into a terminal, then restart dsh. The --profile in it is already set to this machine's — leave it as is.",
208
665
  "telemetry.on": "Anonymous stats (no search text)",
209
666
  "install.action": "Install",
210
667
  "install.confirm": "Confirm install?",
@@ -215,8 +672,17 @@ window.__ModuleLoader__.load({
215
672
  "install.okMarket": "Installed, no restart needed",
216
673
  "install.okLocal": "Installed — restart dsh to activate",
217
674
  "install.restart": "Restart now",
675
+ "install.pendingTag": "Restart needed",
676
+ "install.pendingBody": "{n}: restart dsh to apply",
677
+ "install.effective": "Active",
678
+ "install.effectiveBody": "{n}: changes are live",
679
+ "install.dismiss": "Got it",
680
+ "install.restartFailed": "Restart endpoint unavailable — restart dsh manually",
218
681
  "install.failed": "Install failed",
219
682
  "install.busy": "Another install is already running",
683
+ "install.busySince": "Another install is already running ({n}s) — wait for it to finish, or restart dsh",
684
+ "install.timeout": "Install timed out (no result in 3 minutes) — this run was stopped, retry when ready",
685
+ "install.timeoutChanged": "Install timed out, but the version changed {from} → {to} — it most likely landed; confirm after restarting dsh",
220
686
  "install.hint": "Install runs dsh plugin add inside your dsh, using the package name in the command below.",
221
687
  };
222
688
 
@@ -318,12 +784,20 @@ window.__ModuleLoader__.load({
318
784
  ① 复用已装的 dshmarket 的同源 HTTP 路由(免重启热挂载、可回滚);
319
785
  它只接受自己 curated registry(awesome 目录)里的 url,不在其中会返回 400;
320
786
  ② 降级到本插件 host 路由,直接 spawn `dsh plugin add`(改 profile,需重启生效)。
321
- 已在运行 agent 时 dshmarket 会返回 409 —— 这种情况不降级,避免把插件文件写坏。 */
787
+ 已在运行 agent 时 dshmarket 会返回 409 —— **只有这一种不降级**。
788
+ 其余一切「市场通道给不出确定答复」的状态都必须降级:dshmarket 缺失、被 dsh 判定
789
+ 与本机核心不兼容而整包跳过、或正在升级时,/dsh-market/* 会整体缺席,POST 命不中
790
+ 任何具名路由,于是落到 dsh 静态前端的 fallback —— 它对非 GET/HEAD 一律回**空体 405**。
791
+ 把这种 405 当硬失败,会让一键安装在市场通道不可用时直接报错,而旁边明明有一条
792
+ 可用的本地通道(桌面版 dsh 0.2.0-rc.2 跳过 dshmarket 1.65.1 时即如此)。 */
322
793
  const MARKET_INSTALL = "/dsh-market/install";
323
794
  const MARKET_STATUS = "/dsh-market/status";
324
795
  const LOCAL_INSTALL = "/api/dpharness/install";
325
796
  const INSTALL_POLL_MS = 1200;
326
797
  const INSTALL_MAX_MS = 5 * 60 * 1000;
798
+ /* 对比上限:面板宽 400px,第 4 列已经挤到读不下去;页签更宽,但同一份数据两处渲染,
799
+ 口径必须一致(不能浮窗 3 列、页签 4 列)。 */
800
+ const COMPARE_MAX = 3;
327
801
 
328
802
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
329
803
 
@@ -346,6 +820,61 @@ window.__ModuleLoader__.load({
346
820
 
347
821
  const getJson = (url) => requestJson(url, { cache: "no-store" });
348
822
 
823
+ /**
824
+ * 读一个**本机 host 路由**的 JSON 响应(四个取数 hook 共用)。
825
+ *
826
+ * ⚠️ 必须容忍「响应体不是 JSON」,这不是防御性编程,是实测踩到的坑:
827
+ * 客户端代码刷新页面即生效,而 host 的路由要**重启 dsh** 才会注册 ——
828
+ * 这个窗口期里请求会落到 dsh 静态前端的兜底上,返回纯文本
829
+ * (实测桌面版返回 `not found`、无凭据时 `unauthorized`)。
830
+ * 直接 response.json() 会把 JSON 解析错误当成业务错误抛给用户:
831
+ * 「Unexpected token 'o', "not found" is not valid JSON」
832
+ * —— 这句话对用户毫无意义,而真实原因(host 进程是旧的)被彻底掩盖。
833
+ * 所以这里是「先取文本、再尝试解析」,解析失败一律标成 stale(句柄失效),
834
+ * 由调用方翻成一句可操作的话。
835
+ */
836
+ /**
837
+ * 本 UI **期望**的宿主负载形状版本,必须与 host 侧 index.js 的 SHAPE_REV 一致。
838
+ * 两个半边同包但不同运行时(一个在 Node、一个在浏览器),没法 import,
839
+ * 只能各写一份 —— test-local.mjs 双向断言两者相等,改一处忘另一处会当场变红。
840
+ */
841
+ const HOST_SHAPE_REV = 4;
842
+
843
+ /**
844
+ * 宿主进程比客户端旧?
845
+ *
846
+ * desktop profile 里本插件是**指向工作区的符号链接**:客户端刷新页面即生效,
847
+ * 而宿主的路由与字段要**重启 dsh** 才会更新。这个窗口期里界面会缺字段
848
+ * (例如「更新」视图拿不到中文名)—— 实测已因此误导过两次,
849
+ * 所以要显式说出来,否则用户只会觉得"功能坏了"。
850
+ *
851
+ * 只判「宿主更旧」:宿主更新而客户端旧时,多出来的字段不影响渲染,不必打扰用户。
852
+ */
853
+ function isHostSkewed(body) {
854
+ return Boolean(body) && typeof body.rev === "number" && body.rev < HOST_SHAPE_REV;
855
+ }
856
+
857
+ async function readHostJson(url, signal) {
858
+ const response = await fetch(url, { cache: "no-store", signal: signal });
859
+ const text = await response.text();
860
+ let body = null;
861
+ try {
862
+ body = text ? JSON.parse(text) : null;
863
+ } catch (error) {
864
+ body = null;
865
+ }
866
+ if (body === null) {
867
+ const error = new Error("host route unavailable (HTTP " + response.status + " " + String(text || "").trim().slice(0, 40) + ")");
868
+ /* stale = 这条路压根没注册,而不是服务端报了一个业务错 */
869
+ error.stale = true;
870
+ throw error;
871
+ }
872
+ if (!response.ok || body.ok !== true) {
873
+ throw new Error((body && body.error) || ("HTTP " + response.status));
874
+ }
875
+ return body;
876
+ }
877
+
349
878
  function messageOf(result, fallback) {
350
879
  const data = result && result.data;
351
880
  if (data && typeof data.error === "string" && data.error) return data.error.slice(0, 200);
@@ -375,74 +904,349 @@ window.__ModuleLoader__.load({
375
904
  const job = status.data && status.data.job;
376
905
  if (status.status !== 200 || !job) return { ok: false, via: "local", why: "poll_unreachable", message: messageOf(status, "install status unavailable") };
377
906
  if (job.active === false) {
378
- if (job.code === 0) return { ok: true, market: false };
379
- return { ok: false, via: "local", why: job.error === "timeout" ? "timeout" : "cli_exit", message: String(job.error || job.tail || ("exit code " + job.code)).slice(0, 200) };
907
+ if (job.code === 0) return { ok: true, market: false, changed: job.changed };
908
+ if (job.why === "incompatible") {
909
+ /* dsh 自带的兼容性闸门拒绝 —— 与"安装出错"是两回事:
910
+ 它是**预期结果**,界面要给出原因与放行通道,而不是一句失败。 */
911
+ return {
912
+ ok: false,
913
+ via: "local",
914
+ why: "incompatible",
915
+ reject: job.reject || null,
916
+ message: String(job.error || "incompatible").slice(0, 200),
917
+ };
918
+ }
919
+ /* 供应链策略拒绝(pnpm 内置 24 小时最小发布年龄)—— 与"安装出错"是两回事:
920
+ 它是**预期结果**,界面要给出条目、等待时间与通路。条目在 host 侧已解析好。 */
921
+ if (job.why === "release-age") {
922
+ const aged = job.reject || { count: 0, entries: [] };
923
+ const list = (Array.isArray(aged.entries) ? aged.entries : [])
924
+ .slice(0, 3)
925
+ .map((entry) => entry.name + "@" + entry.version)
926
+ .join("、");
927
+ return {
928
+ ok: false,
929
+ via: "local",
930
+ why: "release-age",
931
+ reject: aged,
932
+ message: format(t("updates.releaseAgeBody"), { n: aged.count || 0, list: list }),
933
+ };
934
+ }
935
+ /* 超时是**唯一**会在"其实已经落盘"的情况下报失败的路径:宿主超时解锁时
936
+ 会补读一次磁盘(见 host forceUnlock),这里就把它读到的版本变化说出来。
937
+ 否则用户看到"失败"会重装一遍,而它早就装上了
938
+ (2026-10-14 实测 4.4.2 → 4.4.3 已落盘,界面却报失败)。 */
939
+ if (job.error === "timeout") {
940
+ return {
941
+ ok: false,
942
+ via: "local",
943
+ why: "timeout",
944
+ message: job.outcome === "changed"
945
+ ? format(t("install.timeoutChanged"), { from: String(job.before || "?"), to: String(job.after || "?") })
946
+ : t("install.timeout"),
947
+ };
948
+ }
949
+ return { ok: false, via: "local", why: "cli_exit", message: String(job.error || job.tail || ("exit code " + job.code)).slice(0, 200) };
380
950
  }
381
951
  }
382
952
  return { ok: false, via: "local", why: "timeout", message: "timeout" };
383
953
  }
384
954
 
385
- async function runInstall(item, t) {
955
+ /**
956
+ * 安装与升级共用同一条执行路径,但**事件名必须分开**:
957
+ * 「装一个新插件」(发现)与「把已装的升到最新」(维护)是两种完全不同的行为,
958
+ * 混成一个数会让两边都读不出结论(一个涨了,你不知道是新用户在装还是老用户在升)。
959
+ * 这里只放动作名,调用点保持逐字可检索。
960
+ */
961
+ const INSTALL_EVENTS = { start: "install", okMarket: "installed_market", okLocal: "installed_local", fail: "install_failed" };
962
+ const UPGRADE_EVENTS = { start: "upgrade", okMarket: "upgrade_done_market", okLocal: "upgrade_done", fail: "upgrade_failed" };
963
+
964
+ /**
965
+ * 目标包名(去掉 @latest / @版本 后缀)。
966
+ *
967
+ * 安装回执要拿它去 profile 清单里查,而 `dependencies` 的键是**裸包名** ——
968
+ * 带着 `@latest` 去查会永远查不到,把「已装上」记成「没装上」。
969
+ * scoped 包(@scope/name)不含版本时原样返回。
970
+ */
971
+ function basePackage(target) {
972
+ const value = String(target || "");
973
+ const matched = /^(.*?)@[^@/]+$/.exec(value);
974
+ return matched ? matched[1] : value;
975
+ }
976
+
977
+ /**
978
+ * 安装任务的唯一写入口。
979
+ *
980
+ * why / reject 每次都显式给默认值:它们是上一轮的残留最容易被带出去的地方
981
+ * (上一个任务被兼容性闸门拒过,下一个任务的失败就会顶着别人的原因显示)。
982
+ */
983
+ function setInstallJob(job) {
984
+ setHub({ install: Object.assign({ why: "", reject: null, verb: "add" }, job) });
985
+ }
986
+
987
+ async function runInstall(item, t, kind) {
386
988
  const target = item.pkg;
387
- if (!target) return;
989
+ if (!target) return { ok: false, via: "none", why: "no_target" };
990
+ const ev = kind === "upgrade" ? UPGRADE_EVENTS : INSTALL_EVENTS;
388
991
  const deadline = Date.now() + INSTALL_MAX_MS;
389
- setHub({ install: { active: true, target, phase: "market", message: t("install.market") } });
390
- track("plugin_hub", { action: "install" });
992
+ setInstallJob({ active: true, target, phase: "market", message: t("install.market") });
993
+ track("plugin_hub", { action: ev.start });
391
994
 
392
995
  let done = null;
393
996
  if (item.url) {
394
997
  const market = await postJson(MARKET_INSTALL, { url: item.url });
395
998
  if (market.status === 200) {
396
999
  done = await pollMarketInstall(deadline);
397
- } else if (market.status === 400 || market.status === 404 || market.status === 0) {
398
- /* 不在 dshmarket 的 curated registry 里 —— 这是预期路径,降级到本地 CLI,
399
- 不是失败,所以这里不埋点。 */
400
- done = null;
1000
+ } else if (market.status === 409) {
1001
+ /* 有 agent 正在跑,dshmarket 拒绝抢插件文件 —— 唯一不降级的情况:
1002
+ 降级路径同样要写插件文件,此刻写下去一样会把工作中的 agent 写崩。 */
1003
+ track("plugin_hub", { action: ev.fail, via: "market", why: "busy" });
1004
+ setInstallJob({ active: false, target, phase: "failed", message: messageOf(market, t("install.failed")) });
1005
+ return { ok: false, via: "market", why: "busy" };
401
1006
  } else {
402
- /* 409 = 有 agent 正在跑,dshmarket 拒绝抢插件文件。它和别的 HTTP 错误
403
- 处理方式相同(都不降级),但原因完全不同,必须分开统计。 */
404
- const why = market.status === 409 ? "busy" : "market_http";
405
- track("plugin_hub", { action: "install_failed", via: "market", why });
406
- setHub({ install: { active: false, target, phase: "failed", message: messageOf(market, t("install.failed")) } });
407
- return;
1007
+ done = null;
1008
+ /* 400/404/0 是预期拒绝(不在 curated registry / 通道不在 / 网络异常),
1009
+ 静默降级。其余状态码说明**市场通道本身不可用**,要留痕,否则看板上
1010
+ 「市场通道缺席」这件事完全不可见(它只会表现为降级后的成功率偏低)。 */
1011
+ if (market.status !== 400 && market.status !== 404 && market.status !== 0) {
1012
+ track("plugin_hub", {
1013
+ action: "market_unavailable",
1014
+ via: "market",
1015
+ why: market.status === 0 ? "network" : "http_" + market.status,
1016
+ });
1017
+ }
408
1018
  }
409
1019
  }
410
1020
  if (done === null) {
411
- setHub({ install: { active: true, target, phase: "local", message: t("install.local") } });
1021
+ setInstallJob({ active: true, target, phase: "local", message: t("install.local") });
412
1022
  const local = await postJson(LOCAL_INSTALL, { pkg: target });
413
1023
  if (local.status !== 202) {
414
- track("plugin_hub", {
415
- action: "install_failed",
416
- via: "local",
417
- why: local.status === 409 ? "busy" : "local_rejected",
1024
+ const why = local.status === 409 ? "busy" : "local_rejected";
1025
+ track("plugin_hub", { action: ev.fail, via: "local", why: why });
1026
+ /* 409 = 宿主里已有一个安装任务。它的原文是英文("an install is already
1027
+ running"),直接摊在卡片上等于没解释 —— 改成按 why 出中文,并带上
1028
+ 已经跑了多少秒,用户至少知道该等它还是该重启。
1029
+ 宿主侧另有一层自愈:明显超时没收尾的任务会被自动解锁(见 forceUnlock),
1030
+ 所以这里的 409 只会表示"真的有一个健康的任务在跑"。 */
1031
+ const busySeconds = why === "busy" && local.data && Number(local.data.seconds) > 0
1032
+ ? Math.round(Number(local.data.seconds))
1033
+ : 0;
1034
+ setInstallJob({
1035
+ active: false,
1036
+ target,
1037
+ phase: "failed",
1038
+ message: why === "busy"
1039
+ ? format(t("install.busySince"), { n: busySeconds })
1040
+ : messageOf(local, t("install.failed")),
418
1041
  });
419
- setHub({ install: { active: false, target, phase: "failed", message: messageOf(local, t("install.failed")) } });
420
- return;
1042
+ return { ok: false, via: "local", why: why };
421
1043
  }
422
1044
  done = await pollLocalInstall(deadline);
1045
+ /* 偶发失败**重试一次**(只一次,不是循环):
1046
+ 实测(2026-10-12)同一台机器、同一条命令,紧挨着的多次操作会抢同一个
1047
+ pnpm-lock.yaml 而报 `Command failed with exit code 1`(dsh 只记命令行、
1048
+ 不记 pnpm 输出),隔几分钟单独跑一次就成功。
1049
+ 重试是幂等的(`pnpm add 同一个版本`),且宿主侧本来就是单飞(并发会 409)。 */
1050
+ if (!done.ok && done.why === "cli_exit") {
1051
+ track("plugin_hub", { action: ev.fail, via: "local", why: "retry" });
1052
+ setInstallJob({ active: true, target, phase: "local", message: t("install.local") });
1053
+ const again = await postJson(LOCAL_INSTALL, { pkg: target });
1054
+ if (again.status === 202) done = await pollLocalInstall(deadline);
1055
+ }
423
1056
  }
424
- setHub({
425
- install: {
426
- active: false,
427
- target,
428
- phase: done.ok ? (done.market ? "okMarket" : "okLocal") : "failed",
429
- message: done.ok ? t(done.market ? "install.okMarket" : "install.okLocal") : done.message,
430
- },
1057
+ setInstallJob({
1058
+ active: false,
1059
+ target,
1060
+ phase: done.ok ? (done.market ? "okMarket" : "okLocal") : "failed",
1061
+ message: done.ok ? t(done.market ? "install.okMarket" : "install.okLocal") : done.message,
1062
+ why: done.ok ? "" : (done.why || ""),
1063
+ reject: done.ok ? null : (done.reject || null),
431
1064
  });
1065
+ /* 装完就重取一次清单:否则行上还是旧版本号,用户会判定"升级没成功"
1066
+ (host 在安装成功时会作废它自己的缓存,所以这次 refresh 拿得到新结果)。 */
1067
+ loadUpdates(true);
432
1068
  if (done.ok) {
433
1069
  const via = done.market ? "market" : "local";
434
- track("plugin_hub", { action: done.market ? "installed_market" : "installed_local" });
1070
+ track("plugin_hub", { action: done.market ? ev.okMarket : ev.okLocal });
435
1071
  /* 留一张凭据给下一次加载。安装成功这一刻没有任何东西能验证结果:
436
1072
  热挂载路径没有重启,本地 CLI 路径要等重启才生效 —— 两者都只能在
437
1073
  「插件再次被加载」时由 host 回查(见 reportPostInstall)。 */
438
- rememberPending({ pkg: target, via: via, at: Date.now() });
439
- } else {
440
- track("plugin_hub", {
441
- action: "install_failed",
442
- via: done.via || "local",
443
- why: done.why || "unknown",
1074
+ rememberPending({ pkg: basePackage(target), via: via, at: Date.now() });
1075
+ /* 本地通道改的是 profile,必须重启才生效 —— 记一条待重启横幅(市场通道热挂载,
1076
+ 不需要;same/none 版本没动,也没什么可生效的)。 */
1077
+ if (!done.market && done.changed) markRestartPending(item.nameZh || item.name || target);
1078
+ return { ok: true, market: Boolean(done.market), via: via, why: "", changed: done.changed };
1079
+ }
1080
+ track("plugin_hub", {
1081
+ action: ev.fail,
1082
+ via: done.via || "local",
1083
+ why: done.why || "unknown",
1084
+ });
1085
+ /* 被 dsh 的兼容性闸门拒过就记住它 —— 下次不再让用户白点一次 */
1086
+ if (done.why === "incompatible" && done.reject && done.reject.spec) rememberBlocked(done.reject.spec);
1087
+ return { ok: false, via: done.via || "local", why: done.why || "unknown", reject: done.reject || null };
1088
+ }
1089
+
1090
+ /**
1091
+ * 卸载 —— 与安装共用同一条本地通道(宿主同一个 job、同一套轮询与脱敏),
1092
+ * 只把 verb 换成 remove。刻意**没有市场通道**:dshmarket 只负责装,卸只能改 profile。
1093
+ *
1094
+ * 卸载同样要重启才彻底(当前进程里插件还挂着),所以成功之后与安装走同一条
1095
+ * 待重启横幅 —— 不另造一套提醒(横幅文案已改成动词中性,装卸都说得通)。
1096
+ */
1097
+ async function runRemove(item, t) {
1098
+ const target = item.pkg;
1099
+ if (!target) return { ok: false, why: "no_target" };
1100
+ const deadline = Date.now() + INSTALL_MAX_MS;
1101
+ setInstallJob({ active: true, verb: "remove", target, phase: "local", message: t("updates.removing") });
1102
+ track("plugin_hub", { action: "remove_start" });
1103
+ const local = await postJson(LOCAL_INSTALL, { pkg: target, verb: "remove" });
1104
+ if (local.status !== 202) {
1105
+ const why = local.status === 409 ? "busy" : "local_rejected";
1106
+ track("plugin_hub", { action: "remove_failed", why: why });
1107
+ /* 与安装同一条通道、同一份 busy 口径(英文原文不出现在界面上) */
1108
+ const busySeconds = why === "busy" && local.data && Number(local.data.seconds) > 0
1109
+ ? Math.round(Number(local.data.seconds))
1110
+ : 0;
1111
+ setInstallJob({
1112
+ active: false,
1113
+ verb: "remove",
1114
+ target,
1115
+ phase: "failed",
1116
+ message: why === "busy"
1117
+ ? format(t("install.busySince"), { n: busySeconds })
1118
+ : messageOf(local, t("install.failed")),
444
1119
  });
1120
+ return { ok: false, changed: false, why: why };
1121
+ }
1122
+ const done = await pollLocalInstall(deadline);
1123
+ setInstallJob({
1124
+ active: false,
1125
+ verb: "remove",
1126
+ target,
1127
+ phase: done.ok ? "okLocal" : "failed",
1128
+ message: done.ok ? t("updates.removed") : done.message,
1129
+ why: done.ok ? "" : (done.why || ""),
1130
+ });
1131
+ /* 装/卸都会改 profile 清单:装完要立刻看到「已安装 vX」消失,所以同样重取 */
1132
+ loadUpdates(true);
1133
+ if (done.ok && done.changed) {
1134
+ track("plugin_hub", { action: "remove_ok" });
1135
+ markRestartPending(item.nameZh || item.name || target);
1136
+ } else if (done.ok) {
1137
+ /* 退出码 0 但磁盘上没变 —— 与安装的 same 同一类三态,别谎报"已卸载" */
1138
+ track("plugin_hub", { action: "remove_noop" });
1139
+ } else {
1140
+ track("plugin_hub", { action: "remove_failed", why: done.why || "unknown" });
1141
+ }
1142
+ return { ok: Boolean(done.ok), changed: Boolean(done.changed), why: done.why || "" };
1143
+ }
1144
+
1145
+ /**
1146
+ * 批量升级。
1147
+ *
1148
+ * ⚠️ **必须串行**:宿主同一时刻只允许一个安装任务(第二个请求直接 409),
1149
+ * 并发只会让大部分条目拿到 busy。
1150
+ * 可中止:每轮开始前看一次标记;中止后剩余条目保持原状(仍是「可升级」),不做任何事 ——
1151
+ * 半途而废也只是"少升了几个",不会留下损坏状态。
1152
+ */
1153
+ async function runUpgradeAll(items, t) {
1154
+ const total = items.length;
1155
+ setHub({ batch: { active: true, total: total, finished: 0, failed: 0, blocked: 0, noop: 0, current: items[0] ? items[0].name : "", stopRequested: false, restartNeeded: false } });
1156
+ let failed = 0;
1157
+ let blocked = 0;
1158
+ let noop = 0;
1159
+ let restartNeeded = false;
1160
+ let finished = 0;
1161
+ for (let index = 0; index < items.length; index += 1) {
1162
+ if (hub.batch && hub.batch.stopRequested) break;
1163
+ setHub({ batch: { ...hub.batch, current: items[index].name } });
1164
+ const result = await runInstall({ pkg: items[index].pkg, name: items[index].name, nameZh: items[index].nameZh }, t, "upgrade");
1165
+ finished += 1;
1166
+ if (!result.ok) {
1167
+ failed += 1;
1168
+ /* 被 dsh 兼容性闸门拦下的要单独计数:它和"真失败"的处置完全不同 */
1169
+ if (result.why === "incompatible") blocked += 1;
1170
+ } else if (result.changed === false) {
1171
+ /* dsh 报成功但版本没变(静默空转)—— 这既不是成功也不是失败,单独计 */
1172
+ noop += 1;
1173
+ } else if (result.via === "local") {
1174
+ restartNeeded = true;
1175
+ }
1176
+ setHub({ batch: { ...hub.batch, finished: finished, failed: failed, blocked: blocked, noop: noop, restartNeeded: restartNeeded } });
1177
+ }
1178
+ setHub({ batch: { ...hub.batch, active: false, current: "" } });
1179
+ /* 批量结束再重取一次清单(逐个重取会把 13 次检查打成 13 轮请求) */
1180
+ loadUpdates(true);
1181
+ track("plugin_hub", {
1182
+ action: "upgrade_all_done",
1183
+ n: finished,
1184
+ scope: hub.batch && hub.batch.stopRequested ? "stopped" : "full",
1185
+ why: blocked > 0 ? "blocked" : noop > 0 ? "noop" : failed > 0 ? "partial" : "ok",
1186
+ });
1187
+ }
1188
+
1189
+ /**
1190
+ * 一键安装整套。
1191
+ *
1192
+ * 复用批量升级那台机器(串行 / 总进度 / 可中止 / 同一份失败分类),只换来源 ——
1193
+ * 宿主同一时刻只允许一个安装任务(并发只会拿到 409),所以"整套安装"必须是
1194
+ * 同一个循环换一个数据源,而不是另写一套并发。
1195
+ *
1196
+ * 已经装上的条目会走到 `changed === false`(本来就是目标版本)→ 计 noop,
1197
+ * **不是失败**(与单条安装同一个三态口径)。
1198
+ * 装完的待重启提醒由 runInstall 自己记(本地通道才记),这里不重复。
1199
+ */
1200
+ async function runSetInstall(set, t) {
1201
+ const items = (Array.isArray(set.items) ? set.items : []).filter((item) => item.pkg);
1202
+ const total = items.length;
1203
+ if (total === 0) return;
1204
+ const labelOf = (item) => item.nameZh || item.name || item.pkg;
1205
+ setHub({ batch: {
1206
+ active: true,
1207
+ kind: "install",
1208
+ scope: "set",
1209
+ slug: set.slug || "",
1210
+ setName: set.name || "",
1211
+ total: total,
1212
+ finished: 0,
1213
+ failed: 0,
1214
+ blocked: 0,
1215
+ noop: 0,
1216
+ current: labelOf(items[0]),
1217
+ stopRequested: false,
1218
+ restartNeeded: false,
1219
+ } });
1220
+ track("plugin_hub", { action: "set_install_start", slug: set.slug || "", n: total });
1221
+ let failed = 0;
1222
+ let blocked = 0;
1223
+ let noop = 0;
1224
+ let restartNeeded = false;
1225
+ let finished = 0;
1226
+ for (let index = 0; index < items.length; index += 1) {
1227
+ if (hub.batch && hub.batch.stopRequested) break;
1228
+ setHub({ batch: { ...hub.batch, current: labelOf(items[index]) } });
1229
+ const result = await runInstall({ pkg: items[index].pkg, name: items[index].name, nameZh: items[index].nameZh }, t, "catalog");
1230
+ finished += 1;
1231
+ if (!result.ok) {
1232
+ failed += 1;
1233
+ if (result.why === "incompatible") blocked += 1;
1234
+ } else if (result.changed === false) {
1235
+ noop += 1;
1236
+ } else if (result.via === "local") {
1237
+ restartNeeded = true;
1238
+ }
1239
+ setHub({ batch: { ...hub.batch, finished: finished, failed: failed, blocked: blocked, noop: noop, restartNeeded: restartNeeded } });
445
1240
  }
1241
+ setHub({ batch: { ...hub.batch, active: false, current: "" } });
1242
+ loadUpdates(true);
1243
+ track("plugin_hub", {
1244
+ action: "set_install_done",
1245
+ slug: set.slug || "",
1246
+ n: finished,
1247
+ scope: hub.batch && hub.batch.stopRequested ? "stopped" : "full",
1248
+ why: blocked > 0 ? "blocked" : noop > 0 ? "noop" : failed > 0 ? "partial" : "ok",
1249
+ });
446
1250
  }
447
1251
 
448
1252
  /** 仅在降级路径(改了 profile)后需要;/api/restart 由 dsh-restart 插件提供(POST)。 */
@@ -468,12 +1272,244 @@ window.__ModuleLoader__.load({
468
1272
  }
469
1273
  }
470
1274
 
471
- /* 三个入口共享的轻量 store;不依赖 dsh 内部 store,避免猜测未验证的 API。 */
472
- const hub = { open: false, hidden: hubHidden, telemetry: telemetryOn, install: null, listeners: new Set() };
1275
+ /* 「每日推荐」开关。默认开 —— 它是这屏里唯一一条「今天该装哪个」的答案,
1276
+ 关掉只是不想看,不该是新用户的默认状态。 */
1277
+ const DAILY_KEY = "dph-hub-daily";
1278
+ let dailyOn = true;
1279
+ try {
1280
+ dailyOn = localStorage.getItem(DAILY_KEY) !== "0";
1281
+ } catch (error) {
1282
+ /* localStorage 不可用时按默认(开)处理 */
1283
+ }
1284
+ function storeDaily(value) {
1285
+ try {
1286
+ localStorage.setItem(DAILY_KEY, value ? "1" : "0");
1287
+ } catch (error) {
1288
+ /* 隐私模式下不持久化,本次会话内仍然可关 */
1289
+ }
1290
+ }
1291
+
1292
+ /* 四个入口共享的轻量 store;不依赖 dsh 内部 store,避免猜测未验证的 API。 */
1293
+ /**
1294
+ * 「自动检查插件更新」的开关(默认开)。
1295
+ *
1296
+ * 有真实用户之后才想清楚:自动检查会让**每台用户的机器**在每次打开 dsh 时
1297
+ * 向 npm 镜像发约 20 个只读请求 —— 这是"未经同意就产生的出网行为"。
1298
+ * 声明写在 README 里没用(用户不会去读),所以给出可关的开关,并明确写下量级。
1299
+ * 关掉后:不自动查、红点不再提醒;**手动「检查更新」仍然可用**。
1300
+ */
1301
+ const AUTO_CHECK_KEY = "dph-hub-auto-check";
1302
+ function readAutoCheck() {
1303
+ try {
1304
+ return localStorage.getItem(AUTO_CHECK_KEY) !== "0";
1305
+ } catch (error) {
1306
+ return true;
1307
+ }
1308
+ }
1309
+
1310
+ /* 「收藏待装」 —— 本机偏好(localStorage):先攒着,之后一起装。
1311
+ 存的是**条目快照**(只留渲染与安装需要的字段),不是包名引用 ——
1312
+ 站点目录会变,包名回头可能查不到,快照至少让这一条还显示得出来、还装得上。
1313
+ 与「对比」刻意不同:对比是一次性动作(不持久),收藏是**跨会话的意图**。 */
1314
+ const FAV_KEY = "dph-hub-fav";
1315
+ const FAV_FIELDS = ["fullName", "pkg", "name", "nameZh", "sell", "cat", "stars", "cmd"];
1316
+ function readFav() {
1317
+ try {
1318
+ const raw = localStorage.getItem(FAV_KEY);
1319
+ if (!raw) return [];
1320
+ const parsed = JSON.parse(raw);
1321
+ if (!Array.isArray(parsed)) return [];
1322
+ return parsed
1323
+ .filter((entry) => entry && typeof entry === "object" && (entry.fullName || entry.pkg))
1324
+ .slice(0, 100)
1325
+ .map((entry) => {
1326
+ const snapshot = {};
1327
+ FAV_FIELDS.forEach((field) => { if (entry[field] !== undefined) snapshot[field] = entry[field]; });
1328
+ return snapshot;
1329
+ });
1330
+ } catch (error) {
1331
+ return [];
1332
+ }
1333
+ }
1334
+ function storeFav(value) {
1335
+ try {
1336
+ localStorage.setItem(FAV_KEY, JSON.stringify(value));
1337
+ } catch (error) {
1338
+ /* 隐私模式下不持久化:本次会话内仍然有效 */
1339
+ }
1340
+ }
1341
+
1342
+ /* 「忽略此版本」 —— 本机偏好(localStorage):某包升到某个版本之前不再提醒。
1343
+ 与 acked(看过即消)刻意不同:acked 记的是"我看过了",这是"我不打算升这一版",
1344
+ 所以它必须持久、且红点与列表都要认它。存的是**目标版本**而不是布尔 ——
1345
+ 等真出了更新的版本(latest 变了),提醒应当自己回来。 */
1346
+ const IGNORE_KEY = "dph-hub-ignore";
1347
+ function readIgnore() {
1348
+ try {
1349
+ const raw = localStorage.getItem(IGNORE_KEY);
1350
+ if (!raw) return {};
1351
+ const parsed = JSON.parse(raw);
1352
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
1353
+ const map = {};
1354
+ Object.keys(parsed).forEach((pkg) => {
1355
+ const version = parsed[pkg];
1356
+ if (typeof version === "string" && version) map[pkg] = version;
1357
+ });
1358
+ return map;
1359
+ } catch (error) {
1360
+ return {};
1361
+ }
1362
+ }
1363
+ function storeIgnore(value) {
1364
+ try {
1365
+ localStorage.setItem(IGNORE_KEY, JSON.stringify(value));
1366
+ } catch (error) {
1367
+ /* 隐私模式下不持久化:本次会话内仍然有效 */
1368
+ }
1369
+ }
1370
+
1371
+ /* 「保留」标注 —— 本机偏好(localStorage):手动认定"这个插件我要留着"。
1372
+ 语义:**人工标注高于一切机器判定** —— 被标注的插件永不进入清理候选;
1373
+ 反过来,机器测不到(无法度量)的插件也要靠它把用户的真实意图记录下来。 */
1374
+ const KEEP_KEY = "dph-hub-keep";
1375
+ function readKeep() {
1376
+ try {
1377
+ const raw = localStorage.getItem(KEEP_KEY);
1378
+ if (!raw) return [];
1379
+ const parsed = JSON.parse(raw);
1380
+ if (!Array.isArray(parsed)) return [];
1381
+ return parsed.map((name) => String(name)).filter(Boolean).slice(0, 300);
1382
+ } catch (error) {
1383
+ return [];
1384
+ }
1385
+ }
1386
+ function storeKeep(value) {
1387
+ try {
1388
+ localStorage.setItem(KEEP_KEY, JSON.stringify(value));
1389
+ } catch (error) {
1390
+ /* 隐私模式下不持久化:本次会话内仍然有效 */
1391
+ }
1392
+ }
1393
+
1394
+ /* 「待重启」提醒 —— 本地通道安装/升级成功后的激活闭环(2026-10-13)。
1395
+ 为什么必须做:桌面 profile 实测**没有 dshmarket**(只有 dsh-restart 的链接),
1396
+ 安装全走本地通道、必须重启才生效 —— 「装了没启用」是主路径而不是边缘情况,
1397
+ 它正是实装验证率最大的漏点。行内提示跟着卡片走,切个视图就看不见了,
1398
+ 所以这条提醒挂在面板与页签顶部,跨视图、跨会话存在,直到重启生效或
1399
+ 用户明确说「知道了」。 */
1400
+ const RESTART_KEY = "dph-hub-restart-pending";
1401
+ function readRestartPending() {
1402
+ try {
1403
+ const raw = localStorage.getItem(RESTART_KEY);
1404
+ if (!raw) return null;
1405
+ const parsed = JSON.parse(raw);
1406
+ if (!parsed || !Array.isArray(parsed.names) || !parsed.names.length) return null;
1407
+ return { names: parsed.names.map((name) => String(name)).filter(Boolean), at: Number(parsed.at) || 0 };
1408
+ } catch (error) {
1409
+ return null;
1410
+ }
1411
+ }
1412
+ function storeRestartPending(value) {
1413
+ try {
1414
+ if (value) localStorage.setItem(RESTART_KEY, JSON.stringify(value));
1415
+ else localStorage.removeItem(RESTART_KEY);
1416
+ } catch (error) {
1417
+ /* 隐私模式下不持久化:本次会话内仍然提醒 */
1418
+ }
1419
+ }
1420
+ const hub = { open: false, hidden: hubHidden, daily: dailyOn, telemetry: telemetryOn, autoCheck: readAutoCheck(), ignore: readIgnore(), fav: readFav(), keep: readKeep(), restartPending: readRestartPending(), install: null, batch: null, compare: [], listeners: new Set() };
473
1421
  function setHub(patch) {
474
1422
  Object.assign(hub, patch);
475
1423
  hub.listeners.forEach((listener) => listener());
476
1424
  }
1425
+ /* 合并去重:连装三个再重启,横幅只出一条,名字不重复。 */
1426
+ function markRestartPending(name) {
1427
+ const label = String(name || "").trim();
1428
+ if (!label) return;
1429
+ const current = hub.restartPending || { names: [], at: 0 };
1430
+ const next = { names: Array.from(new Set(current.names.concat([label]))), at: Date.now() };
1431
+ storeRestartPending(next);
1432
+ setHub({ restartPending: next });
1433
+ }
1434
+ function clearRestartPending() {
1435
+ if (!hub.restartPending) return;
1436
+ storeRestartPending(null);
1437
+ setHub({ restartPending: null });
1438
+ }
1439
+ /** 忽略(version 为空 = 取消忽略)。包名 → 目标版本,版本一变提醒自动回来。 */
1440
+ function setIgnored(pkg, version) {
1441
+ const name = String(pkg || "");
1442
+ if (!name) return;
1443
+ const next = Object.assign({}, hub.ignore);
1444
+ if (version) next[name] = String(version);
1445
+ else delete next[name];
1446
+ storeIgnore(next);
1447
+ setHub({ ignore: next });
1448
+ }
1449
+ /** 收藏条目只留渲染与安装要用的字段(目录会变,快照是唯一还认得出它的东西)。 */
1450
+ const favKey = (item) => String((item && (item.fullName || item.pkg)) || "");
1451
+ function inFav(item) {
1452
+ const key = favKey(item);
1453
+ return Boolean(key) && (hub.fav || []).some((entry) => favKey(entry) === key);
1454
+ }
1455
+ function toggleFav(item) {
1456
+ const key = favKey(item);
1457
+ if (!key) return;
1458
+ const list = hub.fav || [];
1459
+ if (inFav(item)) {
1460
+ const next = list.filter((entry) => favKey(entry) !== key);
1461
+ storeFav(next);
1462
+ setHub({ fav: next });
1463
+ return;
1464
+ }
1465
+ const snapshot = {};
1466
+ FAV_FIELDS.forEach((field) => { if (item[field] !== undefined) snapshot[field] = item[field]; });
1467
+ /* 上限 100:这是"攒着待装"的清单,不是知识库;超了丢最旧的(本地存储也不该无限长) */
1468
+ const next = list.concat([snapshot]).slice(-100);
1469
+ storeFav(next);
1470
+ setHub({ fav: next });
1471
+ }
1472
+ /** 这条更新是否被用户忽略(忽略的是**具体目标版本**,不是这个包)。 */
1473
+ function isIgnored(item) {
1474
+ if (!item || !hub.ignore) return false;
1475
+ const version = hub.ignore[String(item.name || "")];
1476
+ return Boolean(version) && version === String(item.latest || "");
1477
+ }
1478
+ /** 「保留」查询与切换(按包名,跨视图共享一份 hub.keep)。 */
1479
+ function isKept(name) {
1480
+ const key = String(name || "");
1481
+ return Boolean(key) && (hub.keep || []).indexOf(key) >= 0;
1482
+ }
1483
+ function toggleKeep(name) {
1484
+ const key = String(name || "");
1485
+ if (!key) return;
1486
+ const list = hub.keep || [];
1487
+ const next = isKept(key) ? list.filter((entry) => entry !== key) : list.concat([key]).slice(-300);
1488
+ storeKeep(next);
1489
+ setHub({ keep: next });
1490
+ }
1491
+ /**
1492
+ * 对比选择集 —— 挂在 hub 上(浮窗与页签共用一份),但**刻意不持久**:
1493
+ * 对比是一次性的动作,不是偏好;下次打开还挂着上回选的两个插件只会让人困惑。
1494
+ * 存的是**条目对象**而不是包名:搜索词一改,列表就换了,只存名字的话
1495
+ * 表格会当场变空(拿不到星标/卖点这些字段)。
1496
+ */
1497
+ const compareKey = (item) => String((item && (item.fullName || item.pkg)) || "");
1498
+ function inCompare(item) {
1499
+ const key = compareKey(item);
1500
+ return Boolean(key) && (hub.compare || []).some((entry) => compareKey(entry) === key);
1501
+ }
1502
+ function toggleCompare(item) {
1503
+ const key = compareKey(item);
1504
+ if (!key) return;
1505
+ const list = hub.compare || [];
1506
+ if (inCompare(item)) {
1507
+ setHub({ compare: list.filter((entry) => compareKey(entry) !== key) });
1508
+ return;
1509
+ }
1510
+ if (list.length >= COMPARE_MAX) return;
1511
+ setHub({ compare: list.concat([item]) });
1512
+ }
477
1513
  /**
478
1514
  * 浮窗的「手动关闭」。
479
1515
  *
@@ -481,20 +1517,24 @@ window.__ModuleLoader__.load({
481
1517
  * 而 `open` 只表示展开/收起 —— 用户此前没有把这块东西从屏幕上拿掉的手段。
482
1518
  * 这里把「隐藏」做成第三种状态并写进 localStorage(下次进来仍然是关的)。
483
1519
  *
484
- * 恢复入口必须配齐,否则就变成"关掉就找不回来":
485
- * ① 侧边栏底部「严选插件」按钮(FooterEntry,隐藏时点击会先取消隐藏)
486
- * ② 「严选插件」页底部的「显示右下角浮窗」开关(floatToggle)
1520
+ * 恢复入口必须配齐,否则就变成"关掉就找不回来"(三个,误点都不会复活浮窗):
1521
+ * ① 「严选插件」页签底部的「显示右下角浮窗」开关(floatToggle)
1522
+ * ② 浮窗显隐开关所在的设置行(settings.general.item / settings.plugins.tab)
1523
+ * ③ 侧边栏底部按钮(FooterEntry)—— **两步确认**:隐藏态第一下只上劲
1524
+ * (按钮描边 + 标记脉冲 + 提示「再点一次恢复浮窗」,5 秒内有效),
1525
+ * 第二下才把胶囊叫回来。
1526
+ * ⚠️ 为什么不是「点一下就地恢复」(2026-10-13 用户反馈:「胶囊用户关闭了
1527
+ * 就别默认打开了」—— 10-12 那版点一次就叫回胶囊,等于没关掉);而纯无反应
1528
+ * 的按钮又被用户当成「没生效」。两步确认两头都照顾:习惯性误点不会复活
1529
+ * 浮窗,真想找回也只要两下,且按钮永远有可见反馈。
1530
+ * 只有浮窗**可见**时,点侧边栏按钮才展开/收起面板;没有任何 on-mount /
1531
+ * 路由切换类的自动展开。
487
1532
  */
488
1533
  function hideHub(scope) {
489
1534
  storeHidden(true);
490
1535
  setHub({ hidden: true, open: false });
491
1536
  track("plugin_hub", { action: "hide", scope: scope || "pill" });
492
1537
  }
493
- function showHub(scope) {
494
- storeHidden(false);
495
- setHub({ hidden: false, open: true });
496
- track("plugin_hub", { action: "open", scope: scope || "footer" });
497
- }
498
1538
  function useHub() {
499
1539
  const [, force] = react.useState(0);
500
1540
  react.useEffect(() => {
@@ -505,78 +1545,427 @@ window.__ModuleLoader__.load({
505
1545
  return hub;
506
1546
  }
507
1547
 
508
- /* ------------------------------------------------------------- utilities */
509
- function format(template, values) {
510
- return String(template).replace(/\{(\w+)\}/g, (whole, key) => (key in values ? String(values[key]) : whole));
1548
+ /**
1549
+ * 只切换「显不显示浮窗」,**不强行展开面板**。
1550
+ *
1551
+ * 「恢复显示」与「展开面板」是两件事,这里只做前者。两个调用方都是用户的
1552
+ * 显式操作:设置里的浮窗开关、页签底部的「显示右下角浮窗」勾选。用户此刻
1553
+ * 人就在别处浏览,把整块面板糊到屏幕上是打扰(2026-10-12 用户反馈)——
1554
+ * 想展开就点右下角胶囊或侧边栏按钮(仅浮窗可见时)。
1555
+ * 侧边栏按钮只在**两步确认的第二下**走这里(见 FooterEntry 的上劲态)。
1556
+ */
1557
+ function setFloatVisible(next, scope) {
1558
+ if (!next) {
1559
+ hideHub(scope || "settings");
1560
+ return;
1561
+ }
1562
+ storeHidden(false);
1563
+ setHub({ hidden: false });
1564
+ track("plugin_hub", { action: "show", scope: scope || "settings" });
1565
+ }
1566
+
1567
+ function setDaily(next, scope) {
1568
+ storeDaily(next);
1569
+ setHub({ daily: next });
1570
+ track("plugin_hub", { action: "daily_toggle", scope: (scope || "settings") + ":" + (next ? "on" : "off") });
511
1571
  }
512
1572
 
513
- /* ------------------------------------------------------------ 浮窗位置(可拖动) */
514
- /* 为什么要能拖:右下角在 dsh 里不是空位 —— 实测与「检查更新」等既有按钮重叠。
515
- 拖动后位置记在 localStorage(right/bottom,单位 px),下次进来还在原处。 */
516
- const POS_KEY = "dph-hub-pos";
517
- const EDGE = 8;
518
- const DRAG_THRESHOLD = 5;
519
1573
  /**
520
- * 默认位置刻意**不贴右下角**,且要避开其它插件已占的那几个位置。
1574
+ * 「自动检查插件更新」开关:开 → 立刻查一次;关 → 清掉结果,红点随之消失
1575
+ * (不自动查也就不该提醒)。手动「检查更新」按钮不受它影响。
1576
+ */
1577
+ function setAutoCheck(next, scope) {
1578
+ setHub({ autoCheck: next });
1579
+ try {
1580
+ localStorage.setItem(AUTO_CHECK_KEY, next ? "1" : "0");
1581
+ } catch (error) {
1582
+ /* 隐私模式下不持久化 */
1583
+ }
1584
+ track("plugin_hub", { action: "autocheck_toggle", scope: (scope || "settings") + ":" + (next ? "on" : "off") });
1585
+ if (next) {
1586
+ loadUpdates(true);
1587
+ } else {
1588
+ setUpdates({ loading: false, loaded: false, data: null, error: null, stale: false });
1589
+ }
1590
+ }
1591
+
1592
+ /** 匿名统计开关的唯一写入口(面板页脚与设置页共用,避免两处各写一份持久化逻辑)。 */
1593
+ function setTelemetry(next) {
1594
+ try {
1595
+ localStorage.setItem(TEL_KEY, next ? "1" : "0");
1596
+ } catch (error) {
1597
+ /* 隐私模式下不持久化 */
1598
+ }
1599
+ setHub({ telemetry: next });
1600
+ telemetryOn = next;
1601
+ }
1602
+
1603
+ /**
1604
+ * 恢复默认:把三个本地偏好清成出厂值。
521
1605
  *
522
- * 实测(1280×860 与 1280×900 两次量测,2026-09-17/18)右下角竖着排了三个
523
- * **z-index 同为 2147483000** 的浮动按钮,DOM 靠后的会压住前面的:
524
- * · `#dsh-check-updates-btn`(「检查更新」) bottom 16..48
525
- * · `#mem-open`(dsh-mnemon 的「🧠 Memory」)bottom 56..96
526
- * 故取 bottom:108(在两者之上)—— 108 这个数是量出来的,不是拍的:
527
- * 曾经用 60,正好落在 mnemon 按钮的 56..96 里,导致胶囊被完全覆盖、
528
- * **点不动**(playwright 报 `#mem-open … intercepts pointer events`)。
1606
+ * 刻意**不**动 `dph-hub-vid`(访客 ID)与 `dph-hub-pending`(安装回执)——
1607
+ * 前者是统计口径的连续性,后者是一次性的安装结果凭据,都不是「偏好」。
1608
+ * 位置要连 localStorage 一起删:只重置内存里的 pos,下次进来又会读回旧位置。
1609
+ */
1610
+ function resetPrefs(scope) {
1611
+ try {
1612
+ localStorage.removeItem(HIDE_KEY);
1613
+ localStorage.removeItem(POS_KEY);
1614
+ localStorage.removeItem(DAILY_KEY);
1615
+ localStorage.removeItem(AUTO_CHECK_KEY);
1616
+ } catch (error) {
1617
+ /* 隐私模式下没法清盘,本次会话内仍然生效 */
1618
+ }
1619
+ setHub({ hidden: false, daily: true, autoCheck: true, open: false });
1620
+ storeHidden(false);
1621
+ storeDaily(true);
1622
+ track("plugin_hub", { action: "prefs_reset", scope: scope || "settings" });
1623
+ }
1624
+
1625
+ /* --------------------------------------------------- 更新检查(共享 store) */
1626
+ /**
1627
+ * 三处红点 + 「更新」视图读的是**同一份**结果,所以必须是模块级 store。
529
1628
  *
530
- * 不用提高 z-index 去抢:那会让被压住的那个按钮反过来点不动(同样是别人的功能)。
531
- * 位置冲突可以用位置解决;用户仍可拖动,位置会记住。
1629
+ * 若每个组件各自 useState,一次页面加载会向 host 打四遍;而 host 那边每遍是
1630
+ * N 个 registry 请求(本机 21 个)—— 这不是"顺手抽个 store",是本模块唯一
1631
+ * 必须共享的状态。
1632
+ *
1633
+ * 「恢复默认」**刻意不清**这个确认标记:它是"我看过了"而不是"我的偏好",
1634
+ * 一并清掉只会让用户刚关掉的红点立刻又亮起来。
532
1635
  */
533
- const DEFAULT_POS = { right: 16, bottom: 108 };
1636
+ const ACK_KEY = "dph-hub-updates-acked";
1637
+ let ackedSignature = "";
1638
+ try {
1639
+ const raw = localStorage.getItem(ACK_KEY);
1640
+ ackedSignature = raw ? String(JSON.parse(raw) || "") : "";
1641
+ } catch (error) {
1642
+ /* 读不到就当没确认过:宁可多亮一次红点,也不要静默吞掉升级提示 */
1643
+ }
1644
+ /**
1645
+ * dsh 兼容性闸门**拒绝过**的版本(键为 `pkg@version`)。
1646
+ *
1647
+ * 为什么要记:dsh 的闸门只看目标版本的 peerDependencies,而更新检查只看"有没有新版本",
1648
+ * 两者互不知情 —— 于是列表里会出现"能装但会被 dsh 拒绝"的条目(实测 13 个可升级里就有 2 个)。
1649
+ * 这里**不做预判**(那需要自己实现 semver 范围求值,猜错会误伤),只把**真实发生过的拒绝**
1650
+ * 记住,下次直接标出来,省掉一次白点。
1651
+ */
1652
+ const BLOCKED_KEY = "dph-hub-blocked";
1653
+ function readBlocked() {
1654
+ try {
1655
+ const raw = localStorage.getItem(BLOCKED_KEY);
1656
+ const parsed = raw ? JSON.parse(raw) : null;
1657
+ return Array.isArray(parsed) ? parsed.filter((item) => typeof item === "string") : [];
1658
+ } catch (error) {
1659
+ return [];
1660
+ }
1661
+ }
534
1662
 
535
- function viewportSize() {
536
- return {
537
- w: typeof window === "undefined" ? 1440 : window.innerWidth,
538
- h: typeof window === "undefined" ? 900 : window.innerHeight,
539
- };
1663
+ const updates = { loading: false, loaded: false, data: null, error: null, stale: false, acked: ackedSignature, blocked: readBlocked(), listeners: new Set() };
1664
+
1665
+ function setUpdates(patch) {
1666
+ Object.assign(updates, patch);
1667
+ updates.listeners.forEach((listener) => listener());
540
1668
  }
541
1669
 
542
- /** 夹在视口内(留 EDGE 边距)。纯函数,便于测试。 */
543
- function clampPos(pos, size, view) {
544
- const right = Math.max(EDGE, Math.min(Number(pos && pos.right) || EDGE, Math.max(EDGE, view.w - size.w - EDGE)));
545
- const bottom = Math.max(EDGE, Math.min(Number(pos && pos.bottom) || EDGE, Math.max(EDGE, view.h - size.h - EDGE)));
546
- return { right: Math.round(right), bottom: Math.round(bottom) };
1670
+ function storeAcked(signature) {
1671
+ try {
1672
+ localStorage.setItem(ACK_KEY, JSON.stringify(signature));
1673
+ } catch (error) {
1674
+ /* 隐私模式下不持久化,本次会话内仍然算已确认 */
1675
+ }
547
1676
  }
548
1677
 
549
- function readStoredPos() {
1678
+ /** 记住一次被 dsh 兼容性闸门拒掉的版本(供后续直接标注)。 */
1679
+ function rememberBlocked(spec) {
1680
+ const value = String(spec || "");
1681
+ if (!value || updates.blocked.includes(value)) return;
1682
+ const next = updates.blocked.concat([value]).slice(-50);
550
1683
  try {
551
- const raw = localStorage.getItem(POS_KEY);
552
- if (!raw) return DEFAULT_POS;
553
- const parsed = JSON.parse(raw);
554
- return clampPos(parsed, { w: 150, h: 38 }, viewportSize());
1684
+ localStorage.setItem(BLOCKED_KEY, JSON.stringify(next));
555
1685
  } catch (error) {
556
- return DEFAULT_POS;
1686
+ /* 隐私模式下不持久化,本次会话内仍然可见 */
557
1687
  }
1688
+ setUpdates({ blocked: next });
558
1689
  }
559
1690
 
560
- function storePos(pos) {
1691
+ /**
1692
+ * 「可升级集合」的签名 —— 红点的唯一判据。
1693
+ *
1694
+ * 用「包名@目标版本」排序后的串做签名:只要出现**比上次确认过的更新的版本**,
1695
+ * 串就会变,红点重新亮;同一批更新确认过一次之后不再打扰。
1696
+ * 这与用户已有的 check-updates 本地补丁同一套思路(那里存的是 acked-version),
1697
+ * 目的都是避免红点长期常亮。
1698
+ */
1699
+ function updateSignature(data) {
1700
+ if (!data || typeof data !== "object") return "";
1701
+ const parts = [];
1702
+ /* 被忽略的条目不进签名 —— 否则"忽略此版本"之后红点照常亮着,等于没忽略 */
1703
+ if (data.self && data.self.outdated === true && !isIgnored(data.self)) parts.push("self@" + String(data.self.latest || ""));
1704
+ const list = Array.isArray(data.plugins) ? data.plugins : [];
1705
+ list.forEach((item) => {
1706
+ if (item && item.outdated === true && !isIgnored(item)) parts.push(String(item.name) + "@" + String(item.latest || ""));
1707
+ });
1708
+ return parts.sort().join("|");
1709
+ }
1710
+
1711
+ /** 红点状态:count = 待升级项数,fresh = 有「还没确认过」的更新。 */
1712
+ function pendingUpdates() {
1713
+ const signature = updateSignature(updates.data);
1714
+ return {
1715
+ count: signature === "" ? 0 : signature.split("|").length,
1716
+ fresh: signature !== "" && signature !== updates.acked,
1717
+ };
1718
+ }
1719
+
1720
+ /** 用户**看到清单**即视为已确认(在「更新」视图挂载时调用)。 */
1721
+ function ackUpdates(scope) {
1722
+ const signature = updateSignature(updates.data);
1723
+ if (signature === "" || signature === updates.acked) return;
1724
+ storeAcked(signature);
1725
+ track("plugin_hub", { action: "updates_ack", scope: scope || "view", n: signature.split("|").length });
1726
+ setUpdates({ acked: signature });
1727
+ }
1728
+
1729
+ async function loadUpdates(force) {
1730
+ if (updates.loading) return;
1731
+ if (updates.loaded && !force) return;
1732
+ setUpdates({ loading: true, error: null });
1733
+ const controller = new AbortController();
1734
+ const timer = setTimeout(() => controller.abort(), 30000);
561
1735
  try {
562
- localStorage.setItem(POS_KEY, JSON.stringify(pos));
1736
+ const body = await readHostJson("/api/dpharness/updates" + (force ? "?refresh=1" : ""), controller.signal);
1737
+ setUpdates({ loading: false, loaded: true, data: body, stale: false });
563
1738
  } catch (error) {
564
- /* 隐私模式下不持久化,本次会话内仍可拖 */
1739
+ /* 失败要说出来:悄悄回一份空清单,界面会把它读成「全都已是最新」。
1740
+ stale 单独标出来 —— 它对应的是一句可操作的话(重启 dsh),而不是一个技术错误。 */
1741
+ const message = error && error.name === "AbortError" ? "timeout" : String((error && error.message) || error);
1742
+ setUpdates({ loading: false, loaded: true, error: message, stale: Boolean(error && error.stale) });
1743
+ } finally {
1744
+ clearTimeout(timer);
565
1745
  }
566
1746
  }
567
1747
 
568
1748
  /**
569
- * 拖动逻辑:pointer 事件 + 位移阈值区分「点击」与「拖动」。
570
- * 返回的函数把 moved 标记交给调用方,用于在 pointerup 后的 click 里跳过打开动作。
1749
+ * 订阅 + 首次挂载时触发一次检查(幂等)。
571
1750
  *
572
- * ⚠️ 监听挂在 `window` 上而不是被拖元素上:元素级监听依赖
573
- * `setPointerCapture` 成功,而它并非在所有场景都生效(实测面板标题拖不动就是
574
- * 因为指针移出元素后 pointermove 不再派发给它)。window 监听无条件收到移动事件。
1751
+ * 侧边栏按钮与浮窗胶囊**始终挂着**,所以红点不需要用户先打开任何页面就能亮起来 ——
1752
+ * 这正是"用户根本不知道有新版本"这个问题的解法。
575
1753
  */
576
- function makeDragHandlers(getPos, setPos, skipClickRef) {
577
- return function onPointerDown(event) {
578
- if (event.button !== undefined && event.button !== 0) return; // 只响应左键
579
- const node = event.currentTarget;
1754
+ function useUpdates() {
1755
+ const [, force] = react.useState(0);
1756
+ react.useEffect(() => {
1757
+ const listener = () => force((n) => n + 1);
1758
+ updates.listeners.add(listener);
1759
+ /* 关掉自动检查就不查(红点随之不亮);手动「检查更新」按钮不受影响 */
1760
+ if (hub.autoCheck) loadUpdates(false);
1761
+ return () => { updates.listeners.delete(listener); };
1762
+ }, []);
1763
+ return updates;
1764
+ }
1765
+
1766
+ /* ------------------------------------------------------------- utilities */
1767
+ function format(template, values) {
1768
+ return String(template).replace(/\{(\w+)\}/g, (whole, key) => (key in values ? String(values[key]) : whole));
1769
+ }
1770
+
1771
+ /**
1772
+ * 「共 N 条结果」里的 N 必须是 host 转发的**真实命中总数**(total),
1773
+ * 不是本次返回条数(count)—— 两者在搜索时经常相差一个数量级
1774
+ * (take 默认 30,而「统计」命中 106 条)。
1775
+ *
1776
+ * 为什么这不是文案细节(2026-09-30 实测踩到):以前 N 取的是返回条数,
1777
+ * 于是**搜索前后这个数字都是 30**,同时列表首屏变化不大,用户据此判定
1778
+ * 「搜索不生效」—— 功能其实是好的,界面没给出任何证据。
1779
+ * 命中数大于已显示条数时,补一句「已显示前 M 条」,让用户知道列表被截断、
1780
+ * 可以切到 60/100 看更多。
1781
+ *
1782
+ * total 缺失(旧 host)时退回返回条数,保证文案仍有意义。
1783
+ */
1784
+ function summaryOf(data, t) {
1785
+ if (!data) return "";
1786
+ const total = Number.isFinite(data.total) ? data.total : data.count;
1787
+ const shown = Array.isArray(data.plugins) ? data.plugins.length : 0;
1788
+ const base = format(t("count.summary"), { n: total });
1789
+ return total > shown && shown > 0 ? base + " · " + format(t("count.partial"), { m: shown }) : base;
1790
+ }
1791
+
1792
+ /**
1793
+ * 标题位置的那行副标题。
1794
+ *
1795
+ * 重新搜索时让位给「搜索中…」:列表刻意保留旧结果(避免整块闪空),
1796
+ * 若标题也原样不动,界面就没有任何「点到了」的证据 —— 用户正是据此判定
1797
+ * 「搜索不生效」(2026-09-30)。首次加载不给这里,因为下方已有
1798
+ * 「正在读取插件目录…」,重复反而吵。
1799
+ */
1800
+ function countSub(data, t, loading, suffix) {
1801
+ if (!data) return suffix || "";
1802
+ if (loading) return t("count.searching");
1803
+ return summaryOf(data, t) + (suffix ? " · " + suffix : "");
1804
+ }
1805
+
1806
+ /* ------------------------------------------------------- 每日推荐(纯函数) */
1807
+ /**
1808
+ * 每日推荐的三个口径,全部做成纯函数:便于单测,也保证所有入口拿到同一份答案。
1809
+ *
1810
+ * 为什么是「按日期算」而不是服务端下发(2026-10-12 定的方案):
1811
+ * 站点当时没有每日推荐接口(/api/daily、/api/today、/api/recommend 实测全 404),
1812
+ * 而 /api/best 是**月度策展榜单** —— 本身就是编辑审过的集合,从它里按自然日取一条,
1813
+ * 质量有兜底、零站点改动;代价是这条「推荐」是机械轮换,不是编辑每天点选。
1814
+ * 日后站点若给出 /api/daily,只需替换 pickDaily 的数据源,界面无需改动。
1815
+ *
1816
+ * 时区固定 UTC+8:用本地时区会让同一天不同地区的用户看到不同的一条,
1817
+ * 而「今日推荐」的语义本来就是「今天大家看到的是同一条」。
1818
+ */
1819
+ const DAILY_TZ_MS = 8 * 60 * 60 * 1000;
1820
+
1821
+ /** 自然日键(UTC+8),形如 2026-10-12。入参是毫秒时间戳,便于测试固定时间。 */
1822
+ function dailyKey(nowMs) {
1823
+ const shifted = new Date((Number(nowMs) || 0) + DAILY_TZ_MS);
1824
+ const y = shifted.getUTCFullYear();
1825
+ const m = shifted.getUTCMonth() + 1;
1826
+ const d = shifted.getUTCDate();
1827
+ return y + "-" + (m < 10 ? "0" : "") + m + "-" + (d < 10 ? "0" : "") + d;
1828
+ }
1829
+
1830
+ /** FNV-1a 32 位。用它而不是随机数:同一天必须收敛到同一条,且不依赖任何外部状态。 */
1831
+ function hashKey(text) {
1832
+ let hash = 0x811c9dc5;
1833
+ const value = String(text == null ? "" : text);
1834
+ for (let index = 0; index < value.length; index += 1) {
1835
+ hash ^= value.charCodeAt(index);
1836
+ hash = Math.imul(hash, 0x01000193) >>> 0;
1837
+ }
1838
+ return hash >>> 0;
1839
+ }
1840
+
1841
+ /** 展平 /api/best 的三级结构(大类 → 小类 → 条目),并记住条目所属的小类/大类。 */
1842
+ function flattenBest(data) {
1843
+ const output = [];
1844
+ const categories = data && Array.isArray(data.categories) ? data.categories : [];
1845
+ categories.forEach((cat) => {
1846
+ const subs = Array.isArray(cat.subs) ? cat.subs : [];
1847
+ subs.forEach((sub) => {
1848
+ const items = Array.isArray(sub.items) ? sub.items : [];
1849
+ items.forEach((item) => {
1850
+ if (!item) return;
1851
+ /* 目录类条目的唯一键是 fullName;缺它就无从比较、也无从稳定排序 */
1852
+ const key = item.fullName || item.pkg;
1853
+ if (!key) return;
1854
+ output.push({ item: item, key: String(key), cat: cat.label || cat.key || "", sub: sub.label || sub.key || "" });
1855
+ });
1856
+ });
1857
+ });
1858
+ return output;
1859
+ }
1860
+
1861
+ /**
1862
+ * 取「今天的」那一条。
1863
+ *
1864
+ * ⚠️ 候选**必须先稳定排序**再取模:上游 /api/best 的分组顺序会随站点重算榜单、
1865
+ * 增删小类而变化;若按原顺序取模,同一天刷新两次就可能换人 ——
1866
+ * 「每日推荐」只要不稳定,它就不再是一个可信的说法。
1867
+ * 排序键用条目的唯一键,结果与上游顺序完全无关。
1868
+ */
1869
+ function pickDaily(data, dateKey) {
1870
+ const all = flattenBest(data);
1871
+ if (all.length === 0) return null;
1872
+ const sorted = all.slice().sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
1873
+ return sorted[hashKey(dateKey) % sorted.length];
1874
+ }
1875
+
1876
+ /**
1877
+ * 当前自然日键,跨天自动刷新。
1878
+ *
1879
+ * dsh 是常驻页面,用户可能几天不关 —— 只在挂载时算一次的话,
1880
+ * 第二天打开的还是昨天那条。用 60s 轮询 + 页面重新可见/获得焦点时立即比对,
1881
+ * 都很便宜(一次字符串相等判断),不做定时器级的精确对齐。
1882
+ */
1883
+ function useDateKey() {
1884
+ const [key, setKey] = react.useState(() => dailyKey(Date.now()));
1885
+ react.useEffect(() => {
1886
+ const sync = () => setKey((current) => {
1887
+ const next = dailyKey(Date.now());
1888
+ return next === current ? current : next;
1889
+ });
1890
+ const timer = setInterval(sync, 60000);
1891
+ window.addEventListener("visibilitychange", sync);
1892
+ window.addEventListener("focus", sync);
1893
+ return () => {
1894
+ clearInterval(timer);
1895
+ window.removeEventListener("visibilitychange", sync);
1896
+ window.removeEventListener("focus", sync);
1897
+ };
1898
+ }, []);
1899
+ return key;
1900
+ }
1901
+
1902
+ /* ------------------------------------------------------------ 浮窗位置(可拖动) */
1903
+ /* 为什么要能拖:右下角在 dsh 里不是空位 —— 实测与「检查更新」等既有按钮重叠。
1904
+ 拖动后位置记在 localStorage(right/bottom,单位 px),下次进来还在原处。 */
1905
+ const POS_KEY = "dph-hub-pos";
1906
+ const EDGE = 8;
1907
+ const DRAG_THRESHOLD = 5;
1908
+ /**
1909
+ * 默认位置刻意**不贴右下角**,且要避开其它插件已占的那几个位置。
1910
+ *
1911
+ * 实测(1280×860 与 1280×900 两次量测,2026-09-17/18)右下角竖着排了三个
1912
+ * **z-index 同为 2147483000** 的浮动按钮,DOM 靠后的会压住前面的:
1913
+ * · `#dsh-check-updates-btn`(「检查更新」) bottom 16..48
1914
+ * · `#mem-open`(dsh-mnemon 的「🧠 Memory」)bottom 56..96
1915
+ * 故取 bottom:108(在两者之上)—— 108 这个数是量出来的,不是拍的:
1916
+ * 曾经用 60,正好落在 mnemon 按钮的 56..96 里,导致胶囊被完全覆盖、
1917
+ * **点不动**(playwright 报 `#mem-open … intercepts pointer events`)。
1918
+ *
1919
+ * 不用提高 z-index 去抢:那会让被压住的那个按钮反过来点不动(同样是别人的功能)。
1920
+ * 位置冲突可以用位置解决;用户仍可拖动,位置会记住。
1921
+ */
1922
+ const DEFAULT_POS = { right: 16, bottom: 108 };
1923
+
1924
+ function viewportSize() {
1925
+ return {
1926
+ w: typeof window === "undefined" ? 1440 : window.innerWidth,
1927
+ h: typeof window === "undefined" ? 900 : window.innerHeight,
1928
+ };
1929
+ }
1930
+
1931
+ /** 夹在视口内(留 EDGE 边距)。纯函数,便于测试。 */
1932
+ function clampPos(pos, size, view) {
1933
+ const right = Math.max(EDGE, Math.min(Number(pos && pos.right) || EDGE, Math.max(EDGE, view.w - size.w - EDGE)));
1934
+ const bottom = Math.max(EDGE, Math.min(Number(pos && pos.bottom) || EDGE, Math.max(EDGE, view.h - size.h - EDGE)));
1935
+ return { right: Math.round(right), bottom: Math.round(bottom) };
1936
+ }
1937
+
1938
+ function readStoredPos() {
1939
+ try {
1940
+ const raw = localStorage.getItem(POS_KEY);
1941
+ if (!raw) return DEFAULT_POS;
1942
+ const parsed = JSON.parse(raw);
1943
+ return clampPos(parsed, { w: 150, h: 38 }, viewportSize());
1944
+ } catch (error) {
1945
+ return DEFAULT_POS;
1946
+ }
1947
+ }
1948
+
1949
+ function storePos(pos) {
1950
+ try {
1951
+ localStorage.setItem(POS_KEY, JSON.stringify(pos));
1952
+ } catch (error) {
1953
+ /* 隐私模式下不持久化,本次会话内仍可拖 */
1954
+ }
1955
+ }
1956
+
1957
+ /**
1958
+ * 拖动逻辑:pointer 事件 + 位移阈值区分「点击」与「拖动」。
1959
+ * 返回的函数把 moved 标记交给调用方,用于在 pointerup 后的 click 里跳过打开动作。
1960
+ *
1961
+ * ⚠️ 监听挂在 `window` 上而不是被拖元素上:元素级监听依赖
1962
+ * `setPointerCapture` 成功,而它并非在所有场景都生效(实测面板标题拖不动就是
1963
+ * 因为指针移出元素后 pointermove 不再派发给它)。window 监听无条件收到移动事件。
1964
+ */
1965
+ function makeDragHandlers(getPos, setPos, skipClickRef) {
1966
+ return function onPointerDown(event) {
1967
+ if (event.button !== undefined && event.button !== 0) return; // 只响应左键
1968
+ const node = event.currentTarget;
580
1969
  const start = getPos();
581
1970
  const startX = event.clientX;
582
1971
  const startY = event.clientY;
@@ -665,17 +2054,19 @@ window.__ModuleLoader__.load({
665
2054
  if (debounced) params.set("q", debounced);
666
2055
  params.set("take", String(take));
667
2056
  if (byStars) params.set("sort", "stars");
668
- fetch("/api/dpharness/search?" + params.toString(), { cache: "no-store", signal: controller.signal })
669
- .then((response) => response.json().then((body) => ({ status: response.status, body })))
670
- .then((result) => {
2057
+ readHostJson("/api/dpharness/search?" + params.toString(), controller.signal)
2058
+ .then((body) => {
671
2059
  if (controller.signal.aborted) return;
672
- if (result.status !== 200 || !result.body || result.body.ok !== true) {
673
- throw new Error((result.body && result.body.error) || ("HTTP " + result.status));
674
- }
675
- setState({ loading: false, data: result.body, error: null });
2060
+ setState({ loading: false, data: body, error: null });
676
2061
  if (debounced) {
677
- // 只上报关键词长度与命中数,不上报关键词原文
678
- track("plugin_hub", { action: "search", length: debounced.length, results: result.body.count });
2062
+ // 只上报关键词长度与命中数,不上报关键词原文。
2063
+ // 命中数取 total(真实命中总数):取返回条数时它恒等于 take,
2064
+ // 对「这次搜索到底有没有命中东西」没有任何信息量。
2065
+ track("plugin_hub", {
2066
+ action: "search",
2067
+ length: debounced.length,
2068
+ results: Number.isFinite(body.total) ? body.total : body.count,
2069
+ });
679
2070
  }
680
2071
  })
681
2072
  .catch((error) => {
@@ -719,15 +2110,55 @@ window.__ModuleLoader__.load({
719
2110
  const controller = new AbortController();
720
2111
  const timer = setTimeout(() => controller.abort(), 20000);
721
2112
  setState((previous) => ({ loading: true, data: previous.data, error: null }));
722
- fetch("/api/dpharness/best", { cache: "no-store", signal: controller.signal })
723
- .then((response) => response.json().then((body) => ({ status: response.status, body })))
724
- .then((result) => {
2113
+ readHostJson("/api/dpharness/best", controller.signal)
2114
+ .then((body) => {
725
2115
  if (controller.signal.aborted) return;
726
- if (result.status !== 200 || !result.body || result.body.ok !== true) {
727
- throw new Error((result.body && result.body.error) || ("HTTP " + result.status));
728
- }
729
- setState({ loading: false, data: result.body, error: null });
730
- track("plugin_hub", { action: "best_open", cats: (result.body.categories || []).length, total: result.body.total || 0 });
2116
+ setState({ loading: false, data: body, error: null });
2117
+ track("plugin_hub", { action: "best_open", cats: (body.categories || []).length, total: body.total || 0 });
2118
+ })
2119
+ .catch((error) => {
2120
+ if (controller.signal.aborted) return;
2121
+ const message = error && error.name === "AbortError" ? "timeout" : String((error && error.message) || error);
2122
+ setState((previous) => ({ loading: false, data: previous.data, error: message }));
2123
+ })
2124
+ .finally(() => clearTimeout(timer));
2125
+ return () => clearTimeout(timer);
2126
+ }, [enabled, reload]);
2127
+
2128
+ const markCopied = react.useCallback((text) => {
2129
+ setCopiedCmd(text);
2130
+ setTimeout(() => setCopiedCmd((current) => (current === text ? "" : current)), 2000);
2131
+ }, []);
2132
+
2133
+ return { state, copiedCmd, markCopied, refresh: () => setReload((n) => n + 1) };
2134
+ }
2135
+
2136
+ /**
2137
+ * 「套装」取数(站点 /sets 的同源数据,经本机 host 转发)。
2138
+ *
2139
+ * 与 useBest 同一条纪律:只在切到该视图时才请求;拿到一次就不再重复,
2140
+ * 点刷新才重取(缓存交给 host,TTL 5 分钟)。
2141
+ * 与 best 的区别:这里拿到的是**整套方案**(逐条命令与批量命令都由 host 用
2142
+ * 本机 profile 拼好,客户端只负责展示与复制)。
2143
+ */
2144
+ function useSets(t, enabled) {
2145
+ const [reload, setReload] = react.useState(0);
2146
+ const [state, setState] = react.useState({ loading: false, data: null, error: null });
2147
+ const [copiedCmd, setCopiedCmd] = react.useState("");
2148
+ const loaded = react.useRef(false);
2149
+
2150
+ react.useEffect(() => {
2151
+ if (!enabled) return undefined;
2152
+ if (loaded.current && reload === 0) return undefined;
2153
+ loaded.current = true;
2154
+ const controller = new AbortController();
2155
+ const timer = setTimeout(() => controller.abort(), 20000);
2156
+ setState((previous) => ({ loading: true, data: previous.data, error: null }));
2157
+ readHostJson("/api/dpharness/sets", controller.signal)
2158
+ .then((body) => {
2159
+ if (controller.signal.aborted) return;
2160
+ setState({ loading: false, data: body, error: null });
2161
+ track("plugin_hub", { action: "sets_open", n: (body.sets || []).length });
731
2162
  })
732
2163
  .catch((error) => {
733
2164
  if (controller.signal.aborted) return;
@@ -746,6 +2177,51 @@ window.__ModuleLoader__.load({
746
2177
  return { state, copiedCmd, markCopied, refresh: () => setReload((n) => n + 1) };
747
2178
  }
748
2179
 
2180
+ /**
2181
+ * 更新日志(本机 host 的只读接口)。
2182
+ *
2183
+ * 只在**设置页被打开时**才请求 —— 它是设置页里的一节,没必要在每次打开浮窗时拉一遍。
2184
+ * 与 useBest 一样:拿到一次就不再重复请求,点刷新才重取(缓存交给 host,TTL 5 分钟)。
2185
+ */
2186
+ function useChangelog() {
2187
+ const [reload, setReload] = react.useState(0);
2188
+ const [state, setState] = react.useState({ loading: true, data: null, error: null, stale: false });
2189
+ const [copiedCmd, setCopiedCmd] = react.useState("");
2190
+ const loaded = react.useRef(false);
2191
+
2192
+ react.useEffect(() => {
2193
+ if (loaded.current && reload === 0) return undefined;
2194
+ loaded.current = true;
2195
+ const controller = new AbortController();
2196
+ const timer = setTimeout(() => controller.abort(), 20000);
2197
+ setState((previous) => ({ loading: true, data: previous.data, error: null }));
2198
+ readHostJson("/api/dpharness/changelog", controller.signal)
2199
+ .then((body) => {
2200
+ if (controller.signal.aborted) return;
2201
+ setState({ loading: false, data: body, error: null, stale: false });
2202
+ /* 只在**确实有新版本**时上报:这条事件的用途是「有多少人停在旧版」,
2203
+ 把"已是最新"也报进来会把分母撑大,比例就没了意义。 */
2204
+ if (body.outdated === true) {
2205
+ track("plugin_hub", { action: "changelog_open", scope: "outdated" });
2206
+ }
2207
+ })
2208
+ .catch((error) => {
2209
+ if (controller.signal.aborted) return;
2210
+ const message = error && error.name === "AbortError" ? "timeout" : String((error && error.message) || error);
2211
+ setState({ loading: false, data: null, error: message, stale: Boolean(error && error.stale) });
2212
+ })
2213
+ .finally(() => clearTimeout(timer));
2214
+ return () => clearTimeout(timer);
2215
+ }, [reload]);
2216
+
2217
+ const markCopied = react.useCallback((text) => {
2218
+ setCopiedCmd(text);
2219
+ setTimeout(() => setCopiedCmd((current) => (current === text ? "" : current)), 2000);
2220
+ }, []);
2221
+
2222
+ return { state, copiedCmd, markCopied, refresh: () => setReload((n) => n + 1) };
2223
+ }
2224
+
749
2225
  /* ------------------------------------------------------------ components */
750
2226
  function makeUi(t) {
751
2227
  function badge(label, kind) {
@@ -769,11 +2245,19 @@ window.__ModuleLoader__.load({
769
2245
  /* −−− 一键安装:二次确认 → 执行 → 进度 → 结果(失败/需重启) −−− */
770
2246
  function InstallRow(props) {
771
2247
  const item = props.item;
2248
+ /* kind 只改文案与埋点名 —— 执行路径、二次确认、进度与重启提示全部共用同一套 */
2249
+ const upgrading = props.kind === "upgrade";
2250
+ const kind = upgrading ? "upgrade" : "catalog";
772
2251
  const state = useHub();
773
2252
  const [confirming, setConfirming] = react.useState(false);
774
2253
  const [restarting, setRestarting] = react.useState(false);
775
2254
  const [restartFailed, setRestartFailed] = react.useState(false);
2255
+ const [copiedRaw, setCopiedRaw] = react.useState(false);
776
2256
  if (!item.pkg) return null;
2257
+ /* 已经装过的**不要再写"安装"** —— 实测有用户对着早就装好的插件反复点「安装」,
2258
+ 然后判定"安装不成功"(卡片上的「已安装 vX」标注还不够,按钮才是他看的那一处)。 */
2259
+ const idleLabel = upgrading ? t("updates.upgrade") : item.installed ? t("install.reinstall") : t("install.action");
2260
+ const confirmLabel = upgrading ? t("updates.upgradeConfirm") : item.installed ? t("install.reinstallConfirm") : t("install.confirm");
777
2261
 
778
2262
  const job = state.install;
779
2263
  const mine = job && job.target === item.pkg;
@@ -786,9 +2270,16 @@ window.__ModuleLoader__.load({
786
2270
  }
787
2271
 
788
2272
  if (mine && (job.phase === "okMarket" || job.phase === "okLocal")) {
789
- const needsRestart = job.phase === "okLocal";
2273
+ /* 三态(host 读盘得出):changed 装上了 / same **本来就是目标版本**(这是成功)/
2274
+ none 真的什么都没发生。把 same 说成"什么都没装"会让人以为安装失败
2275
+ (2026-10-12 实测被这句误导:用户对着早就装好的插件点安装)。 */
2276
+ const outcome = job.outcome || (job.changed === false ? "same" : "changed");
2277
+ const needsRestart = outcome === "changed" && job.phase === "okLocal";
790
2278
  return h("div", { className: "dph_instRow" }, [
791
- h("span", { className: "dph_instMsg dph_instOk", key: "msg" }, job.message),
2279
+ h("span", { className: "dph_instMsg " + (outcome === "none" ? "dph_instBad" : "dph_instOk"), key: "msg" },
2280
+ outcome === "none" ? t("updates.noChangeTitle") : outcome === "same" ? t("updates.alreadyTitle") : job.message),
2281
+ outcome === "none" ? h("span", { className: "dph_instHint", key: "nochange" }, format(t("updates.noChange"), { v: String(job.after || job.before || "?") })) : null,
2282
+ outcome === "same" ? h("span", { className: "dph_instHint", key: "already" }, format(t("updates.alreadyHint"), { v: String(job.after || "?") })) : null,
792
2283
  needsRestart
793
2284
  ? h("button", {
794
2285
  className: "dph_btn dph_btnPrimary",
@@ -817,168 +2308,1425 @@ window.__ModuleLoader__.load({
817
2308
  }
818
2309
 
819
2310
  if (mine && job.phase === "failed") {
820
- return h("div", { className: "dph_instRow" }, [
821
- h("span", { className: "dph_instMsg dph_instBad", key: "msg" }, t("install.failed") + ":" + job.message),
2311
+ /* 供应链策略暂停:给出被拦的条目 + 还要等多久 + 两条通路。
2312
+ 只回一句英文错误码,用户会以为"插件坏了"(2026-10-14 用户实际撞到)。 */
2313
+ if (job.why === "release-age" && job.reject) {
2314
+ const aged = job.reject;
2315
+ const agedEntries = Array.isArray(aged.entries) ? aged.entries : [];
2316
+ const latest = agedEntries.reduce((max, entry) => {
2317
+ const at = Date.parse(entry.publishedAt || "");
2318
+ return Number.isFinite(at) && at > max ? at : max;
2319
+ }, 0);
2320
+ /* 剩余小时数:不满 1 小时也显示 1,避免出现「约 0 小时后」 */
2321
+ const hoursLeft = latest > 0
2322
+ ? Math.max(1, Math.ceil((latest + 24 * 60 * 60 * 1000 - Date.now()) / (60 * 60 * 1000)))
2323
+ : 0;
2324
+ return h("div", { className: "dph_instRow dph_instCol" }, [
2325
+ h("span", { className: "dph_instMsg dph_instBad", key: "title" }, t("updates.releaseAgeTitle")),
2326
+ h("span", { className: "dph_instHint", key: "body" }, format(t("updates.releaseAgeBody"), {
2327
+ n: String(aged.count || agedEntries.length),
2328
+ list: agedEntries.map((entry) => entry.name + "@" + entry.version).join("、"),
2329
+ })),
2330
+ hoursLeft > 0
2331
+ ? h("span", { className: "dph_instHint", key: "how" }, format(t("updates.releaseAgeHow"), { h: String(hoursLeft) }))
2332
+ : null,
2333
+ ]);
2334
+ }
2335
+ /* 被 dsh 自带的兼容性闸门拒绝 ≠ 安装出错:它是**预期结果**,
2336
+ 必须把原因、两端版本与放行通道说清楚 —— 只说"失败"用户只会觉得功能坏了
2337
+ (实测踩到:通用错误提取抓不到这句话,界面只剩 "dsh: nothing was installed.")。 */
2338
+ if (job.why === "incompatible" && job.reject) {
2339
+ return h("div", { className: "dph_instRow dph_instCol" }, [
2340
+ h("span", { className: "dph_instMsg dph_instBad", key: "title" }, t("updates.blockedTitle")),
2341
+ h("span", { className: "dph_instHint", key: "body" }, format(t("updates.blockedBody"), { spec: job.reject.spec || "", dsh: job.reject.dsh || "" })),
2342
+ h("span", { className: "dph_instHint", key: "how" }, t("updates.blockedHow")),
2343
+ h("button", {
2344
+ className: "dph_btn",
2345
+ key: "raw",
2346
+ type: "button",
2347
+ onClick: () => copyText(job.message || "", () => {
2348
+ setCopiedRaw(true);
2349
+ setTimeout(() => setCopiedRaw(false), 2000);
2350
+ }),
2351
+ }, copiedRaw ? t("action.copied") : t("updates.copyRaw")),
2352
+ ]);
2353
+ }
2354
+ return h("div", { className: "dph_instRow" }, [
2355
+ h("span", { className: "dph_instMsg dph_instBad", key: "msg" }, t("install.failed") + ":" + job.message),
2356
+ ]);
2357
+ }
2358
+
2359
+ if (confirming) {
2360
+ return h("div", { className: "dph_instRow" }, [
2361
+ h("span", { className: "dph_instHint", key: "hint" }, t(upgrading ? "updates.upgradeHint" : "install.hint")),
2362
+ h("button", {
2363
+ className: "dph_btn dph_btnPrimary",
2364
+ key: "go",
2365
+ type: "button",
2366
+ onClick: () => {
2367
+ setConfirming(false);
2368
+ runInstall(item, t, kind);
2369
+ },
2370
+ }, confirmLabel),
2371
+ h("button", {
2372
+ className: "dph_btn",
2373
+ key: "cancel",
2374
+ type: "button",
2375
+ onClick: () => {
2376
+ setConfirming(false);
2377
+ /* 取消单独记一次:只埋 install(确认后)的话,
2378
+ 「想装但被确认框劝退」的人会整段消失,
2379
+ 而他们恰恰是文案/门槛该优化的对象。 */
2380
+ track("plugin_hub", { action: upgrading ? "upgrade_cancel" : "install_cancel", via: "confirm" });
2381
+ },
2382
+ }, t("install.cancel")),
2383
+ ]);
2384
+ }
2385
+
2386
+ return h("div", { className: "dph_instRow" }, [
2387
+ h("button", {
2388
+ className: "dph_btn dph_btnPrimary",
2389
+ key: "install",
2390
+ type: "button",
2391
+ disabled: busyElsewhere,
2392
+ title: busyElsewhere ? t("install.busy") : item.pkg,
2393
+ onClick: () => {
2394
+ setConfirming(true);
2395
+ track("plugin_hub", { action: upgrading ? "upgrade_ask" : "install_ask", via: "confirm" });
2396
+ },
2397
+ }, busyElsewhere ? t("install.busy") : idleLabel),
2398
+ /* 升级行里包名已经在第二行显示过了,这里再摊一遍只是重复;
2399
+ 精确目标(@latest)仍留在按钮的 title 上,悬停可见。 */
2400
+ upgrading ? null : h("span", { className: "dph_instHint", key: "pkg" }, item.pkg),
2401
+ ]);
2402
+ }
2403
+
2404
+ /**
2405
+ * 「分类精选」视图:大类(可折叠)→ 小类 → 条目。
2406
+ *
2407
+ * 与「严选推荐」的区别:那边是**可搜索的全量目录**(按你的关键词找),
2408
+ * 这边是**月度策展结果**(每小类只留 2~3 个),回答的是"按用途该装哪几个"。
2409
+ * 所以渲染上刻意保留两项元数据:
2410
+ * · rank —— 小类内名次,用户要知道"这是这个小类里最好的第几个";
2411
+ * · reason —— 上榜理由(如"实装验证通过 · 周下载 12.8 万"),
2412
+ * 这是"为什么是它"的依据,去掉就只是又一个列表。
2413
+ *
2414
+ * 大类**默认全部收起**(2026-10-13 用户反馈:「分类精选默认折叠」)——
2415
+ * 原先第一个大类默认展开,用户一进视图看到的不是"有哪些类"、
2416
+ * 而是某一个类的全部内容,想扫别的类还得先动手关它。9 个大类一屏列完,
2417
+ * 点哪个看哪个。展开状态在本次会话内保留:`open` 是常量 false,
2418
+ * React 只认 prop 变化,不会把用户手动展开的类重新收回去;
2419
+ * 切走再切回视图才恢复默认收起。
2420
+ */
2421
+ function renderBest(data, copiedCmd, onCopied) {
2422
+ if (!data) return null;
2423
+ const cats = Array.isArray(data.categories) ? data.categories : [];
2424
+ return cats.map((cat, index) =>
2425
+ h("details", { className: "dph_bestCat", key: cat.key || String(index), open: false }, [
2426
+ h("summary", { className: "dph_bestCatHead", key: "head" }, [
2427
+ h("span", { key: "name" }, cat.label),
2428
+ h(
2429
+ "span",
2430
+ { className: "dph_bestCatCount", key: "count" },
2431
+ format(t("best.catCount"), { subs: (cat.subs || []).length, n: cat.count || 0 }),
2432
+ ),
2433
+ ]),
2434
+ ...(cat.subs || []).map((sub) =>
2435
+ h("div", { className: "dph_bestSub", key: sub.key }, [
2436
+ h("div", { className: "dph_bestSubHead", key: "subHead" }, [
2437
+ h("span", { className: "dph_bestSubName", key: "n" }, sub.label),
2438
+ sub.summary
2439
+ ? h("span", { className: "dph_bestSubSum", key: "s", title: sub.summary }, sub.summary)
2440
+ : null,
2441
+ ]),
2442
+ h(
2443
+ "div",
2444
+ { className: "dph_list", key: "list" },
2445
+ (sub.items || []).map((item) =>
2446
+ h("div", { key: item.fullName, className: "dph_bestItem" }, [
2447
+ item.rank
2448
+ ? h("div", { className: "dph_bestRank", key: "rank" }, "#" + item.rank)
2449
+ : null,
2450
+ renderCard(item, copiedCmd, onCopied, true),
2451
+ item.reason
2452
+ ? h("div", { className: "dph_bestReason", key: "why" }, item.reason)
2453
+ : null,
2454
+ ]),
2455
+ ),
2456
+ ),
2457
+ ]),
2458
+ ),
2459
+ ]),
2460
+ );
2461
+ }
2462
+
2463
+ /**
2464
+ * 「一键安装整套」—— 与「全部升级」同一条两步确认(它会连着改十几次 profile,
2465
+ * 一键直落是这一屏里最容易误触的破坏性动作)。
2466
+ *
2467
+ * 另有一套批量在跑(不分升级/安装)时按钮禁用:宿主同一时刻只允许一个安装任务,
2468
+ * 让用户点了必然拿到 409 不如当场说清。
2469
+ */
2470
+ function SetInstallButton(props) {
2471
+ const set = props.set;
2472
+ const state = useHub();
2473
+ const [asked, setAsked] = react.useState(false);
2474
+ const count = (set.items || []).filter((item) => item.pkg).length;
2475
+ const batch = state.batch;
2476
+ const mine = Boolean(batch && batch.scope === "set" && batch.slug === (set.slug || ""));
2477
+ if (mine && batch.active) {
2478
+ return h("span", { className: "dph_logCmd", key: "run" }, [
2479
+ h("span", { className: "dph_instMsg", key: "msg" }, format(t("sets.installing"), { done: batch.finished, total: batch.total, name: batch.current || "" })),
2480
+ h("button", {
2481
+ className: "dph_btn",
2482
+ key: "stop",
2483
+ type: "button",
2484
+ onClick: () => setHub({ batch: { ...hub.batch, stopRequested: true } }),
2485
+ }, t("updates.stop")),
2486
+ ]);
2487
+ }
2488
+ if (mine && !batch.active && batch.total > 0) {
2489
+ return h("span", { className: "dph_instMsg", key: "done" }, format(t("updates.batchDone"), { done: batch.finished, failed: batch.failed }));
2490
+ }
2491
+ if (count === 0) return null;
2492
+ const busyElsewhere = Boolean(batch && batch.active);
2493
+ return h("span", { className: "dph_logCmd", key: "go" }, [
2494
+ asked ? h("span", { className: "dph_setHint", key: "warn" }, format(t("sets.installAllConfirm"), { n: count })) : null,
2495
+ h("button", {
2496
+ className: "dph_btn" + (asked ? " dph_btnPrimary" : ""),
2497
+ key: "btn",
2498
+ type: "button",
2499
+ disabled: busyElsewhere,
2500
+ title: busyElsewhere ? t("install.busy") : "",
2501
+ onClick: () => {
2502
+ if (!asked) {
2503
+ setAsked(true);
2504
+ track("plugin_hub", { action: "set_install_ask", slug: set.slug || "", n: count });
2505
+ return;
2506
+ }
2507
+ setAsked(false);
2508
+ runSetInstall(set, t);
2509
+ },
2510
+ }, format(t("sets.installAll"), { n: count })),
2511
+ ]);
2512
+ }
2513
+
2514
+ /**
2515
+ * 「套装」视图:一整套方案(跨插件纵向组合)→ 槽位 → 批量命令。
2516
+ *
2517
+ * 与「分类精选」的分工:那边是同类**横向**最优(按小类导购),
2518
+ * 这里是**纵向**组合(回答"我这件整事该配哪一套")。
2519
+ *
2520
+ * 与分类精选同一条默认:大类/套装**默认全部收起**(2026-10-13 用户反馈),
2521
+ * 一屏列出所有方案,点哪个看哪个。
2522
+ *
2523
+ * ⚠️ 命令一个字都不在客户端拼:批量命令与逐条命令都由 host 用**本机 profile**
2524
+ * 拼好(`installBlock` / `item.cmd`)。客户端只负责展示与复制 —— 抄站点那份
2525
+ * 会把桌面用户装进 web profile(实测踩过)。
2526
+ */
2527
+ function renderSets(data, copiedCmd, onCopied) {
2528
+ if (!data) return null;
2529
+ const sets = Array.isArray(data.sets) ? data.sets : [];
2530
+ return sets.map((set, index) =>
2531
+ h("details", { className: "dph_bestCat", key: set.slug || String(index), open: false }, [
2532
+ h("summary", { className: "dph_bestCatHead", key: "head" }, [
2533
+ h("span", { key: "name" }, set.name),
2534
+ h("span", { className: "dph_bestCatCount", key: "count" }, format(t("sets.itemCount"), { n: set.itemCount || 0 })),
2535
+ ]),
2536
+ h("div", { className: "dph_bestSub", key: "body" }, [
2537
+ h("div", { className: "dph_bestSubHead", key: "lead" }, [
2538
+ h("span", { className: "dph_bestSubName", key: "sum" }, set.summary),
2539
+ set.audience ? h("span", { className: "dph_bestSubSum", key: "who", title: set.audience }, set.audience) : null,
2540
+ ]),
2541
+ /* 风险徽标:站点给的是结论(自动扫描优先),没结论就没有这条 —— 与页面同口径 */
2542
+ set.risk || set.syncedMonth
2543
+ ? h("div", { className: "dph_tags", key: "meta" }, [
2544
+ set.risk ? h("span", { className: "dph_tag" + (set.risk.level === "high" ? " dph_tagBad" : ""), key: "risk", title: set.risk.desc || "" }, set.risk.label) : null,
2545
+ set.syncedMonth && set.syncedSlots ? h("span", { className: "dph_tag", key: "sync" }, format(t("sets.synced"), { m: set.syncedMonth, s: set.syncedSlots })) : null,
2546
+ ])
2547
+ : null,
2548
+ h("div", { className: "dph_list", key: "list" }, (set.items || []).map((item) =>
2549
+ h("div", { className: "dph_setRow", key: item.fullName }, [
2550
+ h("span", { className: "dph_setRole", key: "role", title: item.slotRole || "" }, item.slotRole || ""),
2551
+ h("span", { className: "dph_setName", key: "name" }, item.nameZh || item.name || item.fullName || ""),
2552
+ h("span", { className: "dph_tag", key: "need" }, t("need." + (item.need || "enhance"))),
2553
+ item.installed
2554
+ ? h("span", { className: "dph_tag dph_tagOk", key: "inst" }, format(t("card.installed"), { v: item.installed }))
2555
+ : h("span", { className: "dph_stars", key: "stars" }, format(t("badge.stars"), { n: item.stars })),
2556
+ ]),
2557
+ )),
2558
+ h("div", { className: "dph_logCmd", key: "install" }, h(SetInstallButton, { set: set })),
2559
+ set.installBlock
2560
+ ? h("div", { className: "dph_cmdWrap", key: "block" }, [
2561
+ h("div", { className: "dph_cmdRow", key: "row" }, [
2562
+ h("code", { className: "dph_cmd dph_cmdBlock", key: "code" }, set.installBlock),
2563
+ h("button", {
2564
+ className: "dph_btn",
2565
+ key: "copy",
2566
+ type: "button",
2567
+ onClick: () => copyText(set.installBlock, () => {
2568
+ onCopied(set.installBlock);
2569
+ track("copy_install", { cmd: set.installBlock, pkg: "" });
2570
+ track("plugin_hub", { action: "set_copy", slug: set.slug || "" });
2571
+ }),
2572
+ }, copiedCmd === set.installBlock ? t("action.copied") : t("action.copy")),
2573
+ ]),
2574
+ h("span", { className: "dph_instHint", key: "hint" }, t("sets.batchHint")),
2575
+ ])
2576
+ : null,
2577
+ set.conflictNote
2578
+ ? h("div", { className: "dph_setHint dph_instBad", key: "conflict" }, t("sets.conflict") + ":" + set.conflictNote)
2579
+ : null,
2580
+ set.url
2581
+ ? h("a", { className: "dph_btn", key: "site", href: set.url, target: "_blank", rel: "noopener noreferrer", onClick: () => track("plugin_hub", { action: "set_site", slug: set.slug || "" }) }, t("sets.detail"))
2582
+ : null,
2583
+ ]),
2584
+ ]),
2585
+ );
2586
+ }
2587
+
2588
+ /**
2589
+ * 「对比」—— 把候选并排看关键事实(服务"内容评测"那条差异化在客户端的形态)。
2590
+ *
2591
+ * 为什么值得做:此前只有单张卡片,用户要在 A 和 B 之间选时只能来回滚、靠记忆比。
2592
+ * 这张表把「能据此做决定」的几件事并排放。**一行只放事实,不放评价** ——
2593
+ * 评价(深度评测、对比结论)是站点的活,客户端负责让人当场看得清。
2594
+ */
2595
+ function CompareTable(props) {
2596
+ const list = useHub().compare || [];
2597
+ if (list.length < 2) return null;
2598
+ const rows = [
2599
+ { key: "stars", label: t("compare.stars"), value: (item) => format(t("badge.stars"), { n: item.stars }) },
2600
+ { key: "verify", label: t("compare.verify"), value: (item) => (item.tested ? t("compare.tested") : item.verify ? t("compare.verified") : t("compare.unverified")) },
2601
+ { key: "installed", label: t("compare.installed"), value: (item) => (item.installed ? format(t("card.installed"), { v: item.installed }) : t("compare.notInstalled")) },
2602
+ { key: "cat", label: t("compare.cat"), value: (item) => item.cat || "—" },
2603
+ { key: "sell", label: t("compare.sell"), value: (item) => item.sell || "—" },
2604
+ ];
2605
+ const cells = (head, render) => [h("span", { className: "dph_cmpCell dph_cmpLabel", key: "label" }, head)]
2606
+ .concat(list.map((item) => render(item)));
2607
+ return h("div", { className: "dph_cmp", key: "cmp" }, [
2608
+ h("div", { className: "dph_cmpRow", key: "head" }, cells("", (item) => h(
2609
+ "span",
2610
+ { className: "dph_cmpCell dph_cmpName", key: compareKey(item), title: String(item.fullName || "") },
2611
+ item.nameZh || item.name || item.fullName || "",
2612
+ ))),
2613
+ ...rows.map((row) => h("div", { className: "dph_cmpRow", key: row.key }, cells(row.label, (item) => h(
2614
+ "span",
2615
+ { className: "dph_cmpCell", key: compareKey(item) },
2616
+ String(row.value(item)),
2617
+ )))),
2618
+ h("div", { className: "dph_cmpRow", key: "cmd" }, cells(t("compare.install"), (item) => h(
2619
+ "span",
2620
+ { className: "dph_cmpCell", key: compareKey(item) },
2621
+ item.cmd
2622
+ ? h("button", {
2623
+ className: "dph_btn",
2624
+ key: "copy",
2625
+ type: "button",
2626
+ title: item.cmd,
2627
+ onClick: () => copyText(item.cmd, () => {
2628
+ props.markCopied(item.cmd);
2629
+ track("copy_install", { cmd: item.cmd, pkg: item.pkg || "" });
2630
+ track("plugin_hub", { action: "compare_copy" });
2631
+ }),
2632
+ }, props.copiedCmd === item.cmd ? t("action.copied") : t("action.copy"))
2633
+ : h("span", { className: "dph_updNote", key: "none" }, t("cmd.missing")),
2634
+ ))),
2635
+ ]);
2636
+ }
2637
+
2638
+ /** 对比条:只在选了东西时出现;少于 2 个开不了表(比一个东西没有意义)。 */
2639
+ function CompareBar(props) {
2640
+ const list = useHub().compare || [];
2641
+ if (list.length === 0) return null;
2642
+ const enough = list.length >= 2;
2643
+ return h("div", { className: "dph_cmpBar", key: "cmpBar" }, [
2644
+ h("span", { className: "dph_setHint", key: "n" }, format(t("compare.selected"), { n: list.length, max: COMPARE_MAX })),
2645
+ h("button", {
2646
+ className: "dph_btn" + (props.open ? " dph_btnPrimary" : ""),
2647
+ key: "go",
2648
+ type: "button",
2649
+ disabled: !enough,
2650
+ title: enough ? "" : t("compare.needTwo"),
2651
+ onClick: props.onToggle,
2652
+ }, props.open ? t("compare.hide") : t("compare.show")),
2653
+ h("button", {
2654
+ className: "dph_btn",
2655
+ key: "clear",
2656
+ type: "button",
2657
+ onClick: () => {
2658
+ setHub({ compare: [] });
2659
+ track("plugin_hub", { action: "compare_clear" });
2660
+ },
2661
+ }, t("compare.clear")),
2662
+ ]);
2663
+ }
2664
+
2665
+ function renderCard(item, copiedCmd, onCopied, compact, comparable) {
2666
+ const title = item.nameZh || item.name || item.fullName || "";
2667
+ const tags = tagsOf(item);
2668
+ // 卖点行:站点 tagline 经严格过滤后的结果;没有就不占位(宁可不显示,也不放英文原文或垃圾串)
2669
+ const sellRow = item.sell
2670
+ ? h("div", { className: "dph_sell", key: "sell" }, [
2671
+ h("span", { className: "dph_sellTag", key: "tag" }, t("label.sell")),
2672
+ h("span", { className: "dph_sellText", key: "text" }, item.sell),
2673
+ ])
2674
+ : null;
2675
+ // 描述:汉化正文优先;没有汉化才回落到英文原文,并明确标注
2676
+ const descRow = item.descZh
2677
+ ? h("p", { className: "dph_desc", key: "desc" }, item.descZh)
2678
+ : item.desc
2679
+ ? h("p", { className: "dph_desc", key: "desc" }, [
2680
+ h("span", { className: "dph_raw", key: "raw" }, item.desc),
2681
+ h("span", { className: "dph_tag", key: "unzh" }, t("label.untranslated")),
2682
+ ])
2683
+ : null;
2684
+ const cmdRow = item.cmd
2685
+ ? h("div", { className: "dph_cmdWrap", key: "cmd" }, [
2686
+ h("div", { className: "dph_cmdRow", key: "row" }, [
2687
+ // 未发布到 npm 时标明来源 —— 站点详情页也是这么标注的,两处用词保持一致
2688
+ item.src === "repo"
2689
+ ? h("span", { className: "dph_tag", key: "src" }, t("label.repoSource"))
2690
+ : null,
2691
+ h("code", { className: "dph_cmd", key: "code" }, item.cmd),
2692
+ h("button", {
2693
+ className: "dph_btn",
2694
+ key: "copy",
2695
+ type: "button",
2696
+ onClick: () => copyText(item.cmd, () => {
2697
+ onCopied(item.cmd);
2698
+ // 与站点 InstallBlock 同口径:value 传整条命令
2699
+ track("copy_install", { cmd: item.cmd, pkg: item.pkg || "" });
2700
+ }),
2701
+ }, copiedCmd === item.cmd ? t("action.copied") : t("action.copy")),
2702
+ ]),
2703
+ item.src === "repo" ? h("div", { className: "dph_instHint", key: "hint" }, t("hint.repoSource")) : null,
2704
+ ])
2705
+ : h("div", { className: "dph_cmdMissing", key: "cmd" }, t("cmd.missing"));
2706
+
2707
+ return h("div", { className: "dph_card" + (compact ? " dph_cardSm" : ""), key: item.fullName || title }, [
2708
+ h("div", { className: "dph_cardTop", key: "top" }, [
2709
+ /* comparable = 这张卡片支持"选择类动作"(对比 + 收藏)。两处都放最左:
2710
+ 多选/收藏的第一列位置固定,扫一眼就知道能选;第二列才是插件名。 */
2711
+ comparable ? h("button", {
2712
+ className: "dph_btn" + (inCompare(item) ? " dph_btnPrimary" : ""),
2713
+ key: "cmp",
2714
+ type: "button",
2715
+ title: format(t("compare.toggle"), { max: COMPARE_MAX }),
2716
+ onClick: () => {
2717
+ /* 先读旧状态再改 —— toggleCompare 是同步写 hub,改完再判断就反了 */
2718
+ const was = inCompare(item);
2719
+ toggleCompare(item);
2720
+ track("plugin_hub", { action: was ? "compare_off" : "compare_on" });
2721
+ },
2722
+ }, inCompare(item) ? t("compare.picked") : t("compare.pick")) : null,
2723
+ comparable ? h("button", {
2724
+ className: "dph_btn" + (inFav(item) ? " dph_btnPrimary" : ""),
2725
+ key: "fav",
2726
+ type: "button",
2727
+ title: t("fav.toggle"),
2728
+ onClick: () => {
2729
+ const was = inFav(item);
2730
+ toggleFav(item);
2731
+ track("plugin_hub", { action: was ? "fav_off" : "fav_on" });
2732
+ },
2733
+ }, inFav(item) ? t("fav.added") : t("fav.add")) : null,
2734
+ h("span", { className: "dph_name", key: "name" }, title),
2735
+ item.owner ? h("span", { className: "dph_owner", key: "owner" }, "@" + item.owner) : null,
2736
+ h("span", { className: "dph_spacer", key: "gap" }),
2737
+ h("span", { className: "dph_stars", key: "stars" }, format(t("badge.stars"), { n: item.stars })),
2738
+ item.url
2739
+ ? h("a", { className: "dph_btn", key: "link", href: item.url, target: "_blank", rel: "noopener noreferrer" }, "GitHub")
2740
+ : null,
2741
+ ]),
2742
+ tags.length ? h("div", { className: "dph_tags", key: "tags" }, tags) : null,
2743
+ /* 已经装过就直说 —— 实测有用户对着一个早就装好的插件反复点「安装」,
2744
+ 然后判定"安装不成功"(他无从知道那东西其实已经在跑了)。 */
2745
+ item.installed ? h("div", { className: "dph_tags", key: "installed" }, h("span", { className: "dph_tag dph_tagOk" }, format(t("card.installed"), { v: item.installed }))) : null,
2746
+ sellRow,
2747
+ descRow,
2748
+ h(InstallRow, { item: item, key: "install" }),
2749
+ cmdRow,
2750
+ ]);
2751
+ }
2752
+
2753
+ function Notice(props) {
2754
+ return h("div", { className: "dph_notice" + (props.kind === "bad" ? " dph_noticeBad" : "") }, props.text);
2755
+ }
2756
+
2757
+ /**
2758
+ * 「今日推荐」卡片 —— 浮窗、页签与「每日推荐」视图共用同一个组件。
2759
+ *
2760
+ * 三态都要给出交代,不能只是"没渲染":取数中 → 显示加载语;
2761
+ * 出错/数据为空 → 明确说「暂不可用」。因为这张卡片出现在默认视图顶部,
2762
+ * 它是最先被看到的位置,悄悄消失会让人以为功能坏了。
2763
+ *
2764
+ * 内层复用 renderCard(同一个插件的呈现只有一份实现),
2765
+ * 本组件只负责上面那行「今日 + 日期 + 所属小类」的抬头与上榜理由。
2766
+ */
2767
+ function dailyCard(best, copiedCmd, onCopied, opts) {
2768
+ const picked = best.state.data ? pickDaily(best.state.data, opts.dateKey) : null;
2769
+ /* 窄面板里默认**收成一行**(调用方给 opts.collapsed + opts.toggle):
2770
+ 实测浮动面板 max-height 只有 min(72vh, 620px),而完整的今日推荐卡约 350px
2771
+ 且 flex:none 不收缩 —— 结果区被压到只剩一小条,用户的说法是
2772
+ 「今日推荐的置顶遮挡,导致其他的插件看不到了」。收起时"今天是谁"仍留在标题行。 */
2773
+ const collapsible = typeof opts.toggle === "function";
2774
+ const head = h("div", { className: "dph_dailyHead", key: "head" }, [
2775
+ h("span", { className: "dph_dailyTag", key: "tag" }, t("daily.title")),
2776
+ h("span", { className: "dph_dailyDate", key: "date" }, opts.dateKey),
2777
+ opts.collapsed && picked ? h("span", { className: "dph_updName", key: "who" }, String(picked.item.nameZh || picked.item.name || picked.item.fullName || "")) : null,
2778
+ opts.collapsed && picked && picked.item.installed ? h("span", { className: "dph_tag dph_tagOk", key: "inst" }, format(t("card.installed"), { v: picked.item.installed })) : null,
2779
+ h("span", { className: "dph_spacer", key: "gap" }),
2780
+ picked
2781
+ ? h("span", { className: "dph_dailyPath", key: "path" }, [picked.cat, picked.sub].filter(Boolean).join(" › "))
2782
+ : null,
2783
+ collapsible && picked
2784
+ ? h("button", { className: "dph_btn", key: "toggle", type: "button", onClick: opts.toggle }, t(opts.collapsed ? "daily.expand" : "daily.collapse"))
2785
+ : null,
2786
+ ]);
2787
+ if (!picked) {
2788
+ return h("div", { className: "dph_daily", key: "daily" }, [
2789
+ head,
2790
+ h("div", { className: "dph_instMsg", key: "msg" }, best.state.error ? t("daily.empty") : t("daily.loading")),
2791
+ ]);
2792
+ }
2793
+ if (opts.collapsed) return h("div", { className: "dph_daily", key: "daily" }, [head]);
2794
+ return h("div", { className: "dph_daily", key: "daily" }, [
2795
+ head,
2796
+ renderCard(picked.item, copiedCmd, onCopied, true),
2797
+ picked.item.reason
2798
+ ? h("p", { className: "dph_dailyWhy", key: "why" }, t("daily.why") + ":" + picked.item.reason)
2799
+ : null,
2800
+ h("div", { className: "dph_setHint", key: "hint" }, t("daily.hint")),
2801
+ ]);
2802
+ }
2803
+
2804
+ /**
2805
+ * 「待重启」横幅 —— 本地通道安装/升级成功后的激活闭环(2026-10-13)。
2806
+ *
2807
+ * 为什么是横幅而不是行内按钮:行内提示跟着卡片走,用户切个视图、装第二个
2808
+ * 插件就看不见了;而「装了没启用」正是实装验证率最大的漏点(桌面 profile
2809
+ * 实测没有 dshmarket,安装全走本地通道、必须重启)。所以它挂在面板与页签
2810
+ * 顶部,跨视图、跨会话存在,直到重启生效或用户明确说「知道了」。
2811
+ *
2812
+ * 挂载时向宿主要 startedAt(/api/dpharness/meta):它比 pending.at 新,
2813
+ * 说明重启已经发生过 —— 这时该说「已生效」而不是继续催重启。取不到就按
2814
+ * 「还没重启」处理:宁可多提醒一次,也不能把提醒悄悄吞掉。
2815
+ */
2816
+ function RestartBanner(props) {
2817
+ const pending = useHub().restartPending;
2818
+ const scope = props && props.scope ? props.scope : "panel";
2819
+ const [armed, setArmed] = react.useState(false);
2820
+ const [restarting, setRestarting] = react.useState(false);
2821
+ const [failed, setFailed] = react.useState(false);
2822
+ const [effective, setEffective] = react.useState(false);
2823
+ react.useEffect(() => {
2824
+ if (!pending) return undefined;
2825
+ let alive = true;
2826
+ /* 先按「需要重启」算:新的待重启(又装了一个)不能沿用上一次的「已生效」 */
2827
+ setEffective(false);
2828
+ getJson("/api/dpharness/meta")
2829
+ .then((body) => {
2830
+ if (!alive || !body) return;
2831
+ setEffective(typeof body.startedAt === "number" && body.startedAt > pending.at);
2832
+ })
2833
+ .catch(() => {});
2834
+ return () => { alive = false; };
2835
+ }, [pending]);
2836
+ if (!pending) return null;
2837
+ const names = pending.names;
2838
+ const label = names.length <= 2 ? names.join("、") : names.slice(0, 2).join("、") + " 等 " + names.length + " 个";
2839
+ const dismiss = (key) => h("button", {
2840
+ className: "dph_btn",
2841
+ key: key,
2842
+ type: "button",
2843
+ onClick: () => {
2844
+ track("plugin_hub", { action: "restart_ack", scope: scope });
2845
+ clearRestartPending();
2846
+ },
2847
+ }, t("install.dismiss"));
2848
+ if (effective) {
2849
+ return h("div", { className: "dph_restart dph_restartOk", key: "restart" }, [
2850
+ h("span", { className: "dph_dailyTag", key: "tag" }, t("install.effective")),
2851
+ h("span", { className: "dph_restartText", key: "text" }, format(t("install.effectiveBody"), { n: label })),
2852
+ h("span", { className: "dph_logCmd", key: "cmds" }, dismiss("ok")),
2853
+ ]);
2854
+ }
2855
+ return h("div", { className: "dph_restart", key: "restart" }, [
2856
+ h("span", { className: "dph_dailyTag", key: "tag" }, t("install.pendingTag")),
2857
+ h("span", { className: "dph_restartText", key: "text" }, format(t("install.pendingBody"), { n: label })),
2858
+ h("span", { className: "dph_logCmd", key: "cmds" }, [
2859
+ armed ? h("span", { className: "dph_setHint", key: "warn" }, t("updates.restartConfirm")) : null,
2860
+ h("button", {
2861
+ className: "dph_btn dph_btnPrimary",
2862
+ key: "restart",
2863
+ type: "button",
2864
+ disabled: restarting,
2865
+ onClick: async () => {
2866
+ /* 两步确认:重启会掐断用户当前会话,与「更新」视图那条同一条规则 */
2867
+ if (!armed) {
2868
+ setArmed(true);
2869
+ track("plugin_hub", { action: "restart_ask", scope: scope });
2870
+ return;
2871
+ }
2872
+ setArmed(false);
2873
+ setRestarting(true);
2874
+ track("plugin_hub", { action: "restart_click", via: scope });
2875
+ const ok = await restartServer();
2876
+ setRestarting(false);
2877
+ if (!ok) {
2878
+ setFailed(true);
2879
+ track("plugin_hub", { action: "restart_failed", via: scope, why: "restart_http" });
2880
+ }
2881
+ },
2882
+ }, restarting ? t("install.running") : t("install.restart")),
2883
+ dismiss("dismiss"),
2884
+ failed ? h("span", { className: "dph_instMsg dph_instBad", key: "fail" }, t("install.restartFailed")) : null,
2885
+ ]),
2886
+ ]);
2887
+ }
2888
+
2889
+ /**
2890
+ * 设置 → 通用 里的一行:只放**最高频**的那一个开关(浮窗显隐)。
2891
+ *
2892
+ * 为什么这一行值得存在:浮窗是跨路由常驻的,被关掉之后用户最可能问的就是
2893
+ * 「我从哪儿再打开它」—— 设置里的这一行就是那个答案,且与页签底部、
2894
+ * 侧边栏按钮共用同一条写路径,不会出现三处状态不一致。
2895
+ */
2896
+ function SettingsFloatRow() {
2897
+ const state = useHub();
2898
+ return h("div", { className: "dph_setRow" }, [
2899
+ h("span", { className: "dph_setCol", key: "col" }, [
2900
+ h("span", { className: "dph_setLabel", key: "l" }, t("settings.float")),
2901
+ h("span", { className: "dph_setHint", key: "h" }, t("settings.floatHint")),
2902
+ ]),
2903
+ h("label", { className: "dph_tel", key: "sw" }, [
2904
+ h("input", {
2905
+ key: "box",
2906
+ type: "checkbox",
2907
+ checked: !state.hidden,
2908
+ onChange: (event) => setFloatVisible(event.target.checked, "settings"),
2909
+ }),
2910
+ h("span", { key: "t" }, state.hidden ? t("settings.off") : t("settings.on")),
2911
+ ]),
2912
+ ]);
2913
+ }
2914
+
2915
+ /**
2916
+ * 版本条目列表 —— 设置页的「更新日志」节与浮窗的「更新」视图**共用同一份渲染**。
2917
+ * openIndex = 默认展开哪一条(0 = 最新一条;null = 全部收起)。
2918
+ */
2919
+ function changelogList(entries, prefix, openIndex) {
2920
+ return (Array.isArray(entries) ? entries : []).map((entry, index) => h("details", {
2921
+ className: "dph_log",
2922
+ key: prefix + (entry.version || String(index)),
2923
+ /* 最新一条默认展开:其余折叠,否则一屏全是历史 */
2924
+ open: openIndex !== null && index === openIndex,
2925
+ }, [
2926
+ h("summary", { className: "dph_logHead", key: "head" }, [
2927
+ h("span", { className: "dph_logVer", key: "v" }, "v" + (entry.version || "")),
2928
+ entry.date ? h("span", { className: "dph_logDate", key: "d" }, entry.date) : null,
2929
+ h("span", { className: "dph_logTitle", key: "t" }, entry.title || ""),
2930
+ ]),
2931
+ (entry.items || []).length
2932
+ ? h("ul", { className: "dph_logItems", key: "items" }, entry.items.map((line, i) => h("li", { key: String(i) }, line)))
2933
+ : h("div", { className: "dph_logItems", key: "empty" }, t("changelog.noItems")),
2934
+ ]));
2935
+ }
2936
+
2937
+ /**
2938
+ * 「更新日志」**块**(浮窗「更新」视图用)。
2939
+ *
2940
+ * 默认**收起成一行**:这个视图的主任务是"该升哪些",日志是参考信息 ——
2941
+ * 一进来就铺开会把升级列表挤到屏幕外;收起的摘要行仍能看出最新一版是什么。
2942
+ */
2943
+ function changelogBlock(entries, prefix) {
2944
+ const list = Array.isArray(entries) ? entries : [];
2945
+ if (list.length === 0) return null;
2946
+ const newest = list[0] || {};
2947
+ return h("details", { className: "dph_log", key: prefix + "log" }, [
2948
+ h("summary", { className: "dph_logHead", key: "head" }, [
2949
+ h("span", { className: "dph_logVer", key: "label" }, t("changelog.title")),
2950
+ h("span", { className: "dph_logDate", key: "v" }, "v" + String(newest.version || "")),
2951
+ h("span", { className: "dph_logTitle", key: "title" }, newest.title || ""),
2952
+ ]),
2953
+ h("div", { className: "dph_logNest", key: "body" }, changelogList(list, prefix + ":", 0)),
2954
+ ]);
2955
+ }
2956
+
2957
+ /**
2958
+ * 设置页里的「更新日志」一节。
2959
+ *
2960
+ * 三件事一起给,缺一件就不好用:
2961
+ * ① 我装的是哪个版本(current,来自 host 的代码常量);
2962
+ * ② 有没有更新的版本(outdated 是三态:true / false / 未知);
2963
+ * ③ 有的话怎么升(upgrade 命令,profile 已按本机填好,点一下复制)。
2964
+ * 只有 ② 明确为 true 时才谈 ③ ——「未知」时把命令摊出来,只会让人怀疑是不是网络出问题。
2965
+ */
2966
+ function changelogSection(cl, pending) {
2967
+ const data = cl.state.data;
2968
+ if (!data) {
2969
+ return h("div", { className: "dph_setGroup", key: "cl" }, [
2970
+ h("span", { className: "dph_dotWrap", key: "t" }, [
2971
+ h("span", { className: "dph_setTitle", key: "title" }, t("changelog.title")),
2972
+ pending.fresh ? updateDot() : null,
2973
+ ]),
2974
+ h("div", { className: "dph_setRow", key: "row" }, [
2975
+ h("span", { className: "dph_setHint", key: "h" }, cl.state.loading ? t("changelog.loading") : t("changelog.failed")),
2976
+ cl.state.loading ? null : h("button", { className: "dph_btn", key: "b", type: "button", onClick: cl.refresh }, t("action.refresh")),
2977
+ ]),
2978
+ cl.state.stale ? h("div", { className: "dph_setHint", key: "stale" }, t("host.stale")) : null,
2979
+ ]);
2980
+ }
2981
+ const entries = Array.isArray(data.entries) ? data.entries : [];
2982
+ const upgrade = typeof data.upgrade === "string" ? data.upgrade : "";
2983
+ return h("div", { className: "dph_setGroup", key: "cl" }, [
2984
+ h("div", { className: "dph_setRow", key: "head" }, [
2985
+ h("span", { className: "dph_setCol", key: "col" }, [
2986
+ h("span", { className: "dph_dotWrap", key: "l" }, [
2987
+ h("span", { className: "dph_setLabel", key: "label" }, t("changelog.title")),
2988
+ pending.fresh ? updateDot() : null,
2989
+ ]),
2990
+ h("span", { className: "dph_setHint", key: "h" }, format(t("changelog.current"), { v: data.current || "?" })),
2991
+ ]),
2992
+ data.outdated === true
2993
+ ? h("span", { className: "dph_tag dph_tagBad", key: "new" }, format(t("changelog.newAvailable"), { v: data.latest || "" }))
2994
+ : data.outdated === false
2995
+ ? h("span", { className: "dph_setState", key: "ok" }, t("changelog.upToDate"))
2996
+ : null,
2997
+ ]),
2998
+ data.outdated === true && upgrade
2999
+ ? h("div", { className: "dph_logCmd", key: "cmd" }, [
3000
+ h("code", { className: "dph_cmd", key: "code" }, upgrade),
3001
+ h("button", {
3002
+ className: "dph_btn dph_btnPrimary",
3003
+ key: "copy",
3004
+ type: "button",
3005
+ onClick: () => copyText(upgrade, () => {
3006
+ cl.markCopied(upgrade);
3007
+ track("plugin_hub", { action: "upgrade_copy", scope: "changelog" });
3008
+ }),
3009
+ }, cl.copiedCmd === upgrade ? t("action.copied") : t("changelog.copyUpgrade")),
3010
+ h("span", { className: "dph_setHint", key: "hint" }, t("changelog.hint")),
3011
+ ])
3012
+ : null,
3013
+ ...changelogList(entries, "cl:", 0),
3014
+ ]);
3015
+ }
3016
+
3017
+ /** 更新红点。只有颜色没有文字等于对读屏用户不存在,所以点里塞一段视觉隐藏文案。 */
3018
+ function updateDot() {
3019
+ return h("span", { className: "dph_dot", key: "dot", title: t("updates.dot") }, h("span", { className: "dph_sr" }, t("updates.dot")));
3020
+ }
3021
+
3022
+ /**
3023
+ * 一行的结论。三态必须三句话:可升级(带复制命令)/已是最新/查不到 ——
3024
+ * 把「查不到」显示成「已是最新」是本插件明确禁止的那类错误。
3025
+ */
3026
+ /**
3027
+ * 「更新」视图的一行。
3028
+ *
3029
+ * **中文名优先、包名靠后**:用户判断"该不该升"靠的是认得出这是谁,而
3030
+ * `dsh-context` 这种包名对人没有信息量(实测:20 个已装插件的名字里,
3031
+ * 只有本机 locale 与站点目录的并集才覆盖全)。缺中文名时显示包名并标注
3032
+ * 「未汉化」——与卡片同一口径,绝不假装有中文。
3033
+ */
3034
+ /* ---- 使用频次与保留价值(宿主下发 tier + usage;这里只做展示与筛选) ---- */
3035
+
3036
+ /** tier → 本地化标签(未知 tier 返回空串,不显示、不猜)。 */
3037
+ function tierLabel(tier) {
3038
+ const keys = { core: "usage.core", common: "usage.common", occasional: "usage.occasional", silent: "usage.silent", disabled: "usage.disabled", unmeasurable: "usage.unmeasurable", unknown: "usage.unknown" };
3039
+ return keys[tier] ? t(keys[tier]) : "";
3040
+ }
3041
+
3042
+ /** 上次使用时间的人话(今天 / 昨天 / N 天前)。 */
3043
+ function usageDaysText(ms) {
3044
+ const at = Number(ms) || 0;
3045
+ if (!at) return "";
3046
+ const days = Math.floor((Date.now() - at) / 86400000);
3047
+ if (days <= 0) return t("usage.today");
3048
+ if (days === 1) return t("usage.yesterday");
3049
+ return format(t("usage.daysAgo"), { d: days });
3050
+ }
3051
+
3052
+ /** 行内副标题里追加的使用情况(没有可说的就不加,保持安静)。 */
3053
+ function usageSubLines(item) {
3054
+ const tier = item && item.tier;
3055
+ const u = item && item.usage;
3056
+ if (tier === "unknown") return [t("usage.unknownNote")];
3057
+ if (tier === "unmeasurable") return [t("usage.unmeasurableNote")];
3058
+ if (u && u.measurable) {
3059
+ return u.calls > 0
3060
+ ? [format(t("usage.stats"), { n: u.calls, d: usageDaysText(u.lastUsedMs) })]
3061
+ : [t("usage.silentNote")];
3062
+ }
3063
+ return [];
3064
+ }
3065
+
3066
+ /** 汇总行:「近 30 天:核心 4 · 常用 6 …」(宿主给了窗口天数就用它)。 */
3067
+ function usageSummaryText(rows, meta) {
3068
+ const count = { core: 0, common: 0, occasional: 0, silent: 0, unmeasurable: 0 };
3069
+ (Array.isArray(rows) ? rows : []).forEach((item) => {
3070
+ const tier = item && item.tier;
3071
+ if (tier && count[tier] !== undefined) count[tier] += 1;
3072
+ });
3073
+ const days = meta && meta.windowDays ? meta.windowDays : 30;
3074
+ return format(t("usage.summary"), { d: days, a: count.core, b: count.common, c: count.occasional, e: count.silent, f: count.unmeasurable });
3075
+ }
3076
+
3077
+ /** 排序与筛选(纯函数):默认序 = 宿主顺序;usage = 按近 30 天调用数降序,未度量排后。 */
3078
+ function applyUsageView(rows, sortMode, onlySuggest) {
3079
+ let list = Array.isArray(rows) ? rows.slice() : [];
3080
+ if (onlySuggest) {
3081
+ list = list.filter((item) => {
3082
+ const tier = item && item.tier;
3083
+ return (tier === "silent" || tier === "disabled") && !isKept(item && item.name);
3084
+ });
3085
+ }
3086
+ if (sortMode === "usage") {
3087
+ list.sort((a, b) => {
3088
+ const ca = a && a.usage && typeof a.usage.calls === "number" ? a.usage.calls : -1;
3089
+ const cb = b && b.usage && typeof b.usage.calls === "number" ? b.usage.calls : -1;
3090
+ if (cb !== ca) return cb - ca;
3091
+ return String((a && a.name) || "").localeCompare(String((b && b.name) || ""));
3092
+ });
3093
+ }
3094
+ return list;
3095
+ }
3096
+
3097
+ function updateRow(item, key, prefix, copied, mark, removable) {
3098
+ const nameZh = typeof item.nameZh === "string" ? item.nameZh.trim() : "";
3099
+ const note = typeof item.note === "string" ? item.note.trim() : "";
3100
+ const untranslated = !nameZh || (note !== "" && !/[\u4e00-\u9fff]/.test(note));
3101
+ /* 这一版被 dsh 的兼容性闸门拒过?只认**真实发生过**的拒绝,不做预判 */
3102
+ const blocked = item.outdated === true && updates.blocked.includes(String(item.name) + "@" + String(item.latest || ""));
3103
+ /* 清单里写死版本(0.5.27 这种)—— plugin add 挪不动它,直接说清,免得用户反复点 */
3104
+ const pinned = item.kind === "pinned";
3105
+ /* 使用频次与保留(tier 由宿主下发;kept 只对本机已装行生效) */
3106
+ const tier = typeof item.tier === "string" ? item.tier : "";
3107
+ const kept = removable ? isKept(item.name) : false;
3108
+ const sub = [];
3109
+ if (note) sub.push(note);
3110
+ /* 有中文名时,包名挪到第二行(用户要靠它去搜/核对);没有中文名时它已在第一行 */
3111
+ if (nameZh) sub.push(String(item.name));
3112
+ if (pinned) sub.push(format(t("updates.pinnedNote"), { v: String(item.current || "") }));
3113
+ usageSubLines(item).forEach((line) => sub.push(line));
3114
+ return h("div", { className: "dph_updItem" + (item.outdated === true ? " dph_updOn" : ""), key: key }, [
3115
+ h("div", { className: "dph_upd", key: "row" }, [
3116
+ h("span", { className: "dph_updName", key: "n" }, (prefix ? prefix + " · " : "") + (nameZh || String(item.name))),
3117
+ untranslated ? h("span", { className: "dph_tag", key: "raw" }, t("label.untranslated")) : null,
3118
+ blocked ? h("span", { className: "dph_tag", key: "blocked" }, t("updates.blocked")) : null,
3119
+ pinned ? h("span", { className: "dph_tag", key: "pinned" }, t("updates.pinned")) : null,
3120
+ tier ? h("span", { className: "dph_tag", key: "usage" }, tierLabel(tier)) : null,
3121
+ h("span", { className: "dph_updVer", key: "v" }, "v" + String(item.current || "?") + (item.outdated === true ? " → v" + String(item.latest || "") : "")),
3122
+ h("span", { className: "dph_spacer", key: "gap" }),
3123
+ updateVerdict(item, key, copied, mark),
3124
+ /* 「保留」标注:人工高于机器 —— 标了就不再进清理建议;再点一次取消 */
3125
+ removable ? h("button", {
3126
+ className: "dph_btn",
3127
+ key: "keep",
3128
+ type: "button",
3129
+ title: t("usage.keepHint"),
3130
+ onClick: () => {
3131
+ const on = !kept;
3132
+ toggleKeep(item.name);
3133
+ track("plugin_hub", { action: "keep_toggle", on: on, scope: "updates" });
3134
+ },
3135
+ }, kept ? t("usage.kept") : t("usage.keep")) : null,
3136
+ /* 启用/禁用:可逆的「观察」动作(宿主提供启停能力时才有这一项) */
3137
+ removable && typeof item.enabled === "boolean" ? h(ToggleButton, { key: "toggle", item: item }) : null,
3138
+ /* 卸载入口:与"该不该升"并排。破坏性操作,自己带两步确认;
3139
+ 本插件自己那一行不给(卸自己等于把管理界面卸掉)。 */
3140
+ removable ? h(RemoveButton, { key: "remove", item: { pkg: String(item.name || ""), name: item.nameZh || String(item.name || "") } }) : null,
3141
+ ]),
3142
+ sub.length ? h("div", { className: "dph_updSub", key: "sub" }, sub.join(" · ")) : null,
3143
+ ]);
3144
+ }
3145
+
3146
+ /**
3147
+ * 「收藏待装」—— 先攒着,之后再一起装(本机偏好,跨会话)。
3148
+ *
3149
+ * 为什么放在「我的插件」而不是再开一个页签:① 浮窗只有 400px,第 6 个标签会把
3150
+ * 一排标签挤爆;② 语义也对 —— 这一屏本来就是"我这边的东西"(装了的 + 攒着的)。
3151
+ * 批量装复用「一键安装整套」那台机器(串行/进度/可中止/同一条两步确认),
3152
+ * 只是数据源从"一套方案"换成"我的收藏"。
3153
+ */
3154
+ function FavSection(props) {
3155
+ const state = useHub();
3156
+ const list = state.fav || [];
3157
+ const [asked, setAsked] = react.useState(false);
3158
+ if (list.length === 0) return null;
3159
+ const installed = props.installedNames || new Set();
3160
+ /* 能批量装的 = 有 npm 包名(pkg)且本机还没装 —— 没有 pkg 的走逐条复制命令那条路 */
3161
+ const pending = list.filter((item) => item.pkg && !installed.has(String(item.pkg)));
3162
+ return h("div", { className: "dph_setGroup", key: "fav" }, [
3163
+ h("div", { className: "dph_setRow", key: "head" }, [
3164
+ h("span", { className: "dph_setCol", key: "col" }, [
3165
+ h("span", { className: "dph_setLabel", key: "l" }, format(t("fav.count"), { n: list.length })),
3166
+ h("span", { className: "dph_setHint", key: "h" }, t("fav.hint")),
3167
+ ]),
3168
+ ]),
3169
+ ...list.map((item) => h("div", { className: "dph_updSub", key: favKey(item) }, [
3170
+ h("span", { key: "n" }, item.nameZh || item.name || item.fullName || ""),
3171
+ item.cmd
3172
+ ? h("button", {
3173
+ className: "dph_btn",
3174
+ key: "copy",
3175
+ type: "button",
3176
+ title: item.cmd,
3177
+ onClick: () => copyText(item.cmd, () => {
3178
+ props.markCopied(item.cmd);
3179
+ track("copy_install", { cmd: item.cmd, pkg: item.pkg || "" });
3180
+ track("plugin_hub", { action: "fav_copy" });
3181
+ }),
3182
+ }, props.copiedCmd === item.cmd ? t("action.copied") : t("action.copy"))
3183
+ : null,
3184
+ h("button", {
3185
+ className: "dph_btn",
3186
+ key: "rm",
3187
+ type: "button",
3188
+ onClick: () => {
3189
+ toggleFav(item);
3190
+ track("plugin_hub", { action: "fav_off", scope: "list" });
3191
+ },
3192
+ }, t("fav.remove")),
3193
+ ])),
3194
+ pending.length >= 2
3195
+ ? h("span", { className: "dph_logCmd", key: "installAll" }, [
3196
+ asked ? h("span", { className: "dph_setHint", key: "warn" }, format(t("fav.installConfirm"), { n: pending.length })) : null,
3197
+ h("button", {
3198
+ className: "dph_btn" + (asked ? " dph_btnPrimary" : ""),
3199
+ key: "go",
3200
+ type: "button",
3201
+ disabled: Boolean(state.batch && state.batch.active),
3202
+ onClick: () => {
3203
+ if (!asked) {
3204
+ setAsked(true);
3205
+ track("plugin_hub", { action: "fav_install_ask", n: pending.length });
3206
+ return;
3207
+ }
3208
+ setAsked(false);
3209
+ /* 复用「一键安装整套」那台机器:slug 用内部保留值,界面不会误认成套装的进度 */
3210
+ runSetInstall({ slug: "__fav__", name: t("fav.title"), items: pending }, t);
3211
+ },
3212
+ }, format(t("fav.installAll"), { n: pending.length })),
3213
+ ])
3214
+ : null,
3215
+ ]);
3216
+ }
3217
+
3218
+ /**
3219
+ * 卸载按钮 —— 破坏性操作,两步确认(与安装/重启同一条规则)。
3220
+ *
3221
+ * 为什么放在「更新」视图:这个视图本来就是"我已装的这些插件"的清单;
3222
+ * 用户在这儿看到某个插件不想要了,最自然的动作就是当场卸掉 ——
3223
+ * 让他为了卸载再开一个终端、再抄一遍包名,等于把他推回命令行。
3224
+ */
3225
+ function RemoveButton(props) {
3226
+ const item = props.item;
3227
+ const state = useHub();
3228
+ const [confirming, setConfirming] = react.useState(false);
3229
+ const job = state.install;
3230
+ const mine = job && job.verb === "remove" && job.target === item.pkg;
3231
+ if (mine && job.active) {
3232
+ return h("span", { className: "dph_instMsg", key: "rm" }, job.message);
3233
+ }
3234
+ if (mine && job.phase === "okLocal") {
3235
+ return h("span", { className: "dph_instMsg dph_instOk", key: "rm" }, t("updates.removed") + " · " + t("updates.removedRestart"));
3236
+ }
3237
+ if (mine && job.phase === "failed") {
3238
+ return h("span", { className: "dph_instMsg dph_instBad", key: "rm" }, job.message || t("install.failed"));
3239
+ }
3240
+ if (confirming) {
3241
+ return h("span", { className: "dph_logCmd", key: "rm" }, [
3242
+ h("button", {
3243
+ className: "dph_btn",
3244
+ key: "go",
3245
+ type: "button",
3246
+ onClick: () => { setConfirming(false); runRemove(item, t); },
3247
+ }, t("updates.removeConfirm")),
3248
+ h("button", {
3249
+ className: "dph_btn",
3250
+ key: "cancel",
3251
+ type: "button",
3252
+ onClick: () => { setConfirming(false); track("plugin_hub", { action: "remove_cancel" }); },
3253
+ }, t("install.cancel")),
822
3254
  ]);
823
3255
  }
3256
+ return h("button", {
3257
+ className: "dph_btn",
3258
+ key: "rm",
3259
+ type: "button",
3260
+ title: item.pkg || "",
3261
+ onClick: () => { setConfirming(true); track("plugin_hub", { action: "remove_ask" }); },
3262
+ }, t("updates.remove"));
3263
+ }
824
3264
 
3265
+ /**
3266
+ * 启用 / 禁用 —— 「先停用观察」的出口(v0.6.0)。
3267
+ *
3268
+ * 与卸载的分工:卸载是破坏性的(改依赖清单、要重启);禁用是**可逆的**
3269
+ * (改本机 profile patch、即时应用、随时恢复)—— 对"拿不准要不要留"的插件,
3270
+ * 先禁用是唯一不后悔的动作。两步确认照旧;宿主不提供启停能力时不出这个按钮。
3271
+ */
3272
+ function ToggleButton(props) {
3273
+ const item = props.item;
3274
+ const [confirming, setConfirming] = react.useState(false);
3275
+ const [busy, setBusy] = react.useState(false);
3276
+ const [done, setDone] = react.useState("");
3277
+ const [failed, setFailed] = react.useState("");
3278
+ /* enabled=false 的行 → 目标是「启用」;其余(含 true)→ 「禁用」 */
3279
+ const want = item.enabled !== true;
3280
+ if (busy) return h("span", { className: "dph_instMsg", key: "tg" }, t("usage.toggling"));
3281
+ if (done) return h("span", { className: "dph_instMsg dph_instOk", key: "tg" }, done);
3282
+ if (failed) return h("span", { className: "dph_instMsg dph_instBad", key: "tg" }, failed);
825
3283
  if (confirming) {
826
- return h("div", { className: "dph_instRow" }, [
827
- h("span", { className: "dph_instHint", key: "hint" }, t("install.hint")),
3284
+ return h("span", { className: "dph_logCmd", key: "tg" }, [
828
3285
  h("button", {
829
- className: "dph_btn dph_btnPrimary",
3286
+ className: "dph_btn",
830
3287
  key: "go",
831
3288
  type: "button",
832
- onClick: () => {
3289
+ onClick: async () => {
833
3290
  setConfirming(false);
834
- runInstall(item, t);
3291
+ setBusy(true);
3292
+ track("plugin_hub", { action: "toggle", on: want, pkg: String(item.name || "") });
3293
+ const result = await postJson("/api/dpharness/toggle", { name: String(item.name || ""), enabled: want });
3294
+ setBusy(false);
3295
+ const body = (result && result.data) || {};
3296
+ if (result && result.status === 200 && body.ok === true && body.enabled === want) {
3297
+ setDone(want ? t("usage.enabledDone") : t("usage.disabledDone"));
3298
+ loadUpdates(true);
3299
+ return;
3300
+ }
3301
+ if (body.code === "unsupported") { setFailed(t("usage.toggleUnsupported")); return; }
3302
+ if (body.code === "self") { setFailed(t("usage.toggleSelf")); return; }
3303
+ if (body.code === "management-required") { setFailed(t("usage.toggleReadonly")); return; }
3304
+ if (body.code === "unaddressable" || body.code === "not-found" || body.code === "ambiguous") { setFailed(t("usage.toggleUnaddressable")); return; }
3305
+ if (body.overridden === true) { setFailed(t("usage.toggleOverridden")); loadUpdates(true); return; }
3306
+ setFailed(t("usage.toggleFailed") + (body.error ? ":" + String(body.error) : ""));
835
3307
  },
836
- }, t("install.confirm")),
3308
+ }, want ? t("usage.enableConfirm") : t("usage.disableConfirm")),
837
3309
  h("button", {
838
3310
  className: "dph_btn",
839
3311
  key: "cancel",
840
3312
  type: "button",
841
- onClick: () => {
842
- setConfirming(false);
843
- /* 取消单独记一次:只埋 install(确认后)的话,
844
- 「想装但被确认框劝退」的人会整段消失,
845
- 而他们恰恰是文案/门槛该优化的对象。 */
846
- track("plugin_hub", { action: "install_cancel", via: "confirm" });
847
- },
3313
+ onClick: () => { setConfirming(false); track("plugin_hub", { action: "toggle_cancel" }); },
848
3314
  }, t("install.cancel")),
849
3315
  ]);
850
3316
  }
3317
+ return h("button", {
3318
+ className: "dph_btn",
3319
+ key: "tg",
3320
+ type: "button",
3321
+ title: t("usage.toggleHint"),
3322
+ onClick: () => { setConfirming(true); track("plugin_hub", { action: "toggle_ask", on: want }); },
3323
+ }, want ? t("usage.enable") : t("usage.disable"));
3324
+ }
851
3325
 
852
- return h("div", { className: "dph_instRow" }, [
3326
+ /**
3327
+ * 一行的结论。三态必须三句话:可升级(一键升级 + 复制命令)/已是最新/查不到 ——
3328
+ * 把「查不到」显示成「已是最新」是本插件明确禁止的那类错误。
3329
+ */
3330
+ function updateVerdict(item, key, copied, mark) {
3331
+ if (!item || item.outdated === null) {
3332
+ return h("span", { className: "dph_updNote", key: key + ":unknown" }, t("updates.unknown"));
3333
+ }
3334
+ if (item.outdated !== true) {
3335
+ return h("span", { className: "dph_updNote", key: key + ":ok" }, t("updates.upToDate"));
3336
+ }
3337
+ if (isIgnored(item)) {
3338
+ /* 忽略记的是**具体目标版本**:出了更新的版本(latest 变了)提醒会自己回来 ——
3339
+ 所以这里显示"忽略了哪一版"并给取消,而不是一句模糊的「已忽略」。 */
3340
+ return h("span", { className: "dph_logCmd", key: key + ":ignored" }, [
3341
+ h("span", { className: "dph_updNote", key: "note" }, format(t("updates.ignored"), { v: String(item.latest || "") })),
3342
+ h("button", {
3343
+ className: "dph_btn",
3344
+ key: "undo",
3345
+ type: "button",
3346
+ onClick: () => {
3347
+ setIgnored(item.name, null);
3348
+ track("plugin_hub", { action: "ignore_off", pkg: String(item.name || "") });
3349
+ },
3350
+ }, t("updates.unignore")),
3351
+ ]);
3352
+ }
3353
+ return h("span", { className: "dph_logCmd", key: key + ":out" }, [
3354
+ h("span", { className: "dph_tag dph_tagBad", key: "tag" }, t("updates.outdated")),
3355
+ /* 一键升级**复用目录项那条安装通道**(二次确认 → 进度 → 失败原因 → 重启提示):
3356
+ 一条路径两处使用,行为才不会分叉。
3357
+ 目标用**具体版本号**(更新检查已经知道它)—— 实测 `@latest` 在 dsh 上会静默空转。 */
3358
+ h(InstallRow, { key: "do", item: { pkg: String(item.name) + "@" + String(item.latest), current: item.current }, kind: "upgrade" }),
853
3359
  h("button", {
854
- className: "dph_btn dph_btnPrimary",
855
- key: "install",
3360
+ className: "dph_btn",
3361
+ key: "copy",
856
3362
  type: "button",
857
- disabled: busyElsewhere,
858
- title: busyElsewhere ? t("install.busy") : item.pkg,
3363
+ title: item.upgrade || "",
3364
+ onClick: () => copyText(item.upgrade || "", () => {
3365
+ mark(item.upgrade || "");
3366
+ track("plugin_hub", { action: "upgrade_copy", scope: "updates" });
3367
+ }),
3368
+ }, copied === item.upgrade ? t("action.copied") : t("updates.copyCmd")),
3369
+ /* 「忽略此版本」:把"不打算升这一版"这个决定记下来,红点与列表都认它 ——
3370
+ 否则用户每次打开都被同一个红点提醒一遍,久了就学会无视红点(那才是真损失)。 */
3371
+ h("button", {
3372
+ className: "dph_btn",
3373
+ key: "ignore",
3374
+ type: "button",
3375
+ title: format(t("updates.ignoreHint"), { v: String(item.latest || "") }),
859
3376
  onClick: () => {
860
- setConfirming(true);
861
- track("plugin_hub", { action: "install_ask", via: "confirm" });
3377
+ setIgnored(item.name, item.latest);
3378
+ track("plugin_hub", { action: "ignore_on", pkg: String(item.name || ""), v: String(item.latest || "") });
862
3379
  },
863
- }, busyElsewhere ? t("install.busy") : t("install.action")),
864
- h("span", { className: "dph_instHint", key: "pkg" }, item.pkg),
3380
+ }, t("updates.ignore")),
865
3381
  ]);
866
3382
  }
867
3383
 
868
3384
  /**
869
- * 「分类精选」视图:大类(可折叠)→ 小类 → 条目。
3385
+ * 「更新」视图:本插件自身 + 已安装插件的更新清单,并**在这里直接升级**。
870
3386
  *
871
- * 与「严选推荐」的区别:那边是**可搜索的全量目录**(按你的关键词找),
872
- * 这边是**月度策展结果**(每小类只留 2~3 个),回答的是"按用途该装哪几个"。
873
- * 所以渲染上刻意保留两项元数据:
874
- * · rank —— 小类内名次,用户要知道"这是这个小类里最好的第几个";
875
- * · reason —— 上榜理由(如"实装验证通过 · 周下载 12.8 万"),
876
- * 这是"为什么是它"的依据,去掉就只是又一个列表。
3387
+ * 用户**看到清单即视为已确认** —— 红点在这里熄灭(与 check-updates 补丁同一思路:
3388
+ * 只有再出现比已确认版本更新的版本才会重新亮)。
877
3389
  */
878
- function renderBest(data, copiedCmd, onCopied) {
879
- if (!data) return null;
880
- const cats = Array.isArray(data.categories) ? data.categories : [];
881
- return cats.map((cat, index) =>
882
- h("details", { className: "dph_bestCat", key: cat.key || String(index), open: index === 0 }, [
883
- h("summary", { className: "dph_bestCatHead", key: "head" }, [
884
- h("span", { key: "name" }, cat.label),
885
- h(
886
- "span",
887
- { className: "dph_bestCatCount", key: "count" },
888
- format(t("best.catCount"), { subs: (cat.subs || []).length, n: cat.count || 0 }),
889
- ),
890
- ]),
891
- ...(cat.subs || []).map((sub) =>
892
- h("div", { className: "dph_bestSub", key: sub.key }, [
893
- h("div", { className: "dph_bestSubHead", key: "subHead" }, [
894
- h("span", { className: "dph_bestSubName", key: "n" }, sub.label),
895
- sub.summary
896
- ? h("span", { className: "dph_bestSubSum", key: "s", title: sub.summary }, sub.summary)
897
- : null,
898
- ]),
899
- h(
900
- "div",
901
- { className: "dph_list", key: "list" },
902
- (sub.items || []).map((item) =>
903
- h("div", { key: item.fullName, className: "dph_bestItem" }, [
904
- item.rank
905
- ? h("div", { className: "dph_bestRank", key: "rank" }, "#" + item.rank)
906
- : null,
907
- renderCard(item, copiedCmd, onCopied, true),
908
- item.reason
909
- ? h("div", { className: "dph_bestReason", key: "why" }, item.reason)
910
- : null,
911
- ]),
912
- ),
913
- ),
914
- ]),
915
- ),
916
- ]),
3390
+ function UpdateView(props) {
3391
+ const store = useUpdates();
3392
+ /* 更新日志也在这里用:用户要看"本插件自己更新了什么",不该被迫再跑一趟设置页 */
3393
+ const cl = useChangelog();
3394
+ /* 批量升级的进度挂在 hub 上(它要跨行显示),所以这里也要订阅 hub */
3395
+ const state = useHub();
3396
+ const [copied, setCopied] = react.useState("");
3397
+ /* 批量升级要两步:它一次会改十几个包,一键直落对真实用户太危险 */
3398
+ const [batchAsk, setBatchAsk] = react.useState(false);
3399
+ const [restartAsk, setRestartAsk] = react.useState(false);
3400
+ const [restarting, setRestarting] = react.useState(false);
3401
+ const [restartFailed, setRestartFailed] = react.useState(false);
3402
+ /* 使用视图:排序切换与「只看建议清理」筛选(本会话内有效,不持久) */
3403
+ const [sortMode, setSortMode] = react.useState("default");
3404
+ const [onlySuggest, setOnlySuggest] = react.useState(false);
3405
+ /* 批量禁用:本地状态驱动(不挤占安装批处理那台机器);stop 用 ref 传递中止信号。
3406
+ ⚠️ 变量名带 disable —— 上面的 `batchAsk` 是「批量升级」的,同名会直接语法错 */
3407
+ const [batchDisableAsk, setBatchDisableAsk] = react.useState(false);
3408
+ const [batchRun, setBatchRun] = react.useState(null);
3409
+ const batchStop = react.useRef(null);
3410
+ const data = store.data;
3411
+ /* 收藏区要知道哪些已经装了(用更新检查这份清单,不再多打一次请求) */
3412
+ const installedNames = new Set(
3413
+ (Array.isArray(data && data.plugins) ? data.plugins : [])
3414
+ .concat(data && data.self ? [data.self] : [])
3415
+ .map((item) => String((item && item.name) || ""))
3416
+ .filter(Boolean),
917
3417
  );
918
- }
919
-
920
- function renderCard(item, copiedCmd, onCopied, compact) {
921
- const title = item.nameZh || item.name || item.fullName || "";
922
- const tags = tagsOf(item);
923
- // 卖点行:站点 tagline 经严格过滤后的结果;没有就不占位(宁可不显示,也不放英文原文或垃圾串)
924
- const sellRow = item.sell
925
- ? h("div", { className: "dph_sell", key: "sell" }, [
926
- h("span", { className: "dph_sellTag", key: "tag" }, t("label.sell")),
927
- h("span", { className: "dph_sellText", key: "text" }, item.sell),
928
- ])
929
- : null;
930
- // 描述:汉化正文优先;没有汉化才回落到英文原文,并明确标注
931
- const descRow = item.descZh
932
- ? h("p", { className: "dph_desc", key: "desc" }, item.descZh)
933
- : item.desc
934
- ? h("p", { className: "dph_desc", key: "desc" }, [
935
- h("span", { className: "dph_raw", key: "raw" }, item.desc),
936
- h("span", { className: "dph_tag", key: "unzh" }, t("label.untranslated")),
3418
+ const scope = props && props.scope ? props.scope : "tab";
3419
+ react.useEffect(() => {
3420
+ if (data) ackUpdates(scope);
3421
+ }, [data]);
3422
+ const mark = react.useCallback((text) => {
3423
+ setCopied(text);
3424
+ setTimeout(() => setCopied((current) => (current === text ? "" : current)), 2000);
3425
+ }, []);
3426
+ /* 两处需要重启出口(接口没注册 / 批量升级装完),共用同一个按钮;
3427
+ key 同时当埋点的 scope,调用点一眼能看出语境。 */
3428
+ function restartButton(key) {
3429
+ return h("span", { className: "dph_logCmd", key: key }, [
3430
+ /* 两步确认:重启会掐断用户当前的会话,不该一键直落 */
3431
+ restartAsk ? h("span", { className: "dph_setHint", key: "warn" }, t("updates.restartConfirm")) : null,
3432
+ h("button", {
3433
+ className: "dph_btn dph_btnPrimary",
3434
+ key: "btn",
3435
+ type: "button",
3436
+ disabled: restarting,
3437
+ onClick: async () => {
3438
+ if (!restartAsk) {
3439
+ setRestartAsk(true);
3440
+ track("plugin_hub", { action: "restart_ask", scope: key });
3441
+ return;
3442
+ }
3443
+ setRestartAsk(false);
3444
+ setRestarting(true);
3445
+ /* 点击即上报:成功的重启会掐断这个请求,
3446
+ 「重启成功」只能由下次加载时的 post_install 证明。 */
3447
+ track("plugin_hub", { action: "restart_click", via: key });
3448
+ const ok = await restartServer();
3449
+ setRestarting(false);
3450
+ if (!ok) {
3451
+ setRestartFailed(true);
3452
+ track("plugin_hub", { action: "restart_failed", via: key, why: "restart_http" });
3453
+ }
3454
+ },
3455
+ }, restarting ? t("install.running") : t("install.restart")),
3456
+ restartFailed ? h("span", { className: "dph_instMsg dph_instBad", key: "fail" }, t("install.failed")) : null,
3457
+ ]);
3458
+ }
3459
+ const head = h("div", { className: "dph_dailyHead", key: "head" }, [
3460
+ h("span", { className: "dph_dailyTag", key: "tag" }, t("updates.title")),
3461
+ h("span", { className: "dph_dailyDate", key: "sum" }, data && data.counts ? format(t("updates.summary"), { n: data.counts.checked, m: data.counts.outdated }) : ""),
3462
+ h("span", { className: "dph_spacer", key: "gap" }),
3463
+ h("button", {
3464
+ className: "dph_btn",
3465
+ key: "check",
3466
+ type: "button",
3467
+ disabled: store.loading,
3468
+ onClick: () => {
3469
+ track("plugin_hub", { action: "updates_check", scope: scope });
3470
+ loadUpdates(true);
3471
+ },
3472
+ }, store.loading ? t("updates.checking") : t("updates.check")),
3473
+ ]);
3474
+ if (store.error) {
3475
+ return h("div", { className: "dph_list", key: "upd" }, [
3476
+ head,
3477
+ h(Notice, { key: "err", kind: "bad", text: t("updates.failed") + ":" + (store.stale ? t("host.stale") : store.error) }),
3478
+ store.stale ? restartButton("stale") : null,
3479
+ ]);
3480
+ }
3481
+ if (!data) {
3482
+ return h("div", { className: "dph_list", key: "upd" }, [head, h(Notice, { key: "loading", text: t("updates.loading") })]);
3483
+ }
3484
+ const self = data.self || {};
3485
+ const rows = Array.isArray(data.plugins) ? data.plugins : [];
3486
+ const visibleRows = applyUsageView(rows, sortMode, onlySuggest);
3487
+ /* 批量禁用只处理「启用中」的候选;已停用的走行内卸载 */
3488
+ const batchCandidates = visibleRows.filter((row) => row && row.enabled === true);
3489
+ async function runBatchDisable() {
3490
+ const queue = batchCandidates.slice();
3491
+ const state = { done: 0, failed: 0, stop: false };
3492
+ batchStop.current = state;
3493
+ setBatchRun({ done: 0, failed: 0, total: queue.length, current: "", finished: false });
3494
+ for (const row of queue) {
3495
+ if (state.stop) break;
3496
+ const result = await postJson("/api/dpharness/toggle", { name: String(row.name || ""), enabled: false });
3497
+ const body = (result && result.data) || {};
3498
+ if (result && result.status === 200 && body.ok === true && body.enabled === false) state.done += 1;
3499
+ else state.failed += 1;
3500
+ setBatchRun({ done: state.done, failed: state.failed, total: queue.length, current: String(row.name || ""), finished: false });
3501
+ }
3502
+ batchStop.current = null;
3503
+ setBatchRun({ done: state.done, failed: state.failed, total: queue.length, current: "", finished: true });
3504
+ loadUpdates(true);
3505
+ track("plugin_hub", { action: "batch_disable_done", done: state.done, failed: state.failed });
3506
+ }
3507
+ const batch = state.batch;
3508
+ /* 自插件也算进去:它同样是"升一下就到最新",用户在意的是一共几个。
3509
+ 目标写成**具体版本号**(@latest 在 dsh 上是空转的)。 */
3510
+ const outgoing = rows
3511
+ .filter((item) => item.outdated === true)
3512
+ .map((item) => ({ name: item.name, pkg: String(item.name) + "@" + String(item.latest) }));
3513
+ if (self.outdated === true && self.name) outgoing.unshift({ name: String(self.name), pkg: String(self.name) + "@" + String(self.latest) });
3514
+ return h("div", { className: "dph_list", key: "upd" }, [
3515
+ head,
3516
+ isHostSkewed(data)
3517
+ ? h("div", { className: "dph_logCmd", key: "skew" }, [
3518
+ h("span", { className: "dph_setHint", key: "h" }, t("host.skew")),
3519
+ restartButton("skew"),
937
3520
  ])
938
- : null;
939
- const cmdRow = item.cmd
940
- ? h("div", { className: "dph_cmdWrap", key: "cmd" }, [
941
- h("div", { className: "dph_cmdRow", key: "row" }, [
942
- // 未发布到 npm 时标明来源 —— 站点详情页也是这么标注的,两处用词保持一致
943
- item.src === "repo"
944
- ? h("span", { className: "dph_tag", key: "src" }, t("label.repoSource"))
945
- : null,
946
- h("code", { className: "dph_cmd", key: "code" }, item.cmd),
3521
+ : null,
3522
+ h("div", { className: "dph_setHint", key: "note" }, t("updates.note") + " " + t("updates.ackNote")),
3523
+ /* 批量:只有在"值得批量"时才出现,免得一个入口配一个条目还用两个按钮 */
3524
+ outgoing.length >= 2 && !(batch && batch.active)
3525
+ ? h("div", { className: "dph_logCmd", key: "all" }, [
3526
+ /* 批量必须两步:单条升级有确认,批量反而一键直落会连改十几个包 ——
3527
+ 对真实用户这是最容易误触的破坏性动作(2026-10-12 补)。 */
3528
+ batchAsk ? h("span", { className: "dph_setHint", key: "warn" }, format(t("updates.upgradeAllConfirm"), { n: outgoing.length })) : null,
3529
+ h("button", {
3530
+ className: "dph_btn" + (batchAsk ? " dph_btnPrimary" : ""),
3531
+ key: "go",
3532
+ type: "button",
3533
+ onClick: () => {
3534
+ if (!batchAsk) {
3535
+ setBatchAsk(true);
3536
+ track("plugin_hub", { action: "upgrade_all_ask", n: outgoing.length, scope: scope });
3537
+ return;
3538
+ }
3539
+ setBatchAsk(false);
3540
+ runUpgradeAll(outgoing, t);
3541
+ },
3542
+ }, format(t("updates.upgradeAll"), { n: outgoing.length })),
3543
+ h("span", { className: "dph_setHint", key: "hint" }, t("updates.upgradeAllHint")),
3544
+ ])
3545
+ : null,
3546
+ batch && batch.active
3547
+ ? h("div", { className: "dph_logCmd", key: "running" }, [
3548
+ h("span", { className: "dph_instMsg", key: "msg" }, format(batch.kind === "install" ? t("sets.installing") : t("updates.batchProgress"), { done: batch.finished, total: batch.total, name: batch.current })),
947
3549
  h("button", {
948
3550
  className: "dph_btn",
949
- key: "copy",
3551
+ key: "stop",
950
3552
  type: "button",
951
- onClick: () => copyText(item.cmd, () => {
952
- onCopied(item.cmd);
953
- // 与站点 InstallBlock 同口径:value 传整条命令
954
- track("copy_install", { cmd: item.cmd, pkg: item.pkg || "" });
955
- }),
956
- }, copiedCmd === item.cmd ? t("action.copied") : t("action.copy")),
957
- ]),
958
- item.src === "repo" ? h("div", { className: "dph_instHint", key: "hint" }, t("hint.repoSource")) : null,
959
- ])
960
- : h("div", { className: "dph_cmdMissing", key: "cmd" }, t("cmd.missing"));
961
-
962
- return h("div", { className: "dph_card" + (compact ? " dph_cardSm" : ""), key: item.fullName || title }, [
963
- h("div", { className: "dph_cardTop", key: "top" }, [
964
- h("span", { className: "dph_name", key: "name" }, title),
965
- item.owner ? h("span", { className: "dph_owner", key: "owner" }, "@" + item.owner) : null,
3553
+ onClick: () => {
3554
+ track("plugin_hub", { action: "upgrade_all_stop", n: batch.finished });
3555
+ setHub({ batch: { ...batch, stopRequested: true } });
3556
+ },
3557
+ }, t("updates.stop")),
3558
+ ])
3559
+ : null,
3560
+ batch && !batch.active && batch.finished > 0
3561
+ ? h("div", { className: "dph_logCmd", key: "done" }, [
3562
+ h("span", { className: "dph_instMsg dph_instOk", key: "msg" }, format(t("updates.batchDone"), { done: batch.finished, failed: batch.failed })),
3563
+ batch.blocked > 0 ? h("span", { className: "dph_setHint", key: "blocked" }, format(t("updates.batchBlocked"), { k: batch.blocked })) : null,
3564
+ batch.noop > 0 ? h("span", { className: "dph_setHint", key: "noop" }, format(t("updates.batchNoop"), { k: batch.noop })) : null,
3565
+ batch.restartNeeded ? h("span", { className: "dph_setHint", key: "hint" }, t("updates.restartNeeded")) : null,
3566
+ batch.restartNeeded ? restartButton("batch") : null,
3567
+ ])
3568
+ : null,
3569
+ h(FavSection, { key: "fav", copiedCmd: copied, markCopied: mark, installedNames: installedNames }),
3570
+ updateRow(self, "self", t("updates.self"), copied, mark),
3571
+ /* 本插件自己的更新日志就在它这一行下面 —— 不必再为它跑一趟设置页 */
3572
+ changelogBlock(cl.state.data ? cl.state.data.entries : null, "upd:"),
3573
+ h("div", { className: "dph_setTitle", key: "installed" }, t("updates.installed")),
3574
+ h("div", { className: "dph_logCmd", key: "usagebar" }, [
3575
+ h("span", { className: "dph_setHint", key: "sum" }, usageSummaryText(rows, data.usageMeta)),
966
3576
  h("span", { className: "dph_spacer", key: "gap" }),
967
- h("span", { className: "dph_stars", key: "stars" }, format(t("badge.stars"), { n: item.stars })),
968
- item.url
969
- ? h("a", { className: "dph_btn", key: "link", href: item.url, target: "_blank", rel: "noopener noreferrer" }, "GitHub")
970
- : null,
3577
+ h("button", {
3578
+ className: "dph_btn",
3579
+ key: "sort",
3580
+ type: "button",
3581
+ onClick: () => {
3582
+ const next = sortMode === "usage" ? "default" : "usage";
3583
+ setSortMode(next);
3584
+ track("plugin_hub", { action: "usage_sort", mode: next, scope: scope });
3585
+ },
3586
+ }, sortMode === "usage" ? t("usage.sortUsageOn") : t("usage.sortUsage")),
3587
+ h("button", {
3588
+ className: "dph_btn" + (onlySuggest ? " dph_btnPrimary" : ""),
3589
+ key: "filter",
3590
+ type: "button",
3591
+ onClick: () => {
3592
+ const next = !onlySuggest;
3593
+ setOnlySuggest(next);
3594
+ track("plugin_hub", { action: "usage_filter", on: next, scope: scope });
3595
+ },
3596
+ }, t("usage.onlySuggest")),
3597
+ ]),
3598
+ batchRun
3599
+ ? h("div", { className: "dph_logCmd", key: "batchrun" }, [
3600
+ h("span", { className: "dph_instMsg", key: "msg" }, batchRun.finished
3601
+ ? format(t("usage.batchDone"), { done: batchRun.done, failed: batchRun.failed })
3602
+ : format(t("usage.batchProgress"), { done: batchRun.done, total: batchRun.total, name: batchRun.current })),
3603
+ !batchRun.finished
3604
+ ? h("button", {
3605
+ className: "dph_btn",
3606
+ key: "stop",
3607
+ type: "button",
3608
+ onClick: () => { if (batchStop.current) batchStop.current.stop = true; track("plugin_hub", { action: "batch_disable_stop" }); },
3609
+ }, t("updates.stop"))
3610
+ : null,
3611
+ ])
3612
+ : (onlySuggest && batchCandidates.length > 0
3613
+ ? h("div", { className: "dph_logCmd", key: "batchask" }, [
3614
+ batchDisableAsk ? h("span", { className: "dph_setHint", key: "warn" }, format(t("usage.batchConfirm"), { n: batchCandidates.length })) : null,
3615
+ h("button", {
3616
+ className: "dph_btn" + (batchDisableAsk ? " dph_btnPrimary" : ""),
3617
+ key: "go",
3618
+ type: "button",
3619
+ onClick: () => {
3620
+ if (!batchDisableAsk) {
3621
+ setBatchDisableAsk(true);
3622
+ track("plugin_hub", { action: "batch_disable_ask", n: batchCandidates.length });
3623
+ return;
3624
+ }
3625
+ setBatchDisableAsk(false);
3626
+ runBatchDisable();
3627
+ },
3628
+ }, format(t("usage.batchDisable"), { n: batchCandidates.length })),
3629
+ h("span", { className: "dph_setHint", key: "hint" }, t("usage.batchHint")),
3630
+ ])
3631
+ : null),
3632
+ visibleRows.length === 0
3633
+ ? h(Notice, { key: "none", text: rows.length === 0 ? t("updates.none") : t("usage.noneSuggest") })
3634
+ : h("div", { className: "dph_updList", key: "list" }, visibleRows.map((item) => updateRow(item, item.name, "", copied, mark, true))),
3635
+ data.counts && data.counts.unknown > 0
3636
+ ? h("div", { className: "dph_setHint", key: "unknown" }, format(t("updates.unknownNote"), { k: data.counts.unknown }))
3637
+ : null,
3638
+ /* 本地链接的包单列:不是漏了,而是它们根本不参与更新检查 */
3639
+ data.counts && data.counts.local > 0
3640
+ ? h("details", { className: "dph_log", key: "locals" }, [
3641
+ h("summary", { className: "dph_logHead", key: "head" }, [
3642
+ h("span", { className: "dph_logTitle", key: "t" }, format(t("updates.locals"), { n: data.counts.local })),
3643
+ ]),
3644
+ h("div", { className: "dph_logNest", key: "body" }, [
3645
+ h("div", { className: "dph_setHint", key: "note" }, t("updates.localsNote")),
3646
+ ...((Array.isArray(data.locals) ? data.locals : []).map((row) => {
3647
+ const bits = [];
3648
+ if (row && row.tier) bits.push(tierLabel(row.tier));
3649
+ if (row && row.usage && row.usage.measurable && row.usage.calls > 0) bits.push(format(t("usage.calls30d"), { n: row.usage.calls }));
3650
+ const suffix = bits.length ? " · " + bits.join(" · ") : "";
3651
+ return h("div", { className: "dph_updSub", key: String(row.name) },
3652
+ String(row.name) + " → " + String(row.spec || "").replace(/^(link|file):/, "") + suffix,
3653
+ );
3654
+ })),
3655
+ ]),
3656
+ ])
3657
+ : null,
3658
+ /* 福利专区:一句话说清是什么 + 外链。**刻意不在此处复刻站点的福利清单** ——
3659
+ 站点那份是人工每周维护的(lib/benefits.ts),公开接口只有爬虫候选池
3660
+ (未审核),拿它当内容会把没核过的东西推给用户。所以这里只做入口。 */
3661
+ h("div", { className: "dph_setGroup", key: "benefits" }, [
3662
+ h("div", { className: "dph_setRow", key: "row" }, [
3663
+ h("span", { className: "dph_setCol", key: "col" }, [
3664
+ h("span", { className: "dph_setLabel", key: "l" }, t("benefits.title")),
3665
+ h("span", { className: "dph_setHint", key: "h" }, t("benefits.body")),
3666
+ ]),
3667
+ h("a", {
3668
+ className: "dph_btn",
3669
+ key: "go",
3670
+ href: SITE + "/benefits",
3671
+ target: "_blank",
3672
+ rel: "noopener noreferrer",
3673
+ onClick: () => track("plugin_hub", { action: "site_click", scope: "benefits" }),
3674
+ }, t("action.openSite")),
3675
+ ]),
971
3676
  ]),
972
- tags.length ? h("div", { className: "dph_tags", key: "tags" }, tags) : null,
973
- sellRow,
974
- descRow,
975
- h(InstallRow, { item: item, key: "install" }),
976
- cmdRow,
977
3677
  ]);
978
3678
  }
979
3679
 
980
- function Notice(props) {
981
- return h("div", { className: "dph_notice" + (props.kind === "bad" ? " dph_noticeBad" : "") }, props.text);
3680
+ /**
3681
+ * 设置 → 插件 里的「严选插件」页签:完整设置页。
3682
+ *
3683
+ * 页签**必须订阅共享 store**:浮窗开关在通用行也有一份,两处读的是同一个
3684
+ * hidden —— 不订阅就会出现「在通用里开了、到这里还显示关」的错位(页签底部
3685
+ * 的同类问题在 v0.4.4 实测踩过)。
3686
+ */
3687
+ function SettingsPanel() {
3688
+ const state = useHub();
3689
+ const [reset, setReset] = react.useState(false);
3690
+ /* 更新日志只在设置页被打开时请求(不是每次打开浮窗都拉) */
3691
+ const cl = useChangelog();
3692
+ /* 更新检查是共享 store:这里只订阅(触发由始终挂着的侧边栏按钮负责) */
3693
+ useUpdates();
3694
+ const pending = pendingUpdates();
3695
+ function switchRow(key, labelKey, hintKey, checked, onToggle) {
3696
+ return h("div", { className: "dph_setRow", key: key }, [
3697
+ h("span", { className: "dph_setCol", key: "col" }, [
3698
+ h("span", { className: "dph_setLabel", key: "l" }, t(labelKey)),
3699
+ h("span", { className: "dph_setHint", key: "h" }, t(hintKey)),
3700
+ ]),
3701
+ h("label", { className: "dph_tel", key: "sw" }, [
3702
+ h("input", { key: "box", type: "checkbox", checked: checked, onChange: (event) => onToggle(event.target.checked) }),
3703
+ h("span", { key: "t" }, checked ? t("settings.on") : t("settings.off")),
3704
+ ]),
3705
+ ]);
3706
+ }
3707
+ return h("div", { className: "dph_set" }, [
3708
+ h("div", { className: "dph_setTitle", key: "title" }, t("settings.title")),
3709
+ switchRow("float", "settings.float", "settings.floatHint", !state.hidden, (next) => setFloatVisible(next, "settings")),
3710
+ switchRow("daily", "settings.daily", "settings.dailyHint", state.daily, (next) => setDaily(next, "settings")),
3711
+ switchRow("check", "settings.check", "settings.checkHint", state.autoCheck, (next) => setAutoCheck(next, "settings")),
3712
+ switchRow("tel", "settings.telemetry", "settings.about", state.telemetry, setTelemetry),
3713
+ changelogSection(cl, pending),
3714
+ h("div", { className: "dph_setGroup", key: "reset" }, [
3715
+ h("div", { className: "dph_setRow", key: "row" }, [
3716
+ h("span", { className: "dph_setHint", key: "h" }, t("settings.resetHint")),
3717
+ h("button", {
3718
+ className: "dph_btn",
3719
+ key: "btn",
3720
+ type: "button",
3721
+ onClick: () => {
3722
+ resetPrefs("settings");
3723
+ setReset(true);
3724
+ },
3725
+ }, t("settings.reset")),
3726
+ ]),
3727
+ reset ? h("span", { className: "dph_setHint dph_instOk", key: "done" }, t("settings.resetDone")) : null,
3728
+ ]),
3729
+ ]);
982
3730
  }
983
3731
 
984
3732
  function seg(options, current, onPick) {
@@ -1009,20 +3757,15 @@ window.__ModuleLoader__.load({
1009
3757
  ]);
1010
3758
  }
1011
3759
 
1012
- function telemetryToggle() {
3760
+ function telemetryToggle(label) {
1013
3761
  return h("label", { className: "dph_tel", key: "tel" }, [
1014
3762
  h("input", {
1015
3763
  key: "box",
1016
3764
  type: "checkbox",
1017
3765
  checked: hub.telemetry,
1018
- onChange: (event) => {
1019
- const next = event.target.checked;
1020
- try { localStorage.setItem(TEL_KEY, next ? "1" : "0"); } catch (error) { /* ignore */ }
1021
- setHub({ telemetry: next });
1022
- telemetryOn = next;
1023
- },
3766
+ onChange: (event) => setTelemetry(event.target.checked),
1024
3767
  }),
1025
- h("span", { key: "label" }, t("telemetry.on")),
3768
+ h("span", { key: "label" }, label || t("telemetry.on")),
1026
3769
  ]);
1027
3770
  }
1028
3771
 
@@ -1039,15 +3782,7 @@ window.__ModuleLoader__.load({
1039
3782
  key: "box",
1040
3783
  type: "checkbox",
1041
3784
  checked: !hub.hidden,
1042
- onChange: (event) => {
1043
- if (event.target.checked) {
1044
- storeHidden(false);
1045
- setHub({ hidden: false });
1046
- track("plugin_hub", { action: "show", scope: "tab" });
1047
- } else {
1048
- hideHub("tab");
1049
- }
1050
- },
3785
+ onChange: (event) => setFloatVisible(event.target.checked, "tab"),
1051
3786
  }),
1052
3787
  h("span", { key: "label" }, t("action.showFloat")),
1053
3788
  ]);
@@ -1068,16 +3803,64 @@ window.__ModuleLoader__.load({
1068
3803
  const cat = useCatalog(t);
1069
3804
  /* 必须订阅共享 store:页签底部的「显示右下角浮窗」开关读的是同一个
1070
3805
  hidden 状态,而关闭动作也可能来自胶囊或面板 —— 不订阅就会出现
1071
- "在别处关了浮窗,这里却还勾着"的错位(实测踩到)。 */
1072
- useHub();
3806
+ "在别处关了浮窗,这里却还勾着"的错位(实测踩到)。
3807
+ 每日推荐的显隐同样读这个 store(设置页改完这里要跟着变)。 */
3808
+ const state = useHub();
1073
3809
  const [mode, setMode] = react.useState("search");
1074
- const best = useBest(t, mode === "best");
3810
+ /* 对比表开没开 ── 每个面各自记(选择集在 hub 上共享,表格的展开状态是本面的) */
3811
+ const [comparing, setComparing] = react.useState(false);
3812
+ const dateKey = useDateKey();
3813
+ /* 默认视图顶部也要放「今日推荐」卡片,所以 daily 开着时必须取榜单数据 ——
3814
+ 不取就没东西可渲染。关掉每日推荐后即回到「只有切到榜单/每日视图才请求」。 */
3815
+ const best = useBest(t, mode === "best" || mode === "daily" || state.daily);
3816
+ const sets = useSets(t, mode === "sets");
1075
3817
  const data = cat.state.data;
1076
3818
  const bestData = best.state.data;
3819
+ const setsData = sets.state.data;
1077
3820
  const isBest = mode === "best";
1078
- const sub = isBest
3821
+ const isDaily = mode === "daily";
3822
+ const isUpdate = mode === "update";
3823
+ const isSets = mode === "sets";
3824
+ const sub = isSets
3825
+ ? (setsData ? format(t("sets.count"), { n: setsData.total || 0 }) : "")
3826
+ : isBest
1079
3827
  ? (bestData ? format(t("best.month"), { m: bestData.month || "" }) : "")
1080
- : (data ? format(t("count.summary"), { n: data.count }) + " · " + t("view.sub") : t("view.sub"));
3828
+ : isDaily
3829
+ ? t("daily.hint")
3830
+ : isUpdate
3831
+ ? ""
3832
+ : countSub(data, t, cat.state.loading, t("view.sub"));
3833
+ /* 各分支各自成段。写成嵌套三元再 spread 已经难以核对,分支越多越该先算好 body。 */
3834
+ const body = isUpdate
3835
+ ? [h(UpdateView, { key: "update", scope: "tab" })]
3836
+ : isSets
3837
+ ? [
3838
+ sets.state.error ? h(Notice, { key: "serror", kind: "bad", text: t("state.failed") + ":" + sets.state.error }) : null,
3839
+ sets.state.loading && !setsData ? h(Notice, { key: "sloading", text: t("sets.loading") }) : null,
3840
+ !sets.state.loading && setsData && (setsData.total || 0) === 0 ? h(Notice, { key: "sempty", text: t("sets.empty") }) : null,
3841
+ h("div", { className: "dph_list", key: "slist" }, renderSets(setsData, sets.copiedCmd, sets.markCopied)),
3842
+ ]
3843
+ : isDaily
3844
+ ? [
3845
+ h("div", { className: "dph_list", key: "dlist" }, dailyCard(best, best.copiedCmd, best.markCopied, { dateKey: dateKey })),
3846
+ ]
3847
+ : isBest
3848
+ ? [
3849
+ best.state.error ? h(Notice, { key: "berror", kind: "bad", text: t("state.failed") + ":" + best.state.error }) : null,
3850
+ best.state.loading && !bestData ? h(Notice, { key: "bloading", text: t("best.loading") }) : null,
3851
+ !best.state.loading && bestData && (bestData.total || 0) === 0 ? h(Notice, { key: "bempty", text: t("best.empty") }) : null,
3852
+ h("div", { className: "dph_list", key: "blist" }, renderBest(bestData, best.copiedCmd, best.markCopied)),
3853
+ ]
3854
+ : [
3855
+ state.daily ? dailyCard(best, cat.copiedCmd, cat.markCopied, { dateKey: dateKey }) : null,
3856
+ controls(cat),
3857
+ cat.state.error ? h(Notice, { key: "error", kind: "bad", text: t("state.failed") + ":" + cat.state.error }) : null,
3858
+ cat.state.loading && cat.plugins.length === 0 ? h(Notice, { key: "loading", text: t("state.loading") }) : null,
3859
+ !cat.state.loading && !cat.state.error && cat.plugins.length === 0 ? h(Notice, { key: "empty", text: t("state.empty") }) : null,
3860
+ h(CompareBar, { key: "cmpBar", open: comparing, onToggle: () => setComparing((value) => !value) }),
3861
+ comparing ? h(CompareTable, { key: "cmp", copiedCmd: cat.copiedCmd, markCopied: cat.markCopied }) : null,
3862
+ h("div", { className: "dph_list", key: "list" }, cat.plugins.map((item) => renderCard(item, cat.copiedCmd, cat.markCopied, false, true))),
3863
+ ];
1081
3864
  return h("div", { className: "dph_root" }, [
1082
3865
  h("div", { className: "dph_header", key: "header" }, [
1083
3866
  h("h2", { className: "dph_title", key: "title" }, t("view.title")),
@@ -1086,33 +3869,25 @@ window.__ModuleLoader__.load({
1086
3869
  h("a", {
1087
3870
  className: "dph_btn",
1088
3871
  key: "site",
1089
- href: isBest ? SITE + "/best" : SITE + "/plugins",
3872
+ href: isSets ? SITE + "/sets" : isBest ? SITE + "/best" : SITE + "/plugins",
1090
3873
  target: "_blank",
1091
3874
  rel: "noopener noreferrer",
1092
- onClick: () => track("plugin_hub", { action: "site_click", scope: isBest ? "best" : "tab" }),
3875
+ onClick: () => track("plugin_hub", { action: "site_click", scope: isDaily ? "daily" : isSets ? "sets" : isBest ? "best" : "tab" }),
1093
3876
  }, t("action.openSite")),
1094
- h("button", { className: "dph_btn", key: "refresh", type: "button", onClick: isBest ? best.refresh : cat.refresh }, t("action.refresh")),
3877
+ h("button", { className: "dph_btn", key: "refresh", type: "button", onClick: isUpdate ? () => loadUpdates(true) : isSets ? sets.refresh : (isBest || isDaily) ? best.refresh : cat.refresh }, t("action.refresh")),
1095
3878
  ]),
1096
3879
  /* 单元素不要写成数组:[seg(...)] 这种"数组里塞一个无 key 元素"会触发
1097
3880
  React 的 key 警告(实测)。直接作为唯一子节点传入即可。 */
1098
3881
  h("div", { className: "dph_bar", key: "seg" }, seg([
1099
3882
  { value: "search", label: t("best.recommend") },
1100
3883
  { value: "best", label: t("best.picks") },
3884
+ { value: "sets", label: t("sets.tab") },
3885
+ { value: "daily", label: t("daily.tab") },
3886
+ { value: "update", label: t("updates.tab") },
1101
3887
  ], mode, setMode)),
1102
- ...(isBest
1103
- ? [
1104
- best.state.error ? h(Notice, { key: "berror", kind: "bad", text: t("state.failed") + ":" + best.state.error }) : null,
1105
- best.state.loading && !bestData ? h(Notice, { key: "bloading", text: t("best.loading") }) : null,
1106
- !best.state.loading && bestData && (bestData.total || 0) === 0 ? h(Notice, { key: "bempty", text: t("best.empty") }) : null,
1107
- h("div", { className: "dph_list", key: "blist" }, renderBest(bestData, best.copiedCmd, best.markCopied)),
1108
- ]
1109
- : [
1110
- controls(cat),
1111
- cat.state.error ? h(Notice, { key: "error", kind: "bad", text: t("state.failed") + ":" + cat.state.error }) : null,
1112
- cat.state.loading && cat.plugins.length === 0 ? h(Notice, { key: "loading", text: t("state.loading") }) : null,
1113
- !cat.state.loading && !cat.state.error && cat.plugins.length === 0 ? h(Notice, { key: "empty", text: t("state.empty") }) : null,
1114
- h("div", { className: "dph_list", key: "list" }, cat.plugins.map((item) => renderCard(item, cat.copiedCmd, cat.markCopied, false))),
1115
- ]),
3888
+ /* 待重启横幅挂在视图切换之下、结果区之上:不跟着卡片滚走,切视图也在 */
3889
+ h(RestartBanner, { scope: "tab", key: "rbanner" }),
3890
+ ...body,
1116
3891
  h("div", { className: "dph_footer", key: "hint" }, t("footer.hint")),
1117
3892
  h("div", { className: "dph_footer", key: "tel" }, h("div", { className: "dph_footToggles" }, [telemetryToggle(), floatToggle()])),
1118
3893
  ]);
@@ -1122,18 +3897,51 @@ window.__ModuleLoader__.load({
1122
3897
  function FooterEntry(props) {
1123
3898
  const wide = props && props.wide;
1124
3899
  const state = useHub();
1125
- return h("div", { className: wide ? "dph_lbWide" : "dph_lbOff" }, [
3900
+ /* 这个入口**始终挂在侧边栏底部**,所以由它负责首次触发更新检查 ——
3901
+ 红点因此能在用户没打开过任何页面时就亮起来。 */
3902
+ useUpdates();
3903
+ const pending = pendingUpdates();
3904
+ /* 「上劲」态:浮窗被关掉后,第一下点击只进入待确认(按钮描边 + 标记脉冲 +
3905
+ 提示「再点一次恢复浮窗」),5 秒内的第二下才恢复。习惯性误点不会把浮窗
3906
+ 叫回来 —— 这是「关掉了就别默认打开」与「按钮不能是死的」之间的折中
3907
+ (2026-10-13:纯无反应的按钮被用户当成「没生效」)。 */
3908
+ const [armed, setArmed] = react.useState(false);
3909
+ react.useEffect(() => {
3910
+ if (!armed) return undefined;
3911
+ const timer = setTimeout(() => setArmed(false), 5000);
3912
+ return () => clearTimeout(timer);
3913
+ }, [armed]);
3914
+ /* 从别处恢复(页签勾选/设置开关)时解除上劲,避免按钮挂着确认态却在做别的事 */
3915
+ react.useEffect(() => {
3916
+ if (!state.hidden) setArmed(false);
3917
+ }, [state.hidden]);
3918
+ /* 提示文案随状态说准:关掉了说"怎么恢复/再点一次",可见时说"展开还是收起" ——
3919
+ 点了没反应却写着「显示浮窗」是最差的一种文案(2026-10-13 踩过)。 */
3920
+ let tip;
3921
+ if (state.hidden) tip = armed ? t("action.armRestore") : t("action.closedHint");
3922
+ else if (state.open) tip = t("action.close");
3923
+ else tip = t("action.expand");
3924
+ return h("div", { className: wide ? "dph_lbWide" : "dph_lbOff", style: { width: "100%", alignSelf: "stretch", display: "flex", minWidth: 0 } }, [
1126
3925
  h("button", {
1127
- className: "dph_lb",
3926
+ className: "dph_lb" + (armed ? " dph_lbArmed" : ""),
1128
3927
  key: "button",
1129
3928
  type: "button",
1130
- title: t("action.open"),
1131
- "aria-label": t("action.open"),
3929
+ title: tip,
3930
+ "aria-label": tip,
1132
3931
  onClick: () => {
1133
- /* 浮窗被手动关掉时,这个按钮同时是**恢复入口** ——
1134
- 若这里只做 open 的开关,关掉之后就再也叫不回来了。 */
3932
+ /* 浮窗被用户关掉后的两步确认(2026-10-13 用户反馈:
3933
+ 「胶囊用户关闭了就别默认打开了」;而纯无反应又被当成
3934
+ 「没生效」—— 两头都要照顾):
3935
+ · 第一下:只上劲,不恢复。习惯性误点到此为止;
3936
+ · 5 秒内第二下:才把胶囊叫回来(只恢复显示,面板不展开)。
3937
+ 浮窗**可见**时,这个按钮才是面板开关:展开/收起,不碰显隐。 */
1135
3938
  if (state.hidden) {
1136
- showHub("footer");
3939
+ if (!armed) {
3940
+ setArmed(true);
3941
+ return;
3942
+ }
3943
+ setArmed(false);
3944
+ setFloatVisible(true, "footer");
1137
3945
  return;
1138
3946
  }
1139
3947
  const next = !state.open;
@@ -1141,7 +3949,11 @@ window.__ModuleLoader__.load({
1141
3949
  if (next) track("plugin_hub", { action: "open", scope: "footer" });
1142
3950
  },
1143
3951
  }, [
1144
- h("span", { className: "dph_lbMark", key: "mark" }, "严"),
3952
+ h("span", { className: "dph_dotWrap", key: "markWrap" }, [
3953
+ /* ⚠️ 数组子节点的每个元素都要有 key —— 少一个 React 会告警(实测踩到) */
3954
+ h("span", { className: "dph_lbMark", key: "mark" }, "严"),
3955
+ pending.fresh ? updateDot() : null,
3956
+ ]),
1145
3957
  wide ? h("span", { className: "dph_lbLabel", key: "label" }, t("action.open")) : null,
1146
3958
  ]),
1147
3959
  ]);
@@ -1150,23 +3962,38 @@ window.__ModuleLoader__.load({
1150
3962
  /* −−− 入口 3:全站浮窗(shell.overlay,跨路由) −−− */
1151
3963
  function OverlayEntry() {
1152
3964
  const state = useHub();
3965
+ /* 更新检查是共享 store:只订阅(触发由始终挂着的侧边栏按钮负责),红点由它决定 */
3966
+ useUpdates();
3967
+ const pending = pendingUpdates();
1153
3968
  const cat = useCatalog(t);
1154
3969
  const [pos, setPos] = react.useState(readStoredPos);
3970
+ /* 窄面板里今日推荐默认收起(否则它会挤掉整个结果区 —— 实测用户反馈) */
3971
+ const [dailyOpen, setDailyOpen] = react.useState(false);
1155
3972
  const posRef = react.useRef(pos);
1156
3973
  posRef.current = pos;
1157
3974
  const skipClickRef = react.useRef(false);
1158
3975
  const panelRef = react.useRef(null);
1159
3976
  const onDrag = makeDragHandlers(() => posRef.current, setPos, skipClickRef);
1160
3977
  /**
1161
- * 面板内的两个视图:
3978
+ * 面板内的视图:
1162
3979
  * search = 严选推荐(可搜索的全量目录)
1163
3980
  * best = 分类精选(站点 /best 的月度策展结果)
3981
+ * sets = 套装(站点 /sets 的组合方案:一整套 + 安装顺序 + 冲突提示)
3982
+ * daily = 每日推荐(按自然日从榜单里取一条,当天固定)
1164
3983
  * 放在同一入口里而不是再开一个入口:用户的意图都是"找该装哪个",
1165
- * 分成两个入口只会让人不知道该点哪个。
3984
+ * 分成多个入口只会让人不知道该点哪个。
1166
3985
  */
1167
3986
  const [mode, setMode] = react.useState("search");
1168
- const best = useBest(t, state.open && mode === "best");
3987
+ /* 对比表开没开 —— 与页签各记一份(选择集共享,展开状态是本面的) */
3988
+ const [comparing, setComparing] = react.useState(false);
3989
+ const dateKey = useDateKey();
3990
+ /* 默认视图顶部也要有「今日推荐」,所以面板一展开就得取榜单数据;
3991
+ 关掉每日推荐开关后,回到「只有切到榜单/每日视图才请求」。
3992
+ 仍然挂在 state.open 上:收成胶囊时不发这个请求。 */
3993
+ const best = useBest(t, state.open && (mode === "best" || mode === "daily" || state.daily));
1169
3994
  const bestData = best.state.data;
3995
+ const sets = useSets(t, state.open && mode === "sets");
3996
+ const setsData = sets.state.data;
1170
3997
 
1171
3998
  /**
1172
3999
  * 展开时按**面板实际尺寸**重新夹取位置。
@@ -1235,7 +4062,10 @@ window.__ModuleLoader__.load({
1235
4062
  track("plugin_hub", { action: "open", scope: "overlay" });
1236
4063
  },
1237
4064
  }, [
1238
- h("span", { className: "dph_pillMark", key: "mark" }, "严"),
4065
+ h("span", { className: "dph_dotWrap", key: "markWrap" }, [
4066
+ h("span", { className: "dph_pillMark", key: "mark" }, "严"),
4067
+ pending.fresh ? updateDot() : null,
4068
+ ]),
1239
4069
  h("span", { key: "label" }, t("action.open")),
1240
4070
  ]),
1241
4071
  /* 胶囊是跨路由常驻的,用户需要一个"把这块东西从屏幕上拿掉"的出口。
@@ -1265,24 +4095,53 @@ window.__ModuleLoader__.load({
1265
4095
  title: t("action.drag"),
1266
4096
  onPointerDown: onDrag,
1267
4097
  }, t("view.title")),
1268
- h("span", { className: "dph_sub", key: "sub" }, mode === "best"
4098
+ h("span", { className: "dph_sub", key: "sub" }, mode === "daily"
4099
+ ? dateKey
4100
+ : mode === "sets"
4101
+ ? (setsData ? format(t("sets.count"), { n: setsData.total || 0 }) : "")
4102
+ : mode === "best"
1269
4103
  ? (bestData ? format(t("best.month"), { m: bestData.month || "" }) : "")
1270
- : (data ? format(t("count.summary"), { n: data.count }) : "")),
4104
+ : mode === "update"
4105
+ ? ""
4106
+ : countSub(data, t, cat.state.loading)),
1271
4107
  h("span", { className: "dph_spacer", key: "gap" }),
1272
- h("a", { className: "dph_btn", key: "site", href: mode === "best" ? SITE + "/best" : SITE + "/plugins", target: "_blank", rel: "noopener noreferrer", onClick: () => track("plugin_hub", { action: "site_click", scope: mode === "best" ? "best" : "overlay" }) }, t("action.openSite")),
4108
+ h("a", { className: "dph_btn", key: "site", href: mode === "sets" ? SITE + "/sets" : mode === "best" ? SITE + "/best" : SITE + "/plugins", target: "_blank", rel: "noopener noreferrer", onClick: () => track("plugin_hub", { action: "site_click", scope: mode === "daily" ? "daily" : mode === "sets" ? "sets" : mode === "best" ? "best" : "overlay" }) }, t("action.openSite")),
1273
4109
  h("button", { className: "dph_close", key: "close", type: "button", title: t("action.close"), "aria-label": t("action.close"), onClick: () => setHub({ open: false }) }, "×"),
1274
4110
  ]),
1275
4111
  h("div", { className: "dph_segWrap", key: "seg" }, seg([
1276
4112
  { value: "search", label: t("best.recommend") },
1277
4113
  { value: "best", label: t("best.picks") },
4114
+ { value: "sets", label: t("sets.tab") },
4115
+ { value: "daily", label: t("daily.tab") },
4116
+ { value: "update", label: t("updates.tab") },
1278
4117
  ], mode, setMode)),
1279
- ...(mode === "search"
4118
+ /* 待重启横幅在面板滚动区之外:面板再窄也一直看得见 */
4119
+ h(RestartBanner, { scope: "panel", key: "rbanner" }),
4120
+ ...(mode === "update"
4121
+ ? [
4122
+ h("div", { className: "dph_panelBody", key: "ubody" }, h(UpdateView, { scope: "overlay" })),
4123
+ ]
4124
+ : mode === "sets"
1280
4125
  ? [
4126
+ sets.state.error ? h(Notice, { key: "serror", kind: "bad", text: t("state.failed") + ":" + sets.state.error }) : null,
4127
+ sets.state.loading && !setsData ? h(Notice, { key: "sloading", text: t("sets.loading") }) : null,
4128
+ !sets.state.loading && setsData && (setsData.total || 0) === 0 ? h(Notice, { key: "sempty", text: t("sets.empty") }) : null,
4129
+ h("div", { className: "dph_panelBody", key: "sbody" }, renderSets(setsData, sets.copiedCmd, sets.markCopied)),
4130
+ ]
4131
+ : mode === "daily"
4132
+ ? [
4133
+ h("div", { className: "dph_panelBody", key: "dbody" }, dailyCard(best, best.copiedCmd, best.markCopied, { dateKey: dateKey })),
4134
+ ]
4135
+ : mode === "search"
4136
+ ? [
4137
+ state.daily ? dailyCard(best, cat.copiedCmd, cat.markCopied, { dateKey: dateKey, collapsed: !dailyOpen, toggle: () => setDailyOpen((v) => !v) }) : null,
1281
4138
  controls(cat),
1282
4139
  cat.state.error ? h(Notice, { key: "error", kind: "bad", text: t("state.failed") + ":" + cat.state.error }) : null,
1283
4140
  cat.state.loading && cat.plugins.length === 0 ? h(Notice, { key: "loading", text: t("state.loading") }) : null,
1284
4141
  !cat.state.loading && !cat.state.error && cat.plugins.length === 0 ? h(Notice, { key: "empty", text: t("state.empty") }) : null,
1285
- h("div", { className: "dph_panelBody", key: "body" }, cat.plugins.map((item) => renderCard(item, cat.copiedCmd, cat.markCopied, true))),
4142
+ h(CompareBar, { key: "cmpBar", open: comparing, onToggle: () => setComparing((value) => !value) }),
4143
+ comparing ? h(CompareTable, { key: "cmp", copiedCmd: cat.copiedCmd, markCopied: cat.markCopied }) : null,
4144
+ h("div", { className: "dph_panelBody", key: "body" }, cat.plugins.map((item) => renderCard(item, cat.copiedCmd, cat.markCopied, true, true))),
1286
4145
  ]
1287
4146
  : [
1288
4147
  best.state.error ? h(Notice, { key: "berror", kind: "bad", text: t("state.failed") + ":" + best.state.error }) : null,
@@ -1307,7 +4166,7 @@ window.__ModuleLoader__.load({
1307
4166
  ]);
1308
4167
  }
1309
4168
 
1310
- return { CatalogView, FooterEntry, OverlayEntry };
4169
+ return { CatalogView, FooterEntry, OverlayEntry, SettingsFloatRow, SettingsPanel };
1311
4170
  }
1312
4171
 
1313
4172
  /* ---------------------------------------------------------------- plugin */
@@ -1350,13 +4209,51 @@ window.__ModuleLoader__.load({
1350
4209
  ui.OverlayEntry,
1351
4210
  ),
1352
4211
  );
4212
+
4213
+ /* −−− 设置入口(2026-10-12)−−−
4214
+ 浮窗是跨路由常驻的,被关掉之后用户需要一个**显式的设置**地方把它打开,
4215
+ 而不是只在页签底部留一个勾选框。两个槽位各司其职:
4216
+ · settings.general.item —— 设置 → 通用 里的一行(最高频的浮窗开关)
4217
+ · settings.plugins.tab —— 设置 → 插件 里的完整设置页
4218
+ ⚠️ 老宿主没有这两个槽位时**不会报错**:SlotRegistry.inject 在槽位未声明时
4219
+ 只是登记等待(reconcile 里 specDynamic 为 undefined 就返回),回调永不执行、
4220
+ 注册永不发生,属静默降级 —— 故这里不需要 try/catch。
4221
+ (依据:@deepseek-ai/dsh-client-runtime src/client/slots.ts 的 inject 实现,
4222
+ 2026-10-12 查证,非猜测。) */
4223
+ ctx.slots.inject(
4224
+ "settings.general.item",
4225
+ () =>
4226
+ ctx.slots.register(
4227
+ { name: "settings.general.item", id: "dpharness", order: 40, locale: NS, label: () => t("settings.float"), inject: () => ({}) },
4228
+ ui.SettingsFloatRow,
4229
+ ),
4230
+ );
4231
+
4232
+ ctx.slots.inject(
4233
+ "settings.plugins.tab",
4234
+ () =>
4235
+ ctx.slots.register(
4236
+ { name: "settings.plugins.tab", id: "dpharness", order: 40, locale: NS, label: () => t("settings.tab"), inject: () => ({}) },
4237
+ ui.SettingsPanel,
4238
+ ),
4239
+ );
1353
4240
  }
1354
4241
 
1355
4242
  exports.NS = NS;
1356
4243
  exports.apply = apply;
1357
4244
  exports.inject = inject;
1358
- /* 供测试使用:位置夹取是纯函数,单独导出便于断言边界 */
4245
+ /* 供测试使用:位置夹取、副标题文案、每日推荐的选取都是纯函数,单独导出便于断言边界 */
1359
4246
  exports.clampPos = clampPos;
4247
+ exports.summaryOf = summaryOf;
4248
+ exports.countSub = countSub;
4249
+ exports.dailyKey = dailyKey;
4250
+ exports.hashKey = hashKey;
4251
+ exports.flattenBest = flattenBest;
4252
+ exports.pickDaily = pickDaily;
4253
+ /* 供测试使用:本机路由的响应解析要能容忍非 JSON 正文(host 未重启的窗口期) */
4254
+ exports.readHostJson = readHostJson;
4255
+ /* 供测试使用:升级目标要还原成裸包名才能查 profile 清单 */
4256
+ exports.basePackage = basePackage;
1360
4257
  return module.exports;
1361
4258
  },
1362
4259
  });