dsh-dock 0.23.1 → 0.25.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/README.md +50 -40
- package/client.js +2552 -472
- package/features/animation/host.js +3 -2
- package/features/balance/host.js +3 -3
- package/features/dshtools/host.js +319 -0
- package/features/dshtools/view.jsx +403 -0
- package/features/git/host.js +884 -0
- package/features/git/rpc.js +156 -0
- package/features/git/view.jsx +1946 -0
- package/features/mcpconfig/host.js +3 -3
- package/features/mcpconfig/view.js +8 -8
- package/features/mobile-relay/host.js +42 -9
- package/features/modelconfig/host.js +3 -3
- package/features/notify/host.js +3 -2
- package/features/notify/view.jsx +38 -46
- package/features/providerconfig/host.js +3 -3
- package/features/runstate/host.js +3 -2
- package/features/tokenlog/host.js +3 -2
- package/features/tts/host.js +3 -2
- package/index.js +8 -2
- package/package.json +5 -6
- package/src/client.jsx +21 -2
- package/src/host-core.js +52 -13
- package/screenshots/dock-animation.png +0 -0
- package/screenshots/dock-balance.png +0 -0
- package/screenshots/dock-games.png +0 -0
- package/screenshots/dock-home.png +0 -0
- package/screenshots/dock-modelconfig-provider-create.png +0 -0
- package/screenshots/dock-modelconfig-provider-edit.png +0 -0
- package/screenshots/dock-modelconfig-providers.png +0 -0
- package/screenshots/dock-modelconfig.png +0 -0
- package/screenshots/dock-notify.png +0 -0
- package/screenshots/dock-runstate.png +0 -0
- package/screenshots/dock-settings.png +0 -0
- package/screenshots/dock-tokenlog-charts-2.png +0 -0
- package/screenshots/dock-tokenlog-charts-3.png +0 -0
- package/screenshots/dock-tokenlog-charts.png +0 -0
- package/screenshots/dock-tokenlog.png +0 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
// dsh-dock · 功能模块【DSH功能】· 客户端视图
|
|
2
|
+
//
|
|
3
|
+
// 给 DSH 自带界面补充能力的开关页:分组(例如「文件右键」)× 勾选项。
|
|
4
|
+
// 勾选状态存在宿主设置里(features/dshtools/host.js 的 /dsh-dock/dshtools),
|
|
5
|
+
// 跨浏览器/跨设备一致;面板页只负责渲染清单与提交单项切换。
|
|
6
|
+
//
|
|
7
|
+
// 新增能力不需要改这里:宿主清单里加一项,页面就多一个勾选框;
|
|
8
|
+
// 行为侧按分组/键名自行接线(见 installClient 里的「文件右键 → 大文件下载」示例)。
|
|
9
|
+
//
|
|
10
|
+
// 约束(与其它模块一致):
|
|
11
|
+
// 1. fetch 用文档相对路径 "dsh-dock/dshtools"(子路径反代 /ui/ 下自动带前缀);
|
|
12
|
+
// 2. 不引用宿主全局对象,测试可在 node:vm 里跑构建产物;
|
|
13
|
+
// 3. 宿主不支持该路由(旧版本)时页面给出提示,右键菜单也绝不出现新条目。
|
|
14
|
+
import react from "react";
|
|
15
|
+
import { stateOf } from "../../src/shared.js";
|
|
16
|
+
|
|
17
|
+
const ENDPOINT = "dsh-dock/dshtools";
|
|
18
|
+
/** 内置「下载」Remote 的整文件默认上限:超过它的文件才需要本功能的流式下载。 */
|
|
19
|
+
export const LARGE_FILE_BYTES = 32 * 1024 * 1024;
|
|
20
|
+
|
|
21
|
+
// ---------- 配置 Store(面板页与右键菜单共用;变更即通知) ----------
|
|
22
|
+
const store = {
|
|
23
|
+
/** 宿主 /dsh-dock/dshtools 是否已成功读过一次:没读过就绝不接管菜单。 */
|
|
24
|
+
ready: false,
|
|
25
|
+
error: "",
|
|
26
|
+
groups: [],
|
|
27
|
+
listeners: new Set(),
|
|
28
|
+
loading: null,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function notify() {
|
|
32
|
+
for (const fn of store.listeners) {
|
|
33
|
+
try { fn(); } catch (e) { console.error("[dsh-dock] DSH功能订阅者出错:", e); }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 订阅配置变化;返回退订函数。 */
|
|
38
|
+
export function subscribe(fn) {
|
|
39
|
+
store.listeners.add(fn);
|
|
40
|
+
return () => { store.listeners.delete(fn); };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 用宿主返回的清单覆盖本地状态;形状不对时保持原状并记错误。 */
|
|
44
|
+
function applyPayload(data) {
|
|
45
|
+
const groups = data && data.ok === true && Array.isArray(data.groups) ? data.groups : null;
|
|
46
|
+
if (!groups) {
|
|
47
|
+
store.error = (data && data.error) || "宿主返回的配置格式不正确";
|
|
48
|
+
notify();
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
store.groups = groups;
|
|
52
|
+
store.error = "";
|
|
53
|
+
store.ready = true;
|
|
54
|
+
notify();
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 读一次配置(并发调用共用一个请求;失败后可重试)。 */
|
|
59
|
+
export function ensureLoaded() {
|
|
60
|
+
if (store.ready) return Promise.resolve(true);
|
|
61
|
+
if (store.loading) return store.loading;
|
|
62
|
+
if (typeof fetch !== "function") {
|
|
63
|
+
store.error = "当前环境不支持 fetch";
|
|
64
|
+
notify();
|
|
65
|
+
return Promise.resolve(false);
|
|
66
|
+
}
|
|
67
|
+
store.loading = fetch(ENDPOINT, { headers: { accept: "application/json" } })
|
|
68
|
+
.then(async (res) => {
|
|
69
|
+
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
70
|
+
return res.json();
|
|
71
|
+
})
|
|
72
|
+
.then((data) => applyPayload(data))
|
|
73
|
+
.catch(() => {
|
|
74
|
+
// 宿主旧版本(无此路由)/未启用:页面提示,菜单不出现;下次打开可重试。
|
|
75
|
+
store.error = "宿主没有「DSH功能」接口:宿主进程可能是旧版本,或该功能在宿主侧未启用(重启 dsh web,或在功能坞里关掉再打开本功能)";
|
|
76
|
+
notify();
|
|
77
|
+
return false;
|
|
78
|
+
})
|
|
79
|
+
.finally(() => { store.loading = null; });
|
|
80
|
+
return store.loading;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 某项当前勾选值;不存在返回 undefined。 */
|
|
84
|
+
export function valueOf(groupId, key) {
|
|
85
|
+
const group = store.groups.find((g) => g.id === groupId);
|
|
86
|
+
const item = group && Array.isArray(group.items) ? group.items.find((i) => i.key === key) : undefined;
|
|
87
|
+
return item ? item.value === true : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 切换单项:提交宿主并同步本地(失败时抛错,由调用方展示)。 */
|
|
91
|
+
export async function setValue(groupId, key, value) {
|
|
92
|
+
const res = await fetch(ENDPOINT, {
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: { "content-type": "application/json" },
|
|
95
|
+
body: JSON.stringify({ group: groupId, key, value: value === true }),
|
|
96
|
+
});
|
|
97
|
+
const data = await res.json().catch(() => null);
|
|
98
|
+
if (!res.ok || !data || data.ok !== true) {
|
|
99
|
+
throw new Error((data && data.error) || ("HTTP " + res.status));
|
|
100
|
+
}
|
|
101
|
+
applyPayload(data);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ---------- 「文件右键」接线:大文件流式下载 ----------
|
|
105
|
+
/** 从 DSH 的原始文件 URL(/api/file?path=…)里取绝对路径;不是该形态返回 undefined。 */
|
|
106
|
+
function filePathOf(url) {
|
|
107
|
+
if (typeof url !== "string" || url.length === 0) return undefined;
|
|
108
|
+
let parsed;
|
|
109
|
+
try {
|
|
110
|
+
parsed = new URL(url, document.baseURI);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (typeof location !== "undefined" && parsed.origin !== location.origin) return undefined;
|
|
115
|
+
if (!/\/api\/file$/.test(parsed.pathname)) return undefined;
|
|
116
|
+
const path = parsed.searchParams.get("path");
|
|
117
|
+
return path && path.length > 0 ? path : undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 探测宿主下载路由是否可用(HEAD 204)。只有探测通过才接管 DSH 自带「下载」,
|
|
122
|
+
* 否则保持原行为——宿主旧版本 / 功能在宿主侧未启用时绝不改变现有下载。
|
|
123
|
+
*/
|
|
124
|
+
let routeReady = false;
|
|
125
|
+
let routeProbe = null;
|
|
126
|
+
function ensureRoute() {
|
|
127
|
+
if (routeReady) return Promise.resolve(true);
|
|
128
|
+
if (routeProbe) return routeProbe;
|
|
129
|
+
if (typeof fetch !== "function") return Promise.resolve(false);
|
|
130
|
+
routeProbe = fetch("dsh-dock/download?probe=1", { method: "HEAD", cache: "no-store" })
|
|
131
|
+
.then((res) => { routeReady = res.status === 204 || res.ok === true; return routeReady; })
|
|
132
|
+
.catch(() => false)
|
|
133
|
+
.finally(() => { routeProbe = null; });
|
|
134
|
+
return routeProbe;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 当前是否接管 DSH 自带的「下载」:功能启用 + 勾选开启 + 宿主下载路由探测通过。 */
|
|
138
|
+
function shouldTakeover() {
|
|
139
|
+
const state = stateOf("dshtools");
|
|
140
|
+
if (!state || state.enabled !== true) return false;
|
|
141
|
+
if (valueOf("fileContextMenu", "streamingDownload") === false) return false;
|
|
142
|
+
if (!routeReady) { void ensureRoute(); return false; }
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 接管 DSH 自带的「下载」:Web 端下载文件时不再走 workspaceFiles.readBytes 整文件读取
|
|
148
|
+
* (默认 32 MiB 上限,超了只弹「无法保存文件」),改为跳转本模块的流式下载路由。
|
|
149
|
+
* 只替换实例上的 save 方法,其余情况(Desktop、图片、非 /api/file 来源)原样回调。
|
|
150
|
+
* @param {object} actions ui-file-actions 提供的 fileActions 服务实例
|
|
151
|
+
*/
|
|
152
|
+
function installDownloadTakeover(actions) {
|
|
153
|
+
if (!actions || typeof actions.save !== "function" || actions.__dshDockStreamingDownload === true) return;
|
|
154
|
+
const original = actions.save;
|
|
155
|
+
const wrapped = async function (source, mode) {
|
|
156
|
+
if (mode === "download" && actions.canSaveAs !== true && shouldTakeover()) {
|
|
157
|
+
const path = filePathOf(source && source.url);
|
|
158
|
+
if (path !== undefined) {
|
|
159
|
+
try {
|
|
160
|
+
startDownload(path);
|
|
161
|
+
return { status: "requested" };
|
|
162
|
+
} catch (e) {
|
|
163
|
+
// 落回原下载路径(例如 document 不可用)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return original.call(actions, source, mode);
|
|
168
|
+
};
|
|
169
|
+
wrapped.__original = original;
|
|
170
|
+
try {
|
|
171
|
+
actions.save = wrapped;
|
|
172
|
+
actions.__dshDockStreamingDownload = true;
|
|
173
|
+
} catch (e) {
|
|
174
|
+
// 服务对象只读:保持 DSH 原行为
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---------- 「文件右键」接线的第一步:大文件下载 ----------
|
|
179
|
+
/**
|
|
180
|
+
* 触发浏览器原生下载:URL 走文档相对路径(反代前缀由 base 带入),
|
|
181
|
+
* 响应带 Content-Disposition: attachment,所以只下载、不跳页。
|
|
182
|
+
* @param {string} absolutePath 文件绝对路径
|
|
183
|
+
*/
|
|
184
|
+
function startDownload(absolutePath) {
|
|
185
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
186
|
+
const base = document.baseURI || (typeof location !== "undefined" ? location.href : "http://localhost/");
|
|
187
|
+
const url = new URL("dsh-dock/download?path=" + encodeURIComponent(absolutePath), base);
|
|
188
|
+
const anchor = document.createElement("a");
|
|
189
|
+
anchor.href = url.href;
|
|
190
|
+
anchor.download = "";
|
|
191
|
+
anchor.rel = "noopener";
|
|
192
|
+
document.body.append(anchor);
|
|
193
|
+
anchor.click();
|
|
194
|
+
anchor.remove();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** 右键「文件」时按文件大小决定是否追加「下载(大文件)」。 */
|
|
198
|
+
async function resolveFileMenu(remote, target, signal) {
|
|
199
|
+
const state = stateOf("dshtools");
|
|
200
|
+
if (!state || state.enabled !== true) return [];
|
|
201
|
+
// 首屏配置没取到(宿主刚重启 / 请求失败)时补一次:本次不出现,下次右键就有。
|
|
202
|
+
if (!store.ready) { void ensureLoaded(); return []; }
|
|
203
|
+
if (valueOf("fileContextMenu", "streamingDownload") !== true) return [];
|
|
204
|
+
let result;
|
|
205
|
+
try {
|
|
206
|
+
result = await remote.workspaceFiles.stat(target.sessionId, target.path, signal);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
return []; // 元数据不可用:不提供本项,菜单其余条目照常
|
|
209
|
+
}
|
|
210
|
+
if (!result || result.ok !== true || !result.value) return [];
|
|
211
|
+
const bytes = typeof result.value.bytes === "number" ? result.value.bytes : undefined;
|
|
212
|
+
// 小文件 DSH 自带的「下载」就能用,不重复占位;只有超过整文件上限才出现。
|
|
213
|
+
if (bytes === undefined || bytes <= LARGE_FILE_BYTES) return [];
|
|
214
|
+
const absolutePath = result.value.absolutePath;
|
|
215
|
+
if (typeof absolutePath !== "string" || absolutePath.length === 0) return [];
|
|
216
|
+
return [{
|
|
217
|
+
id: "download-large",
|
|
218
|
+
label: "下载(大文件)",
|
|
219
|
+
icon: { key: "dsh-dock.download" },
|
|
220
|
+
run: () => startDownload(absolutePath),
|
|
221
|
+
}];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** 下载图标(contextMenu.icon 座位用;跟随菜单文字颜色)。 */
|
|
225
|
+
function DownloadIcon() {
|
|
226
|
+
return react.createElement("svg", {
|
|
227
|
+
width: 14, height: 14, viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true",
|
|
228
|
+
},
|
|
229
|
+
react.createElement("path", {
|
|
230
|
+
d: "M8 2.5v7.2m0 0 2.8-2.8M8 9.7 5.2 6.9M3 13h10",
|
|
231
|
+
stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round", strokeLinejoin: "round",
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** 取服务:优先属性访问(正常 ctx),再退回 get()(精简 ctx / 测试桩)。 */
|
|
236
|
+
function serviceOf(scope, name) {
|
|
237
|
+
if (!scope) return undefined;
|
|
238
|
+
const direct = scope[name];
|
|
239
|
+
if (direct !== undefined) return direct;
|
|
240
|
+
return typeof scope.get === "function" ? scope.get(name) : undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 在依赖服务就绪后执行;没有 ctx.inject(测试桩 / 极简 ctx)时直接尝试一次。
|
|
245
|
+
* @param {object} ctx Client context
|
|
246
|
+
* @param {string[]} names 依赖的服务名
|
|
247
|
+
* @param {(scope: object) => void} run 装配回调
|
|
248
|
+
*/
|
|
249
|
+
function onServices(ctx, names, run) {
|
|
250
|
+
if (typeof ctx.inject === "function") {
|
|
251
|
+
try {
|
|
252
|
+
ctx.inject(names, (scope) => run(scope));
|
|
253
|
+
return;
|
|
254
|
+
} catch (e) {
|
|
255
|
+
// 桩 ctx 的 inject 不可用时退回直接取服务
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
run(ctx);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* 客户端装配:注册右键菜单与图标。由 src/client.jsx 的 apply() 调一次。
|
|
263
|
+
* 依赖用 ctx.inject 延迟获取(功能坞可能先于 ui-file-actions / ui-context-menu 加载);
|
|
264
|
+
* 服务缺失(桌面端 / 测试桩)时静默跳过,面板页本身仍可用。
|
|
265
|
+
* @param {object} ctx Client context
|
|
266
|
+
*/
|
|
267
|
+
export function installClient(ctx) {
|
|
268
|
+
if (!ctx || typeof ctx !== "object") return;
|
|
269
|
+
ensureLoaded();
|
|
270
|
+
onServices(ctx, ["slots"], (scope) => {
|
|
271
|
+
const slots = serviceOf(scope, "slots");
|
|
272
|
+
if (!slots || typeof slots.inject !== "function" || typeof slots.register !== "function") return;
|
|
273
|
+
slots.inject("contextMenu.icon", function* () {
|
|
274
|
+
yield slots.register({ name: "contextMenu.icon", key: "dsh-dock.download" }, DownloadIcon);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
onServices(ctx, ["contextMenus", "remote.workspaceFiles"], (scope) => {
|
|
278
|
+
const menus = serviceOf(scope, "contextMenus");
|
|
279
|
+
const remote = serviceOf(scope, "remote");
|
|
280
|
+
if (!menus || typeof menus.register !== "function") return;
|
|
281
|
+
if (!remote || !remote.workspaceFiles || typeof remote.workspaceFiles.stat !== "function") return;
|
|
282
|
+
const register = () => menus.register({
|
|
283
|
+
id: "dsh-dock.dshtools.file",
|
|
284
|
+
target: "file",
|
|
285
|
+
// 排在 DSH 自带 file-actions(order 200)之后:同菜单里我们的是补充项。
|
|
286
|
+
order: 210,
|
|
287
|
+
resolve: (target, signal) => resolveFileMenu(remote, target, signal),
|
|
288
|
+
});
|
|
289
|
+
if (typeof scope.effect === "function") scope.effect(register, "dsh-dock: DSH功能 · 文件右键");
|
|
290
|
+
else register();
|
|
291
|
+
});
|
|
292
|
+
// 关键:把 DSH 自带的「下载」也接到流式路由上——用户最常点的是那一条,
|
|
293
|
+
// 不能让他先点旧条目再看到「无法保存文件」。
|
|
294
|
+
ensureRoute();
|
|
295
|
+
onServices(ctx, ["fileActions"], (scope) => {
|
|
296
|
+
const actions = serviceOf(scope, "fileActions");
|
|
297
|
+
if (!actions) return;
|
|
298
|
+
installDownloadTakeover(actions);
|
|
299
|
+
if (typeof scope.effect === "function") {
|
|
300
|
+
scope.effect(() => () => {
|
|
301
|
+
if (actions.__dshDockStreamingDownload !== true) return;
|
|
302
|
+
const restore = actions.save && actions.save.__original;
|
|
303
|
+
if (typeof restore === "function") {
|
|
304
|
+
try { actions.save = restore; } catch (e) { /* 忽略 */ }
|
|
305
|
+
}
|
|
306
|
+
delete actions.__dshDockStreamingDownload;
|
|
307
|
+
}, "dsh-dock: DSH功能 · 下载接管");
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// ---------- 面板页 ----------
|
|
313
|
+
const CSS = [
|
|
314
|
+
".dkht{display:flex;flex-direction:column;gap:12px;}",
|
|
315
|
+
".dkht-intro{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.7;border:1px dashed var(--dsw-alias-border-l1);border-radius:8px;padding:8px 10px;}",
|
|
316
|
+
".dkht-group{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;padding:10px 12px;display:flex;flex-direction:column;gap:6px;background:var(--dsw-alias-bg-layer-1);}",
|
|
317
|
+
".dkht-group-head{display:flex;align-items:baseline;gap:8px;flex-wrap:wrap;}",
|
|
318
|
+
".dkht-group-name{font-weight:600;font-size:13px;}",
|
|
319
|
+
".dkht-group-desc{font-size:11px;color:var(--dsw-alias-label-tertiary);}",
|
|
320
|
+
".dkht-item{display:flex;gap:10px;align-items:flex-start;padding:8px 10px;border-radius:8px;cursor:pointer;border:1px solid transparent;transition:background .12s,border-color .12s;}",
|
|
321
|
+
".dkht-item:hover{background:var(--dsw-alias-interactive-bg-hover);}",
|
|
322
|
+
".dkht-item.on{border-color:color-mix(in srgb,var(--dk-accent) 35%,transparent);background:var(--dk-hover-tint);}",
|
|
323
|
+
".dkht-item.busy{opacity:.6;cursor:progress;}",
|
|
324
|
+
".dkht-check{width:15px;height:15px;margin:2px 0 0;accent-color:var(--dk-accent);flex:none;cursor:pointer;}",
|
|
325
|
+
".dkht-text{display:flex;flex-direction:column;gap:2px;min-width:0;}",
|
|
326
|
+
".dkht-name{font-size:12px;font-weight:600;}",
|
|
327
|
+
".dkht-desc{font-size:11px;line-height:1.6;color:var(--dsw-alias-label-secondary);}",
|
|
328
|
+
".dkht-error{color:var(--dsw-alias-state-error-primary);font-size:12px;line-height:1.6;}",
|
|
329
|
+
".dkht-empty{color:var(--dsw-alias-label-tertiary);font-size:12px;}",
|
|
330
|
+
".dkht-note{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:1.6;}",
|
|
331
|
+
].join("\n");
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* 面板页:按宿主清单渲染分组与勾选框。
|
|
335
|
+
* @param {{ctx?: object}} props 宿主插槽透传(本页不直接用)
|
|
336
|
+
*/
|
|
337
|
+
function DshToolsView(props) {
|
|
338
|
+
const [, force] = react.useReducer((n) => n + 1, 0);
|
|
339
|
+
const [busy, setBusy] = react.useState("");
|
|
340
|
+
const [error, setError] = react.useState("");
|
|
341
|
+
react.useEffect(() => {
|
|
342
|
+
const off = subscribe(() => force());
|
|
343
|
+
ensureLoaded().then(() => force());
|
|
344
|
+
return off;
|
|
345
|
+
}, []);
|
|
346
|
+
const toggle = async (group, item) => {
|
|
347
|
+
const id = group.id + "/" + item.key;
|
|
348
|
+
if (busy) return;
|
|
349
|
+
setBusy(id);
|
|
350
|
+
setError("");
|
|
351
|
+
try {
|
|
352
|
+
await setValue(group.id, item.key, item.value !== true);
|
|
353
|
+
} catch (e) {
|
|
354
|
+
setError(e && e.message ? e.message : String(e));
|
|
355
|
+
} finally {
|
|
356
|
+
setBusy("");
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const groups = store.groups;
|
|
360
|
+
return react.createElement("div", { className: "dkht" },
|
|
361
|
+
react.createElement("div", { className: "dkht-intro" },
|
|
362
|
+
"这里给 DSH 自带界面补充能力,按分组逐项勾选;勾选状态保存在功能坞设置里,换浏览器也一致。",
|
|
363
|
+
"取消勾选即完全撤掉对应入口,不影响 DSH 原有功能。"),
|
|
364
|
+
error ? react.createElement("div", { className: "dkht-error" }, error) : null,
|
|
365
|
+
store.error ? react.createElement("div", { className: "dkht-error" }, store.error) : null,
|
|
366
|
+
!store.ready && !store.error
|
|
367
|
+
? react.createElement("div", { className: "dkht-empty" }, "正在读取配置…")
|
|
368
|
+
: null,
|
|
369
|
+
groups.map((group) => react.createElement("div", { className: "dkht-group", key: group.id },
|
|
370
|
+
react.createElement("div", { className: "dkht-group-head" },
|
|
371
|
+
react.createElement("span", { className: "dkht-group-name" }, group.name),
|
|
372
|
+
group.description ? react.createElement("span", { className: "dkht-group-desc" }, group.description) : null),
|
|
373
|
+
group.items.map((item) => {
|
|
374
|
+
const id = group.id + "/" + item.key;
|
|
375
|
+
return react.createElement("label", {
|
|
376
|
+
key: item.key,
|
|
377
|
+
className: "dkht-item" + (item.value === true ? " on" : "") + (busy === id ? " busy" : ""),
|
|
378
|
+
},
|
|
379
|
+
react.createElement("input", {
|
|
380
|
+
type: "checkbox",
|
|
381
|
+
className: "dkht-check",
|
|
382
|
+
checked: item.value === true,
|
|
383
|
+
disabled: busy !== "",
|
|
384
|
+
onChange: () => { void toggle(group, item); },
|
|
385
|
+
}),
|
|
386
|
+
react.createElement("span", { className: "dkht-text" },
|
|
387
|
+
react.createElement("span", { className: "dkht-name" }, item.name),
|
|
388
|
+
item.description ? react.createElement("span", { className: "dkht-desc" }, item.description) : null));
|
|
389
|
+
}))),
|
|
390
|
+
react.createElement("div", { className: "dkht-note" },
|
|
391
|
+
"后续新增的 DSH 增强能力会以新分组/新勾选项出现在这里,无需另外配置。"));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export const feature = {
|
|
395
|
+
id: "dshtools",
|
|
396
|
+
name: "DSH功能",
|
|
397
|
+
order: 170,
|
|
398
|
+
accent: "#8b5cf6",
|
|
399
|
+
description: "给 DSH 自带界面补充能力(文件右键等),按分组勾选启用",
|
|
400
|
+
defaultEnabled: true,
|
|
401
|
+
css: CSS,
|
|
402
|
+
View: DshToolsView,
|
|
403
|
+
};
|