dsh-anime-bundle 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +107 -2
- package/catalog.js +91 -0
- package/client.js +1009 -0
- package/cordis.patch.yml +4 -0
- package/icon.svg +35 -0
- package/index.js +1069 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +61 -3
- package/persona.js +18 -0
package/client.js
ADDED
|
@@ -0,0 +1,1009 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 二次元大肥鱼模式 · Client 半侧
|
|
3
|
+
*
|
|
4
|
+
* 一个「设置 → 大肥鱼模式」页面:
|
|
5
|
+
* - 模式总开关(二次元外观整套开 / 关,关的时候记住组合)
|
|
6
|
+
* - 大肥鱼人格开关(Host 侧注入系统提示词,无需重启)
|
|
7
|
+
* - 插件清单:单独开关、检查更新、一键下载缺失、更新全部
|
|
8
|
+
*/
|
|
9
|
+
window.__ModuleLoader__.load({
|
|
10
|
+
id: 'dsh-anime-bundle',
|
|
11
|
+
factory(require) {
|
|
12
|
+
const React = require('react')
|
|
13
|
+
const h = React.createElement
|
|
14
|
+
const { useCallback, useEffect, useRef, useState } = React
|
|
15
|
+
|
|
16
|
+
const NS = 'dafy-mode'
|
|
17
|
+
const API = '/dafy-mode'
|
|
18
|
+
const STYLE_ID = 'dsh-anime-bundle/styles'
|
|
19
|
+
|
|
20
|
+
const zh = {
|
|
21
|
+
section: '大肥鱼模式',
|
|
22
|
+
title: '二次元大肥鱼模式',
|
|
23
|
+
subtitle: '一键开关整套二次元插件,顺手把本鱼的人格请上来。',
|
|
24
|
+
modeTitle: '模式总开关',
|
|
25
|
+
modeOn: '已开启',
|
|
26
|
+
modeOff: '普通模式',
|
|
27
|
+
modeMixed: '部分开启',
|
|
28
|
+
modeDescOn: '外观插件都在位。关闭会全部收起来,再开启时按上次记住的组合恢复。',
|
|
29
|
+
modeDescOff: '当前是干净的普通界面。开启会恢复上次记住的那套组合。',
|
|
30
|
+
modeDescMixed: '现在的插件状态和记住的组合不一致,点总开关可以重新对齐。',
|
|
31
|
+
modeCount: '{on}/{total} 个外观插件在跑',
|
|
32
|
+
remember: '记住当前组合',
|
|
33
|
+
remembered: '已把当前组合记为「开启状态」。',
|
|
34
|
+
realign: '重新对齐',
|
|
35
|
+
personaTitle: '二次元大肥鱼人格',
|
|
36
|
+
personaDesc: '开启后本鱼接管说话方式;关闭立即恢复正常。',
|
|
37
|
+
personaOn: '人格已导入',
|
|
38
|
+
personaOff: '正常模式',
|
|
39
|
+
personaHint: '下一条消息生效,不用重启。',
|
|
40
|
+
personaPreview: '看看本鱼怎么说话',
|
|
41
|
+
personaChars: '约 {n} 字',
|
|
42
|
+
pluginsTitle: '二次元外观',
|
|
43
|
+
pluginsDesc: '归总开关管,也可以在这里单独开关。',
|
|
44
|
+
utilsTitle: '功能插件',
|
|
45
|
+
utilsDesc: '不随总开关走,只在这里单独开关。',
|
|
46
|
+
check: '检查更新',
|
|
47
|
+
install: '一键下载缺失',
|
|
48
|
+
updateAll: '更新全部',
|
|
49
|
+
enableAll: '全部启用',
|
|
50
|
+
disableAll: '全部停用',
|
|
51
|
+
refresh: '刷新',
|
|
52
|
+
selfCheck: '自检',
|
|
53
|
+
selfCheckPass: '自检通过 {pass}/{total}:{detail}',
|
|
54
|
+
selfCheckFail: '自检 {pass}/{total},发现问题:{detail}',
|
|
55
|
+
pluginCount: '共 {n} 个',
|
|
56
|
+
customBadge: '自定义',
|
|
57
|
+
addPlugin: '添加插件',
|
|
58
|
+
addTitle: '已安装、还没进清单',
|
|
59
|
+
addDesc: '只改清单,不会安装或卸载任何东西。',
|
|
60
|
+
addEmpty: '所有已安装的第三方插件都已经在清单里了。',
|
|
61
|
+
addMode: '加入外观',
|
|
62
|
+
addUtil: '加入功能',
|
|
63
|
+
addBack: '加回清单',
|
|
64
|
+
catalogBadge: '默认清单',
|
|
65
|
+
addHint: '@deepseek-ai 的内置插件不在这里管,请去「设置 → 插件」。',
|
|
66
|
+
resetList: '恢复默认清单',
|
|
67
|
+
closePanel: '收起',
|
|
68
|
+
remove: '移除',
|
|
69
|
+
confirmRemove: '把「{title}」从清单移除?插件不会被卸载,当前的开关状态也不变。',
|
|
70
|
+
removed: '已从清单移除「{title}」。插件还在,没有卸载。',
|
|
71
|
+
added: '已把「{title}」加入「{group}」。',
|
|
72
|
+
addedBack: '已把「{title}」加回默认清单。',
|
|
73
|
+
addedGroupMode: '二次元外观',
|
|
74
|
+
addedGroupUtil: '功能插件',
|
|
75
|
+
resetDone: '已恢复默认清单。',
|
|
76
|
+
confirmDisableAll: '这会停用清单里的所有插件(包括记忆、MCP 面板)。确定吗?',
|
|
77
|
+
jobModeOn: '正在开启大肥鱼模式',
|
|
78
|
+
jobModeOff: '正在关闭大肥鱼模式',
|
|
79
|
+
jobAllOn: '正在启用全部插件',
|
|
80
|
+
jobAllOff: '正在停用全部插件',
|
|
81
|
+
jobInstall: '正在下载缺失插件',
|
|
82
|
+
jobCheck: '正在检查更新',
|
|
83
|
+
jobUpdate: '正在更新插件',
|
|
84
|
+
jobDefault: '正在处理',
|
|
85
|
+
jobDone: '完成',
|
|
86
|
+
jobFailed: '失败',
|
|
87
|
+
jobCancelled: '未开始',
|
|
88
|
+
nothingToInstall: '清单里的插件都已经装好了。',
|
|
89
|
+
nothingToUpdate: '没有可更新的插件。',
|
|
90
|
+
upToDate: '已是最新',
|
|
91
|
+
updateTo: '可更新 {v}',
|
|
92
|
+
notInstalled: '未安装',
|
|
93
|
+
incompatible: '版本不兼容',
|
|
94
|
+
linkBadge: '本地链接',
|
|
95
|
+
holdBadge: '慎升',
|
|
96
|
+
enabled: '已启用',
|
|
97
|
+
disabled: '已停用',
|
|
98
|
+
restart: '需重启',
|
|
99
|
+
verified: '已复核 {n} 次,状态一致。',
|
|
100
|
+
verifyFail: '复核 {n} 次仍不一致:{list}',
|
|
101
|
+
lastCheckNever: '还没检查过更新',
|
|
102
|
+
lastCheckAt: '上次检查:{time}',
|
|
103
|
+
checkedWith: '仓库:{registry}',
|
|
104
|
+
loading: '正在读取插件状态…',
|
|
105
|
+
loadFailed: '读取失败:{msg}',
|
|
106
|
+
retry: '重试',
|
|
107
|
+
errorTitle: '出错了',
|
|
108
|
+
noticeTitle: '完成',
|
|
109
|
+
dismiss: '知道了',
|
|
110
|
+
progress: '{done}/{total}',
|
|
111
|
+
footer: 'dsh-anime-bundle v1.0.0 · 所有开关即时保存,改完不用重启',
|
|
112
|
+
autoNote: '人格来自插件内置文案,可在 persona.js 里换成你自己的。',
|
|
113
|
+
busy: '有任务在跑,先等它结束。',
|
|
114
|
+
phaseEnable: '启用',
|
|
115
|
+
phaseDisable: '停用',
|
|
116
|
+
phaseInstall: '下载',
|
|
117
|
+
phaseCheck: '检查',
|
|
118
|
+
phaseUpdate: '更新',
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const en = {
|
|
122
|
+
section: 'Big Fish Mode',
|
|
123
|
+
title: 'Anime Big Fish Mode',
|
|
124
|
+
subtitle: 'One switch for the whole anime plugin set, plus the Big Fish persona.',
|
|
125
|
+
modeTitle: 'Master switch',
|
|
126
|
+
modeOn: 'On',
|
|
127
|
+
modeOff: 'Normal mode',
|
|
128
|
+
modeMixed: 'Partially on',
|
|
129
|
+
modeDescOn: 'Visual plugins are in place. Turning it off stows them and remembers the combo.',
|
|
130
|
+
modeDescOff: 'Clean, plain interface. Turning it on restores the combo you last remembered.',
|
|
131
|
+
modeDescMixed: 'Plugin state differs from the remembered combo. Click the switch to realign.',
|
|
132
|
+
modeCount: '{on}/{total} visual plugins running',
|
|
133
|
+
remember: 'Remember this combo',
|
|
134
|
+
remembered: 'Saved the current combo as the "on" state.',
|
|
135
|
+
realign: 'Realign',
|
|
136
|
+
personaTitle: 'Anime Big Fish persona',
|
|
137
|
+
personaDesc: 'Turns the fish into your assistant; off goes straight back to normal.',
|
|
138
|
+
personaOn: 'Persona imported',
|
|
139
|
+
personaOff: 'Normal mode',
|
|
140
|
+
personaHint: 'Takes effect on the next message, no restart.',
|
|
141
|
+
personaPreview: 'Hear how the fish talks',
|
|
142
|
+
personaChars: 'about {n} chars',
|
|
143
|
+
pluginsTitle: 'Anime visuals',
|
|
144
|
+
pluginsDesc: 'Controlled by the master switch, and individually toggleable here.',
|
|
145
|
+
utilsTitle: 'Utility plugins',
|
|
146
|
+
utilsDesc: 'Not part of the master switch; toggle them individually.',
|
|
147
|
+
check: 'Check updates',
|
|
148
|
+
install: 'Install missing',
|
|
149
|
+
updateAll: 'Update all',
|
|
150
|
+
enableAll: 'Enable all',
|
|
151
|
+
disableAll: 'Disable all',
|
|
152
|
+
refresh: 'Refresh',
|
|
153
|
+
selfCheck: 'Self-check',
|
|
154
|
+
selfCheckPass: 'Self-check passed {pass}/{total}: {detail}',
|
|
155
|
+
selfCheckFail: 'Self-check {pass}/{total}, problems: {detail}',
|
|
156
|
+
pluginCount: '{n} total',
|
|
157
|
+
customBadge: 'Custom',
|
|
158
|
+
addPlugin: 'Add plugin',
|
|
159
|
+
addTitle: 'Installed, not in the list',
|
|
160
|
+
addDesc: 'Only edits the list — nothing gets installed or uninstalled.',
|
|
161
|
+
addEmpty: 'Every installed third-party plugin is already in the list.',
|
|
162
|
+
addMode: 'Add to visuals',
|
|
163
|
+
addUtil: 'Add to utilities',
|
|
164
|
+
addBack: 'Restore',
|
|
165
|
+
catalogBadge: 'Default',
|
|
166
|
+
addHint: '@deepseek-ai built-ins are managed in Settings → Plugins, not here.',
|
|
167
|
+
resetList: 'Reset list',
|
|
168
|
+
closePanel: 'Close',
|
|
169
|
+
remove: 'Remove',
|
|
170
|
+
confirmRemove: 'Remove "{title}" from the list? It stays installed, and its on/off state is unchanged.',
|
|
171
|
+
removed: 'Removed "{title}" from the list. The plugin is still installed.',
|
|
172
|
+
added: 'Added "{title}" to {group}.',
|
|
173
|
+
addedBack: 'Restored "{title}" to the default list.',
|
|
174
|
+
addedGroupMode: 'visuals',
|
|
175
|
+
addedGroupUtil: 'utilities',
|
|
176
|
+
resetDone: 'Default list restored.',
|
|
177
|
+
confirmDisableAll: 'This disables every plugin in the list, including memory and the MCP panel. Continue?',
|
|
178
|
+
jobModeOn: 'Turning Big Fish Mode on',
|
|
179
|
+
jobModeOff: 'Turning Big Fish Mode off',
|
|
180
|
+
jobAllOn: 'Enabling all plugins',
|
|
181
|
+
jobAllOff: 'Disabling all plugins',
|
|
182
|
+
jobInstall: 'Installing missing plugins',
|
|
183
|
+
jobCheck: 'Checking for updates',
|
|
184
|
+
jobUpdate: 'Updating plugins',
|
|
185
|
+
jobDefault: 'Working',
|
|
186
|
+
jobDone: 'Done',
|
|
187
|
+
jobFailed: 'Failed',
|
|
188
|
+
jobCancelled: 'Not started',
|
|
189
|
+
nothingToInstall: 'Everything in the list is already installed.',
|
|
190
|
+
nothingToUpdate: 'No updates available.',
|
|
191
|
+
upToDate: 'Up to date',
|
|
192
|
+
updateTo: 'Update {v}',
|
|
193
|
+
notInstalled: 'Not installed',
|
|
194
|
+
incompatible: 'Incompatible',
|
|
195
|
+
linkBadge: 'Local link',
|
|
196
|
+
holdBadge: 'Hold',
|
|
197
|
+
enabled: 'Enabled',
|
|
198
|
+
disabled: 'Disabled',
|
|
199
|
+
restart: 'Restart needed',
|
|
200
|
+
verified: 'Verified {n} time(s), state matches.',
|
|
201
|
+
verifyFail: 'Still mismatched after {n} checks: {list}',
|
|
202
|
+
lastCheckNever: 'Never checked for updates',
|
|
203
|
+
lastCheckAt: 'Last check: {time}',
|
|
204
|
+
checkedWith: 'Registry: {registry}',
|
|
205
|
+
loading: 'Reading plugin status…',
|
|
206
|
+
loadFailed: 'Failed to load: {msg}',
|
|
207
|
+
retry: 'Retry',
|
|
208
|
+
errorTitle: 'Something went wrong',
|
|
209
|
+
noticeTitle: 'Done',
|
|
210
|
+
dismiss: 'Got it',
|
|
211
|
+
progress: '{done}/{total}',
|
|
212
|
+
footer: 'dsh-anime-bundle v1.0.0 · every switch saves immediately, no restart needed',
|
|
213
|
+
autoNote: 'The persona ships in persona.js — edit it to make the fish sound like yours.',
|
|
214
|
+
busy: 'A task is running. Wait for it to finish.',
|
|
215
|
+
phaseEnable: 'Enable',
|
|
216
|
+
phaseDisable: 'Disable',
|
|
217
|
+
phaseInstall: 'Install',
|
|
218
|
+
phaseCheck: 'Check',
|
|
219
|
+
phaseUpdate: 'Update',
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const CSS = `
|
|
223
|
+
.dfm-panel { max-width: 820px; margin: 0 auto; padding: 2px 0 52px; color: var(--dsw-alias-label-primary); font-size: 13px; line-height: 1.55; }
|
|
224
|
+
.dfm-panel *, .dfm-panel *::before, .dfm-panel *::after { box-sizing: border-box; }
|
|
225
|
+
.dfm-hero { display: flex; align-items: center; gap: 14px; padding: 18px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 16px; background: var(--dsw-alias-bg-layer-1); background: radial-gradient(130% 150% at 0% 0%, color-mix(in srgb, var(--dsw-alias-brand-primary) 16%, transparent), transparent 58%), var(--dsw-alias-bg-layer-1); }
|
|
226
|
+
.dfm-hero-icon { width: 44px; height: 44px; flex: 0 0 44px; display: grid; place-items: center; border-radius: 13px; background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); }
|
|
227
|
+
.dfm-hero-text { min-width: 0; flex: 1; }
|
|
228
|
+
.dfm-title { margin: 0; font-size: 18px; line-height: 1.3; font-weight: 650; letter-spacing: .01em; }
|
|
229
|
+
.dfm-sub { margin: 3px 0 0; font-size: 12.5px; color: var(--dsw-alias-label-secondary); }
|
|
230
|
+
.dfm-tag { flex: 0 0 auto; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--dsw-alias-border-l2); color: var(--dsw-alias-label-secondary); }
|
|
231
|
+
.dfm-tag--on { color: var(--dsw-alias-brand-primary); border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 45%, transparent); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 10%, transparent); }
|
|
232
|
+
.dfm-card { margin-top: 12px; padding: 16px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 14px; background: var(--dsw-alias-bg-layer-1); }
|
|
233
|
+
.dfm-mode-head { display: flex; align-items: flex-start; gap: 16px; }
|
|
234
|
+
.dfm-mode-text { flex: 1; min-width: 0; }
|
|
235
|
+
.dfm-card-title { font-size: 14px; font-weight: 600; }
|
|
236
|
+
.dfm-muted { color: var(--dsw-alias-label-secondary); font-size: 12.5px; margin-top: 2px; }
|
|
237
|
+
.dfm-mode-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
|
|
238
|
+
.dfm-count { font-size: 12px; color: var(--dsw-alias-label-secondary); margin-left: auto; }
|
|
239
|
+
.dfm-switch { position: relative; flex: 0 0 auto; width: 40px; height: 24px; padding: 0; border-radius: 999px; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); cursor: pointer; transition: background .15s ease, border-color .15s ease; }
|
|
240
|
+
.dfm-switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.22); transition: transform .15s ease; }
|
|
241
|
+
.dfm-switch[aria-checked="true"] { background: var(--dsw-alias-brand-primary); border-color: transparent; }
|
|
242
|
+
.dfm-switch[aria-checked="true"]::after { transform: translateX(16px); }
|
|
243
|
+
.dfm-switch:disabled { opacity: .45; cursor: not-allowed; }
|
|
244
|
+
.dfm-switch:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }
|
|
245
|
+
.dfm-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
|
|
246
|
+
.dfm-actions--split { align-items: center; }
|
|
247
|
+
.dfm-btn { height: 30px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--dsw-alias-border-l1); background: transparent; color: var(--dsw-alias-label-primary); font-size: 12.5px; font-family: inherit; cursor: pointer; }
|
|
248
|
+
.dfm-btn:hover:not(:disabled) { background: var(--dsw-alias-bg-layer-2); }
|
|
249
|
+
.dfm-btn:disabled { opacity: .45; cursor: not-allowed; }
|
|
250
|
+
.dfm-btn--primary { background: var(--dsw-alias-brand-primary); border-color: transparent; color: #fff; }
|
|
251
|
+
.dfm-btn--primary:hover:not(:disabled) { background: var(--dsw-alias-brand-primary); filter: brightness(1.06); }
|
|
252
|
+
.dfm-btn--ghost { border-color: transparent; color: var(--dsw-alias-label-secondary); padding: 0 8px; }
|
|
253
|
+
.dfm-btn--ghost:hover:not(:disabled) { color: var(--dsw-alias-label-primary); }
|
|
254
|
+
.dfm-section { margin-top: 22px; }
|
|
255
|
+
.dfm-section-head h3 { margin: 0; font-size: 13px; font-weight: 600; }
|
|
256
|
+
.dfm-section-head p { margin: 2px 0 8px; font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
257
|
+
.dfm-section-head--row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
|
|
258
|
+
.dfm-section-head--row p { margin-bottom: 0; }
|
|
259
|
+
.dfm-section-tools { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
|
|
260
|
+
.dfm-row-remove { flex: 0 0 auto; width: 24px; height: 24px; padding: 0; border-radius: 7px; border: 1px solid transparent; background: transparent; color: var(--dsw-alias-label-secondary); font-size: 16px; line-height: 1; cursor: pointer; }
|
|
261
|
+
.dfm-row-remove:hover:not(:disabled) { color: var(--dsw-alias-state-error-primary); background: var(--dsw-alias-bg-layer-2); }
|
|
262
|
+
.dfm-row-remove:disabled { opacity: .4; cursor: not-allowed; }
|
|
263
|
+
.dfm-add { margin: 2px 0 10px; }
|
|
264
|
+
.dfm-add-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
|
265
|
+
.dfm-add-list { margin-top: 10px; display: flex; flex-direction: column; max-height: 320px; overflow: auto; border-top: 1px solid var(--dsw-alias-border-l1); }
|
|
266
|
+
.dfm-add-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--dsw-alias-border-l1); }
|
|
267
|
+
.dfm-add-row:last-child { border-bottom: 0; }
|
|
268
|
+
.dfm-add-actions { display: flex; gap: 6px; flex: 0 0 auto; }
|
|
269
|
+
.dfm-add-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
|
|
270
|
+
.dfm-empty { margin-top: 10px; padding: 14px; text-align: center; font-size: 12px; color: var(--dsw-alias-label-secondary); border: 1px dashed var(--dsw-alias-border-l1); border-radius: 10px; }
|
|
271
|
+
.dfm-list { border: 1px solid var(--dsw-alias-border-l1); border-radius: 14px; background: var(--dsw-alias-bg-layer-1); padding: 0 16px; }
|
|
272
|
+
.dfm-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--dsw-alias-border-l1); }
|
|
273
|
+
.dfm-row:first-child { border-top: 0; }
|
|
274
|
+
.dfm-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; background: var(--dsw-alias-state-idle-primary); }
|
|
275
|
+
.dfm-dot--on { background: var(--dsw-alias-state-success-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--dsw-alias-state-success-primary) 18%, transparent); }
|
|
276
|
+
.dfm-row-main { flex: 1; min-width: 0; }
|
|
277
|
+
.dfm-row-title { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; font-size: 13px; font-weight: 550; }
|
|
278
|
+
.dfm-note { margin-top: 1px; font-size: 11.5px; color: var(--dsw-alias-label-secondary); }
|
|
279
|
+
.dfm-pkg { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10.5px; color: var(--dsw-alias-label-secondary); opacity: .8; }
|
|
280
|
+
.dfm-badges { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
|
|
281
|
+
.dfm-badge { font-size: 10.5px; line-height: 1; padding: 3px 6px; border-radius: 999px; border: 1px solid var(--dsw-alias-border-l1); color: var(--dsw-alias-label-secondary); white-space: nowrap; }
|
|
282
|
+
.dfm-badge--update { color: var(--dsw-alias-state-warn-primary); border-color: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 45%, transparent); }
|
|
283
|
+
.dfm-badge--warn { color: var(--dsw-alias-state-warn-primary); }
|
|
284
|
+
.dfm-badge--on { color: var(--dsw-alias-state-success-primary); border-color: color-mix(in srgb, var(--dsw-alias-state-success-primary) 40%, transparent); }
|
|
285
|
+
.dfm-badge--off { color: var(--dsw-alias-label-secondary); }
|
|
286
|
+
.dfm-job { margin-top: 12px; padding: 14px 16px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 14px; background: var(--dsw-alias-bg-layer-1); }
|
|
287
|
+
.dfm-job-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 550; }
|
|
288
|
+
.dfm-job-head .dfm-count { margin-left: auto; }
|
|
289
|
+
.dfm-bar { height: 4px; margin-top: 10px; border-radius: 999px; background: var(--dsw-alias-bg-layer-2); overflow: hidden; }
|
|
290
|
+
.dfm-bar > i { display: block; height: 100%; border-radius: 999px; background: var(--dsw-alias-brand-primary); transition: width .25s ease; }
|
|
291
|
+
.dfm-job-current { margin-top: 8px; font-size: 11.5px; color: var(--dsw-alias-label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
292
|
+
.dfm-results { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; max-height: 148px; overflow: auto; }
|
|
293
|
+
.dfm-results li { display: flex; gap: 6px; font-size: 11.5px; color: var(--dsw-alias-label-secondary); }
|
|
294
|
+
.dfm-results li b { font-weight: 550; color: var(--dsw-alias-label-primary); }
|
|
295
|
+
.dfm-results li em { font-style: normal; color: var(--dsw-alias-state-success-primary); }
|
|
296
|
+
.dfm-results li.is-bad em { color: var(--dsw-alias-state-error-primary); }
|
|
297
|
+
.dfm-banner { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 12.5px; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); }
|
|
298
|
+
.dfm-banner--error { border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 45%, transparent); color: var(--dsw-alias-state-error-primary); background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 8%, var(--dsw-alias-bg-layer-1)); }
|
|
299
|
+
.dfm-banner--ok { border-color: color-mix(in srgb, var(--dsw-alias-state-success-primary) 40%, transparent); color: var(--dsw-alias-state-success-primary); background: color-mix(in srgb, var(--dsw-alias-state-success-primary) 8%, var(--dsw-alias-bg-layer-1)); }
|
|
300
|
+
.dfm-banner-text { flex: 1; min-width: 0; color: var(--dsw-alias-label-primary); }
|
|
301
|
+
.dfm-details { margin-top: 10px; }
|
|
302
|
+
.dfm-details summary { cursor: pointer; font-size: 12px; color: var(--dsw-alias-label-secondary); user-select: none; }
|
|
303
|
+
.dfm-details summary:hover { color: var(--dsw-alias-label-primary); }
|
|
304
|
+
.dfm-persona-text { margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); font-size: 12px; color: var(--dsw-alias-label-secondary); white-space: pre-wrap; max-height: 220px; overflow: auto; }
|
|
305
|
+
.dfm-foot { margin-top: 18px; font-size: 11px; color: var(--dsw-alias-label-secondary); text-align: center; }
|
|
306
|
+
.dfm-loading { padding: 40px 0; text-align: center; color: var(--dsw-alias-label-secondary); font-size: 12.5px; }
|
|
307
|
+
@media (max-width: 560px) { .dfm-hero { align-items: flex-start; } .dfm-tag { display: none; } .dfm-section-head--row { flex-direction: column; align-items: stretch; } .dfm-section-tools { justify-content: flex-end; } }
|
|
308
|
+
`
|
|
309
|
+
|
|
310
|
+
function installStyles() {
|
|
311
|
+
const existing = document.getElementById(STYLE_ID)
|
|
312
|
+
if (existing) return () => {}
|
|
313
|
+
const el = document.createElement('style')
|
|
314
|
+
el.id = STYLE_ID
|
|
315
|
+
el.textContent = CSS
|
|
316
|
+
document.head.appendChild(el)
|
|
317
|
+
return () => {
|
|
318
|
+
try {
|
|
319
|
+
el.remove()
|
|
320
|
+
} catch {
|
|
321
|
+
/* 页面卸载时忽略 */
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function fmt(template, values) {
|
|
327
|
+
return String(template).replace(/\{(\w+)\}/g, (whole, key) =>
|
|
328
|
+
values && Object.prototype.hasOwnProperty.call(values, key) ? String(values[key]) : whole,
|
|
329
|
+
)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function timeText(timestamp) {
|
|
333
|
+
if (!timestamp) return ''
|
|
334
|
+
try {
|
|
335
|
+
const date = new Date(timestamp)
|
|
336
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
337
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`
|
|
338
|
+
} catch {
|
|
339
|
+
return ''
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async function request(path, options) {
|
|
344
|
+
let lastError = null
|
|
345
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
346
|
+
try {
|
|
347
|
+
const response = await fetch(`${API}${path}`, {
|
|
348
|
+
cache: 'no-store',
|
|
349
|
+
...options,
|
|
350
|
+
headers: {
|
|
351
|
+
accept: 'application/json',
|
|
352
|
+
...(options && options.body ? { 'content-type': 'application/json' } : {}),
|
|
353
|
+
},
|
|
354
|
+
})
|
|
355
|
+
const payload = await response.json().catch(() => null)
|
|
356
|
+
if (!payload) throw new Error(`HTTP ${response.status}`)
|
|
357
|
+
if (!payload.ok) throw new Error(payload.error || `HTTP ${response.status}`)
|
|
358
|
+
return payload
|
|
359
|
+
} catch (error) {
|
|
360
|
+
lastError = error
|
|
361
|
+
if (attempt < 2) await new Promise((resolve) => setTimeout(resolve, 350 * (attempt + 1)))
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
throw lastError || new Error('请求失败')
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function FishIcon({ size = 28 }) {
|
|
368
|
+
return h(
|
|
369
|
+
'svg',
|
|
370
|
+
{ width: size, height: size, viewBox: '0 0 64 64', 'aria-hidden': true },
|
|
371
|
+
h('path', {
|
|
372
|
+
d: 'M13 31c-4-5-7-9-7-9s6-1 10 1c3 2 4 6 4 6s-1 4-4 6c-4 2-10 1-10 1s3-4 7-5z',
|
|
373
|
+
fill: '#3E63E8',
|
|
374
|
+
}),
|
|
375
|
+
h('path', {
|
|
376
|
+
d: 'M16 30c0-9 8-16 20-16 13 0 21 7 21 17 0 11-9 18-21 18-12 0-20-8-20-19z',
|
|
377
|
+
fill: '#4C74F5',
|
|
378
|
+
}),
|
|
379
|
+
h('path', {
|
|
380
|
+
d: 'M22 38c3 6 8 9 15 9 8 0 14-4 17-10-3 8-9 12-17 12-8 0-13-4-15-11z',
|
|
381
|
+
fill: '#DCE6FF',
|
|
382
|
+
opacity: 0.92,
|
|
383
|
+
}),
|
|
384
|
+
h('circle', { cx: 46, cy: 28, r: 4.6, fill: '#fff' }),
|
|
385
|
+
h('circle', { cx: 46.8, cy: 28.4, r: 2.5, fill: '#12224F' }),
|
|
386
|
+
h('circle', { cx: 47.7, cy: 27.2, r: 1, fill: '#fff' }),
|
|
387
|
+
h('ellipse', { cx: 41, cy: 35, rx: 3.4, ry: 2.2, fill: '#FF9BB5', opacity: 0.75 }),
|
|
388
|
+
)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function Toggle({ checked, disabled, onChange, label }) {
|
|
392
|
+
return h('button', {
|
|
393
|
+
type: 'button',
|
|
394
|
+
role: 'switch',
|
|
395
|
+
className: 'dfm-switch',
|
|
396
|
+
'aria-checked': checked ? 'true' : 'false',
|
|
397
|
+
'aria-label': label,
|
|
398
|
+
disabled,
|
|
399
|
+
onClick: disabled ? undefined : onChange,
|
|
400
|
+
})
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function Badge({ children, tone }) {
|
|
404
|
+
return h('span', { className: `dfm-badge${tone ? ` dfm-badge--${tone}` : ''}` }, children)
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function PluginRow({ row, t, busy, onToggle, onRemove }) {
|
|
408
|
+
const parts = []
|
|
409
|
+
if (row.installed && row.version) parts.push(h(Badge, { key: 'v' }, `v${row.version}`))
|
|
410
|
+
if (!row.installed) parts.push(h(Badge, { key: 'missing', tone: 'warn' }, t('notInstalled')))
|
|
411
|
+
if (row.incompatible) parts.push(h(Badge, { key: 'bad', tone: 'warn' }, t('incompatible')))
|
|
412
|
+
if (row.custom) parts.push(h(Badge, { key: 'custom' }, t('customBadge')))
|
|
413
|
+
if (row.kind === 'link') parts.push(h(Badge, { key: 'link' }, t('linkBadge')))
|
|
414
|
+
if (row.update && row.update.newer) {
|
|
415
|
+
parts.push(h(Badge, { key: 'upd', tone: 'update' }, fmt(t('updateTo'), { v: row.update.latest })))
|
|
416
|
+
}
|
|
417
|
+
if (row.hold) parts.push(h(Badge, { key: 'hold', tone: 'warn' }, t('holdBadge')))
|
|
418
|
+
|
|
419
|
+
return h(
|
|
420
|
+
'div',
|
|
421
|
+
{ className: 'dfm-row' },
|
|
422
|
+
h('span', { className: `dfm-dot${row.enabled ? ' dfm-dot--on' : ''}` }),
|
|
423
|
+
h(
|
|
424
|
+
'div',
|
|
425
|
+
{ className: 'dfm-row-main' },
|
|
426
|
+
h(
|
|
427
|
+
'div',
|
|
428
|
+
{ className: 'dfm-row-title' },
|
|
429
|
+
h('span', null, row.title),
|
|
430
|
+
h('span', { className: 'dfm-pkg' }, row.name),
|
|
431
|
+
),
|
|
432
|
+
h('div', { className: 'dfm-note' }, row.note || ''),
|
|
433
|
+
),
|
|
434
|
+
h('div', { className: 'dfm-badges' }, parts),
|
|
435
|
+
h(Toggle, {
|
|
436
|
+
checked: row.enabled,
|
|
437
|
+
disabled: busy || !row.installed,
|
|
438
|
+
label: `${row.title} ${row.enabled ? t('enabled') : t('disabled')}`,
|
|
439
|
+
onChange: () => onToggle(row),
|
|
440
|
+
}),
|
|
441
|
+
h(
|
|
442
|
+
'button',
|
|
443
|
+
{
|
|
444
|
+
type: 'button',
|
|
445
|
+
className: 'dfm-row-remove',
|
|
446
|
+
title: t('remove'),
|
|
447
|
+
'aria-label': `${t('remove')} ${row.title}`,
|
|
448
|
+
disabled: busy,
|
|
449
|
+
onClick: () => onRemove(row),
|
|
450
|
+
},
|
|
451
|
+
'×',
|
|
452
|
+
),
|
|
453
|
+
)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function AddPanel({ t, items, busy, onAdd, onReset, onClose }) {
|
|
457
|
+
return h(
|
|
458
|
+
'section',
|
|
459
|
+
{ className: 'dfm-card dfm-add' },
|
|
460
|
+
h(
|
|
461
|
+
'div',
|
|
462
|
+
{ className: 'dfm-add-head' },
|
|
463
|
+
h(
|
|
464
|
+
'div',
|
|
465
|
+
null,
|
|
466
|
+
h('div', { className: 'dfm-card-title' }, t('addTitle')),
|
|
467
|
+
h('div', { className: 'dfm-muted' }, t('addDesc')),
|
|
468
|
+
),
|
|
469
|
+
h('button', { type: 'button', className: 'dfm-btn dfm-btn--ghost', onClick: onClose }, t('closePanel')),
|
|
470
|
+
),
|
|
471
|
+
items.length === 0
|
|
472
|
+
? h('div', { className: 'dfm-empty' }, t('addEmpty'))
|
|
473
|
+
: h(
|
|
474
|
+
'div',
|
|
475
|
+
{ className: 'dfm-add-list' },
|
|
476
|
+
items.map((item) =>
|
|
477
|
+
h(
|
|
478
|
+
'div',
|
|
479
|
+
{ key: item.name, className: 'dfm-add-row' },
|
|
480
|
+
h(
|
|
481
|
+
'div',
|
|
482
|
+
{ className: 'dfm-row-main' },
|
|
483
|
+
h(
|
|
484
|
+
'div',
|
|
485
|
+
{ className: 'dfm-row-title' },
|
|
486
|
+
h('span', null, item.title),
|
|
487
|
+
h('span', { className: 'dfm-pkg' }, item.name),
|
|
488
|
+
),
|
|
489
|
+
h('div', { className: 'dfm-note' }, item.note || ''),
|
|
490
|
+
h(
|
|
491
|
+
'div',
|
|
492
|
+
{ className: 'dfm-badges' },
|
|
493
|
+
item.version ? h(Badge, { key: 'v' }, `v${item.version}`) : null,
|
|
494
|
+
item.enabled ? h(Badge, { key: 'on', tone: 'on' }, t('enabled')) : null,
|
|
495
|
+
item.inCatalog ? h(Badge, { key: 'cat' }, t('catalogBadge')) : null,
|
|
496
|
+
),
|
|
497
|
+
),
|
|
498
|
+
h(
|
|
499
|
+
'div',
|
|
500
|
+
{ className: 'dfm-add-actions' },
|
|
501
|
+
item.inCatalog
|
|
502
|
+
? h(
|
|
503
|
+
'button',
|
|
504
|
+
{
|
|
505
|
+
type: 'button',
|
|
506
|
+
className: 'dfm-btn',
|
|
507
|
+
disabled: busy,
|
|
508
|
+
onClick: () => onAdd(item.name, 'util'),
|
|
509
|
+
},
|
|
510
|
+
t('addBack'),
|
|
511
|
+
)
|
|
512
|
+
: [
|
|
513
|
+
h(
|
|
514
|
+
'button',
|
|
515
|
+
{
|
|
516
|
+
key: 'mode',
|
|
517
|
+
type: 'button',
|
|
518
|
+
className: 'dfm-btn',
|
|
519
|
+
disabled: busy,
|
|
520
|
+
onClick: () => onAdd(item.name, 'mode'),
|
|
521
|
+
},
|
|
522
|
+
t('addMode'),
|
|
523
|
+
),
|
|
524
|
+
h(
|
|
525
|
+
'button',
|
|
526
|
+
{
|
|
527
|
+
key: 'util',
|
|
528
|
+
type: 'button',
|
|
529
|
+
className: 'dfm-btn',
|
|
530
|
+
disabled: busy,
|
|
531
|
+
onClick: () => onAdd(item.name, 'util'),
|
|
532
|
+
},
|
|
533
|
+
t('addUtil'),
|
|
534
|
+
),
|
|
535
|
+
],
|
|
536
|
+
),
|
|
537
|
+
),
|
|
538
|
+
),
|
|
539
|
+
),
|
|
540
|
+
h(
|
|
541
|
+
'div',
|
|
542
|
+
{ className: 'dfm-add-foot' },
|
|
543
|
+
h('span', { className: 'dfm-note' }, t('addHint')),
|
|
544
|
+
h('button', { type: 'button', className: 'dfm-btn dfm-btn--ghost', disabled: busy, onClick: onReset }, t('resetList')),
|
|
545
|
+
),
|
|
546
|
+
)
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function JobCard({ job, t, onDismiss }) {
|
|
550
|
+
const running = job.status === 'running'
|
|
551
|
+
const labelKey =
|
|
552
|
+
job.kind === 'mode-on'
|
|
553
|
+
? 'jobModeOn'
|
|
554
|
+
: job.kind === 'mode-off'
|
|
555
|
+
? 'jobModeOff'
|
|
556
|
+
: job.kind === 'all-on'
|
|
557
|
+
? 'jobAllOn'
|
|
558
|
+
: job.kind === 'all-off'
|
|
559
|
+
? 'jobAllOff'
|
|
560
|
+
: job.kind === 'install'
|
|
561
|
+
? 'jobInstall'
|
|
562
|
+
: job.kind === 'check'
|
|
563
|
+
? 'jobCheck'
|
|
564
|
+
: job.kind === 'update'
|
|
565
|
+
? 'jobUpdate'
|
|
566
|
+
: 'jobDefault'
|
|
567
|
+
const percent = job.total > 0 ? Math.min(100, Math.round((job.done / job.total) * 100)) : 0
|
|
568
|
+
const statusText = running ? t('progress') : job.status === 'done' ? t('jobDone') : t('jobFailed')
|
|
569
|
+
const results = (job.results || []).slice(-8).reverse()
|
|
570
|
+
|
|
571
|
+
return h(
|
|
572
|
+
'section',
|
|
573
|
+
{ className: 'dfm-job' },
|
|
574
|
+
h(
|
|
575
|
+
'div',
|
|
576
|
+
{ className: 'dfm-job-head' },
|
|
577
|
+
h('span', null, running ? t(labelKey) : job.status === 'done' ? t('jobDone') : t('jobFailed')),
|
|
578
|
+
h('span', { className: 'dfm-count' }, fmt(statusText, { done: job.done, total: job.total })),
|
|
579
|
+
!running
|
|
580
|
+
? h('button', { type: 'button', className: 'dfm-btn dfm-btn--ghost', onClick: onDismiss }, t('dismiss'))
|
|
581
|
+
: null,
|
|
582
|
+
),
|
|
583
|
+
h('div', { className: 'dfm-bar' }, h('i', { style: { width: `${percent}%` } })),
|
|
584
|
+
job.message ? h('div', { className: 'dfm-job-current' }, job.message) : null,
|
|
585
|
+
job.current ? h('div', { className: 'dfm-job-current' }, `${job.phase ? t(`phase${job.phase.charAt(0).toUpperCase()}${job.phase.slice(1)}`) : ''} ${job.current}`.trim()) : null,
|
|
586
|
+
job.verify
|
|
587
|
+
? h(
|
|
588
|
+
'div',
|
|
589
|
+
{ className: 'dfm-job-current' },
|
|
590
|
+
job.verify.consistent
|
|
591
|
+
? t('verified').replace('{n}', String(job.verify.attempts))
|
|
592
|
+
: fmt(t('verifyFail'), {
|
|
593
|
+
n: job.verify.attempts,
|
|
594
|
+
list: (job.verify.mismatches || []).map((item) => item.name).join(', ') || '?',
|
|
595
|
+
}),
|
|
596
|
+
)
|
|
597
|
+
: null,
|
|
598
|
+
results.length
|
|
599
|
+
? h(
|
|
600
|
+
'ul',
|
|
601
|
+
{ className: 'dfm-results' },
|
|
602
|
+
results.map((item, index) =>
|
|
603
|
+
h(
|
|
604
|
+
'li',
|
|
605
|
+
{ key: `${item.name}-${index}`, className: item.ok ? '' : 'is-bad' },
|
|
606
|
+
h('em', null, item.ok ? '✓' : '×'),
|
|
607
|
+
h('b', null, item.name),
|
|
608
|
+
h('span', null, item.message || ''),
|
|
609
|
+
),
|
|
610
|
+
),
|
|
611
|
+
)
|
|
612
|
+
: null,
|
|
613
|
+
)
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function Panel({ t }) {
|
|
617
|
+
const [data, setData] = useState(null)
|
|
618
|
+
const [error, setError] = useState('')
|
|
619
|
+
const [notice, setNotice] = useState('')
|
|
620
|
+
const [pending, setPending] = useState(false)
|
|
621
|
+
const [hiddenJob, setHiddenJob] = useState('')
|
|
622
|
+
const [addOpen, setAddOpen] = useState(false)
|
|
623
|
+
const noticeTimer = useRef(0)
|
|
624
|
+
|
|
625
|
+
const load = useCallback(async (quiet) => {
|
|
626
|
+
try {
|
|
627
|
+
const payload = await request('/state')
|
|
628
|
+
setData(payload)
|
|
629
|
+
if (!quiet) setError('')
|
|
630
|
+
return payload
|
|
631
|
+
} catch (err) {
|
|
632
|
+
if (!quiet) setError(String((err && err.message) || err))
|
|
633
|
+
return null
|
|
634
|
+
}
|
|
635
|
+
}, [])
|
|
636
|
+
|
|
637
|
+
useEffect(() => {
|
|
638
|
+
load(false)
|
|
639
|
+
}, [load])
|
|
640
|
+
|
|
641
|
+
const job = data && data.job && data.job.id !== hiddenJob ? data.job : null
|
|
642
|
+
const jobRunning = Boolean(job && job.status === 'running')
|
|
643
|
+
|
|
644
|
+
useEffect(() => {
|
|
645
|
+
if (!jobRunning) return undefined
|
|
646
|
+
const timer = setInterval(() => {
|
|
647
|
+
load(true)
|
|
648
|
+
}, 900)
|
|
649
|
+
return () => clearInterval(timer)
|
|
650
|
+
}, [jobRunning, load])
|
|
651
|
+
|
|
652
|
+
const showNotice = useCallback((text) => {
|
|
653
|
+
setNotice(text)
|
|
654
|
+
if (noticeTimer.current) clearTimeout(noticeTimer.current)
|
|
655
|
+
noticeTimer.current = setTimeout(() => setNotice(''), 6000)
|
|
656
|
+
}, [])
|
|
657
|
+
|
|
658
|
+
useEffect(() => () => {
|
|
659
|
+
if (noticeTimer.current) clearTimeout(noticeTimer.current)
|
|
660
|
+
}, [])
|
|
661
|
+
|
|
662
|
+
const busy = pending || jobRunning
|
|
663
|
+
|
|
664
|
+
const post = useCallback(
|
|
665
|
+
async (path, body) => {
|
|
666
|
+
setPending(true)
|
|
667
|
+
setError('')
|
|
668
|
+
try {
|
|
669
|
+
const payload = await fetch(`${API}${path}`, {
|
|
670
|
+
method: 'POST',
|
|
671
|
+
headers: { 'content-type': 'application/json' },
|
|
672
|
+
body: JSON.stringify(body || {}),
|
|
673
|
+
}).then(async (response) => {
|
|
674
|
+
const json = await response.json().catch(() => null)
|
|
675
|
+
if (!json) throw new Error(`HTTP ${response.status}`)
|
|
676
|
+
if (!json.ok) throw new Error(json.error || `HTTP ${response.status}`)
|
|
677
|
+
return json
|
|
678
|
+
})
|
|
679
|
+
if (payload.state) setData(payload.state)
|
|
680
|
+
else await load(true)
|
|
681
|
+
return payload
|
|
682
|
+
} catch (err) {
|
|
683
|
+
setError(String((err && err.message) || err))
|
|
684
|
+
return null
|
|
685
|
+
} finally {
|
|
686
|
+
setPending(false)
|
|
687
|
+
}
|
|
688
|
+
},
|
|
689
|
+
[load],
|
|
690
|
+
)
|
|
691
|
+
|
|
692
|
+
const toggleMode = useCallback(async () => {
|
|
693
|
+
if (!data) return
|
|
694
|
+
await post('/action', { action: 'set-mode', enabled: !data.mode.on })
|
|
695
|
+
}, [data, post])
|
|
696
|
+
|
|
697
|
+
const togglePersona = useCallback(async () => {
|
|
698
|
+
if (!data) return
|
|
699
|
+
const payload = await post('/persona', { enabled: !data.persona.enabled })
|
|
700
|
+
if (payload) showNotice(payload.state && payload.state.persona.enabled ? t('personaOn') : t('personaOff'))
|
|
701
|
+
}, [data, post, showNotice, t])
|
|
702
|
+
|
|
703
|
+
const togglePlugin = useCallback(
|
|
704
|
+
async (row) => {
|
|
705
|
+
await post('/action', { action: 'set-plugin', name: row.name, enabled: !row.enabled })
|
|
706
|
+
},
|
|
707
|
+
[post],
|
|
708
|
+
)
|
|
709
|
+
|
|
710
|
+
const addPlugin = useCallback(
|
|
711
|
+
async (name, group) => {
|
|
712
|
+
const payload = await post('/action', { action: 'add-plugin', name, group })
|
|
713
|
+
if (!payload || !payload.result) return
|
|
714
|
+
const result = payload.result
|
|
715
|
+
const rows = (payload.state && payload.state.plugins) || []
|
|
716
|
+
const row = rows.find((item) => item.name === name)
|
|
717
|
+
if (result.restored) {
|
|
718
|
+
showNotice(fmt(t('addedBack'), { title: row ? row.title : name }))
|
|
719
|
+
} else if (result.entry) {
|
|
720
|
+
showNotice(
|
|
721
|
+
fmt(t('added'), {
|
|
722
|
+
title: result.entry.title,
|
|
723
|
+
group: result.entry.group === 'mode' ? t('addedGroupMode') : t('addedGroupUtil'),
|
|
724
|
+
}),
|
|
725
|
+
)
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
[post, showNotice, t],
|
|
729
|
+
)
|
|
730
|
+
|
|
731
|
+
const removePlugin = useCallback(
|
|
732
|
+
async (row) => {
|
|
733
|
+
if (!window.confirm(fmt(t('confirmRemove'), { title: row.title }))) return
|
|
734
|
+
const payload = await post('/action', { action: 'remove-plugin', name: row.name })
|
|
735
|
+
if (payload) showNotice(fmt(t('removed'), { title: row.title }))
|
|
736
|
+
},
|
|
737
|
+
[post, showNotice, t],
|
|
738
|
+
)
|
|
739
|
+
|
|
740
|
+
const resetList = useCallback(async () => {
|
|
741
|
+
const payload = await post('/action', { action: 'reset-list' })
|
|
742
|
+
if (payload) showNotice(t('resetDone'))
|
|
743
|
+
}, [post, showNotice, t])
|
|
744
|
+
|
|
745
|
+
const setAll = useCallback(
|
|
746
|
+
async (enabled) => {
|
|
747
|
+
if (!enabled && !window.confirm(t('confirmDisableAll'))) return
|
|
748
|
+
await post('/action', { action: 'set-all', enabled })
|
|
749
|
+
},
|
|
750
|
+
[post, t],
|
|
751
|
+
)
|
|
752
|
+
|
|
753
|
+
const remember = useCallback(async () => {
|
|
754
|
+
const payload = await post('/action', { action: 'remember' })
|
|
755
|
+
if (payload) showNotice(t('remembered'))
|
|
756
|
+
}, [post, showNotice, t])
|
|
757
|
+
|
|
758
|
+
const selfCheck = useCallback(async () => {
|
|
759
|
+
const payload = await post('/action', { action: 'self-check' })
|
|
760
|
+
if (!payload || !payload.result) return
|
|
761
|
+
const result = payload.result
|
|
762
|
+
const detail = (result.checks || [])
|
|
763
|
+
.map((check) => `${check.ok ? '✓' : '×'} ${check.message}`)
|
|
764
|
+
.join(';')
|
|
765
|
+
showNotice(
|
|
766
|
+
fmt(t(result.ok ? 'selfCheckPass' : 'selfCheckFail'), {
|
|
767
|
+
pass: result.passed,
|
|
768
|
+
total: result.total,
|
|
769
|
+
detail,
|
|
770
|
+
}),
|
|
771
|
+
)
|
|
772
|
+
}, [post, showNotice, t])
|
|
773
|
+
|
|
774
|
+
const realign = useCallback(async () => {
|
|
775
|
+
await post('/action', { action: 'set-mode', enabled: true })
|
|
776
|
+
}, [post])
|
|
777
|
+
|
|
778
|
+
if (!data) {
|
|
779
|
+
return h(
|
|
780
|
+
'div',
|
|
781
|
+
{ className: 'dfm-panel' },
|
|
782
|
+
error
|
|
783
|
+
? h(
|
|
784
|
+
'div',
|
|
785
|
+
{ className: 'dfm-banner dfm-banner--error' },
|
|
786
|
+
h('div', { className: 'dfm-banner-text' }, fmt(t('loadFailed'), { msg: error })),
|
|
787
|
+
h('button', { type: 'button', className: 'dfm-btn', onClick: () => load(false) }, t('retry')),
|
|
788
|
+
)
|
|
789
|
+
: h('div', { className: 'dfm-loading' }, t('loading')),
|
|
790
|
+
)
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
const modeTag = data.mode.on ? (data.mode.aligned ? t('modeOn') : t('modeMixed')) : t('modeOff')
|
|
794
|
+
const modeDesc = data.mode.on
|
|
795
|
+
? data.mode.aligned
|
|
796
|
+
? t('modeDescOn')
|
|
797
|
+
: t('modeDescMixed')
|
|
798
|
+
: t('modeDescOff')
|
|
799
|
+
const modeRows = data.plugins.filter((row) => row.group === 'mode')
|
|
800
|
+
const utilRows = data.plugins.filter((row) => row.group === 'util')
|
|
801
|
+
const lastCheck = data.updates.checkedAt
|
|
802
|
+
? fmt(t('lastCheckAt'), { time: timeText(data.updates.checkedAt) })
|
|
803
|
+
: t('lastCheckNever')
|
|
804
|
+
|
|
805
|
+
return h(
|
|
806
|
+
'div',
|
|
807
|
+
{ className: 'dfm-panel' },
|
|
808
|
+
h(
|
|
809
|
+
'header',
|
|
810
|
+
{ className: 'dfm-hero' },
|
|
811
|
+
h('div', { className: 'dfm-hero-icon' }, h(FishIcon, { size: 28 })),
|
|
812
|
+
h(
|
|
813
|
+
'div',
|
|
814
|
+
{ className: 'dfm-hero-text' },
|
|
815
|
+
h('h2', { className: 'dfm-title' }, t('title')),
|
|
816
|
+
h('p', { className: 'dfm-sub' }, t('subtitle')),
|
|
817
|
+
),
|
|
818
|
+
h('span', { className: `dfm-tag${data.mode.on ? ' dfm-tag--on' : ''}` }, modeTag),
|
|
819
|
+
),
|
|
820
|
+
|
|
821
|
+
error
|
|
822
|
+
? h(
|
|
823
|
+
'div',
|
|
824
|
+
{ className: 'dfm-banner dfm-banner--error' },
|
|
825
|
+
h('div', { className: 'dfm-banner-text' }, error),
|
|
826
|
+
h('button', { type: 'button', className: 'dfm-btn', onClick: () => load(false) }, t('retry')),
|
|
827
|
+
)
|
|
828
|
+
: null,
|
|
829
|
+
notice
|
|
830
|
+
? h(
|
|
831
|
+
'div',
|
|
832
|
+
{ className: 'dfm-banner dfm-banner--ok' },
|
|
833
|
+
h('div', { className: 'dfm-banner-text' }, notice),
|
|
834
|
+
)
|
|
835
|
+
: null,
|
|
836
|
+
|
|
837
|
+
h(
|
|
838
|
+
'section',
|
|
839
|
+
{ className: 'dfm-card' },
|
|
840
|
+
h(
|
|
841
|
+
'div',
|
|
842
|
+
{ className: 'dfm-mode-head' },
|
|
843
|
+
h(
|
|
844
|
+
'div',
|
|
845
|
+
{ className: 'dfm-mode-text' },
|
|
846
|
+
h('div', { className: 'dfm-card-title' }, t('modeTitle')),
|
|
847
|
+
h('div', { className: 'dfm-muted' }, modeDesc),
|
|
848
|
+
),
|
|
849
|
+
h(Toggle, {
|
|
850
|
+
checked: data.mode.on,
|
|
851
|
+
disabled: busy,
|
|
852
|
+
label: t('modeTitle'),
|
|
853
|
+
onChange: toggleMode,
|
|
854
|
+
}),
|
|
855
|
+
),
|
|
856
|
+
h(
|
|
857
|
+
'div',
|
|
858
|
+
{ className: 'dfm-mode-meta' },
|
|
859
|
+
data.mode.on && !data.mode.aligned
|
|
860
|
+
? h('button', { type: 'button', className: 'dfm-btn', disabled: busy, onClick: realign }, t('realign'))
|
|
861
|
+
: null,
|
|
862
|
+
data.mode.on
|
|
863
|
+
? h('button', { type: 'button', className: 'dfm-btn', disabled: busy, onClick: remember }, t('remember'))
|
|
864
|
+
: null,
|
|
865
|
+
h('span', { className: 'dfm-count' }, fmt(t('modeCount'), {
|
|
866
|
+
on: data.mode.enabledCount,
|
|
867
|
+
total: data.mode.totalCount,
|
|
868
|
+
})),
|
|
869
|
+
),
|
|
870
|
+
),
|
|
871
|
+
|
|
872
|
+
h(
|
|
873
|
+
'section',
|
|
874
|
+
{ className: 'dfm-card' },
|
|
875
|
+
h(
|
|
876
|
+
'div',
|
|
877
|
+
{ className: 'dfm-mode-head' },
|
|
878
|
+
h(
|
|
879
|
+
'div',
|
|
880
|
+
{ className: 'dfm-mode-text' },
|
|
881
|
+
h('div', { className: 'dfm-card-title' }, t('personaTitle')),
|
|
882
|
+
h('div', { className: 'dfm-muted' }, t('personaDesc')),
|
|
883
|
+
),
|
|
884
|
+
h(Toggle, {
|
|
885
|
+
checked: data.persona.enabled,
|
|
886
|
+
disabled: pending,
|
|
887
|
+
label: t('personaTitle'),
|
|
888
|
+
onChange: togglePersona,
|
|
889
|
+
}),
|
|
890
|
+
),
|
|
891
|
+
h(
|
|
892
|
+
'div',
|
|
893
|
+
{ className: 'dfm-mode-meta' },
|
|
894
|
+
h(Badge, { tone: data.persona.enabled ? 'on' : 'off' }, data.persona.enabled ? t('personaOn') : t('personaOff')),
|
|
895
|
+
h('span', { className: 'dfm-count' }, data.persona.enabled ? t('personaHint') : ''),
|
|
896
|
+
),
|
|
897
|
+
h(
|
|
898
|
+
'details',
|
|
899
|
+
{ className: 'dfm-details' },
|
|
900
|
+
h('summary', null, `${t('personaPreview')} · ${fmt(t('personaChars'), { n: data.persona.chars })}`),
|
|
901
|
+
h('div', { className: 'dfm-persona-text' }, data.persona.preview),
|
|
902
|
+
h('div', { className: 'dfm-note', style: { marginTop: '6px' } }, t('autoNote')),
|
|
903
|
+
),
|
|
904
|
+
),
|
|
905
|
+
|
|
906
|
+
h(
|
|
907
|
+
'div',
|
|
908
|
+
{ className: 'dfm-actions dfm-actions--split' },
|
|
909
|
+
h('button', { type: 'button', className: 'dfm-btn dfm-btn--primary', disabled: busy, onClick: () => post('/action', { action: 'check-updates' }) }, t('check')),
|
|
910
|
+
h('button', { type: 'button', className: 'dfm-btn', disabled: busy, onClick: () => post('/action', { action: 'install-missing' }) }, t('install')),
|
|
911
|
+
h('button', { type: 'button', className: 'dfm-btn', disabled: busy, onClick: () => post('/action', { action: 'update-all' }) }, t('updateAll')),
|
|
912
|
+
h('span', { style: { flex: 1 } }),
|
|
913
|
+
h('button', { type: 'button', className: 'dfm-btn', disabled: busy, onClick: () => setAll(true) }, t('enableAll')),
|
|
914
|
+
h('button', { type: 'button', className: 'dfm-btn', disabled: busy, onClick: () => setAll(false) }, t('disableAll')),
|
|
915
|
+
h('button', { type: 'button', className: 'dfm-btn dfm-btn--ghost', disabled: pending, onClick: selfCheck }, t('selfCheck')),
|
|
916
|
+
h('button', { type: 'button', className: 'dfm-btn dfm-btn--ghost', disabled: busy, onClick: () => load(true) }, t('refresh')),
|
|
917
|
+
),
|
|
918
|
+
h('div', { className: 'dfm-note', style: { marginTop: '6px' } }, lastCheck),
|
|
919
|
+
|
|
920
|
+
job ? h(JobCard, { job, t, onDismiss: () => setHiddenJob(job.id) }) : null,
|
|
921
|
+
|
|
922
|
+
h(
|
|
923
|
+
'section',
|
|
924
|
+
{ className: 'dfm-section' },
|
|
925
|
+
h(
|
|
926
|
+
'div',
|
|
927
|
+
{ className: 'dfm-section-head dfm-section-head--row' },
|
|
928
|
+
h(
|
|
929
|
+
'div',
|
|
930
|
+
null,
|
|
931
|
+
h('h3', null, t('pluginsTitle')),
|
|
932
|
+
h('p', null, t('pluginsDesc')),
|
|
933
|
+
),
|
|
934
|
+
h(
|
|
935
|
+
'div',
|
|
936
|
+
{ className: 'dfm-section-tools' },
|
|
937
|
+
h('span', { className: 'dfm-count' }, fmt(t('pluginCount'), { n: data.plugins.length })),
|
|
938
|
+
h(
|
|
939
|
+
'button',
|
|
940
|
+
{
|
|
941
|
+
type: 'button',
|
|
942
|
+
className: 'dfm-btn dfm-btn--primary',
|
|
943
|
+
disabled: busy,
|
|
944
|
+
onClick: () => setAddOpen((open) => !open),
|
|
945
|
+
},
|
|
946
|
+
t('addPlugin'),
|
|
947
|
+
),
|
|
948
|
+
),
|
|
949
|
+
),
|
|
950
|
+
addOpen
|
|
951
|
+
? h(AddPanel, {
|
|
952
|
+
t,
|
|
953
|
+
items: data.available || [],
|
|
954
|
+
busy,
|
|
955
|
+
onAdd: addPlugin,
|
|
956
|
+
onReset: resetList,
|
|
957
|
+
onClose: () => setAddOpen(false),
|
|
958
|
+
})
|
|
959
|
+
: null,
|
|
960
|
+
h('div', { className: 'dfm-list' }, modeRows.map((row) => h(PluginRow, {
|
|
961
|
+
key: row.name,
|
|
962
|
+
row,
|
|
963
|
+
t,
|
|
964
|
+
busy,
|
|
965
|
+
onToggle: togglePlugin,
|
|
966
|
+
onRemove: removePlugin,
|
|
967
|
+
}))),
|
|
968
|
+
),
|
|
969
|
+
|
|
970
|
+
h(
|
|
971
|
+
'section',
|
|
972
|
+
{ className: 'dfm-section' },
|
|
973
|
+
h('div', { className: 'dfm-section-head' }, h('h3', null, t('utilsTitle')), h('p', null, t('utilsDesc'))),
|
|
974
|
+
h('div', { className: 'dfm-list' }, utilRows.map((row) => h(PluginRow, {
|
|
975
|
+
key: row.name,
|
|
976
|
+
row,
|
|
977
|
+
t,
|
|
978
|
+
busy,
|
|
979
|
+
onToggle: togglePlugin,
|
|
980
|
+
onRemove: removePlugin,
|
|
981
|
+
}))),
|
|
982
|
+
),
|
|
983
|
+
|
|
984
|
+
h('div', { className: 'dfm-foot' }, t('footer')),
|
|
985
|
+
)
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
return {
|
|
989
|
+
inject: ['slots', 'locale'],
|
|
990
|
+
apply(ctx) {
|
|
991
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-anime-bundle: locale')
|
|
992
|
+
ctx.effect(() => installStyles(), 'dsh-anime-bundle: styles')
|
|
993
|
+
const t = ctx.locale.bind(NS)
|
|
994
|
+
ctx.slots.inject('settings.section', () =>
|
|
995
|
+
ctx.slots.register(
|
|
996
|
+
{
|
|
997
|
+
name: 'settings.section',
|
|
998
|
+
id: 'dafy-mode',
|
|
999
|
+
order: 27,
|
|
1000
|
+
label: () => t('section'),
|
|
1001
|
+
locale: NS,
|
|
1002
|
+
},
|
|
1003
|
+
() => h(Panel, { t }),
|
|
1004
|
+
),
|
|
1005
|
+
)
|
|
1006
|
+
},
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
1009
|
+
})
|