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