dsh-lan-guard 0.3.5 → 0.4.1
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/CHANGELOG.md +137 -0
- package/README.md +58 -2
- package/README.zh.md +57 -2
- package/lib/client.js +1038 -13
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +81 -0
- package/lib/index.js +992 -52
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -5,6 +5,663 @@ window.__ModuleLoader__.load({
|
|
|
5
5
|
var exports = module.exports;
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
7
|
let react = require("react");
|
|
8
|
+
//#region src/client/picker-logic.ts
|
|
9
|
+
/**
|
|
10
|
+
* dsh-lan-guard — browser-half decision logic for the workspace picker.
|
|
11
|
+
*
|
|
12
|
+
* Kept free of React and of the DOM so it can be unit-tested in a node
|
|
13
|
+
* environment: everything here is a pure function of facts the caller samples.
|
|
14
|
+
*
|
|
15
|
+
* The two decisions this module owns:
|
|
16
|
+
*
|
|
17
|
+
* 1. WHICH interaction this browser gets. The official directory-picker seam is
|
|
18
|
+
* resolved once per PROCESS, so DSH's own answer is "native" whenever its web
|
|
19
|
+
* server binds loopback — even for a phone on the LAN. The browser half
|
|
20
|
+
* therefore shadows the official flow occupant and answers the question per
|
|
21
|
+
* CLIENT: a browser sitting at this machine keeps the OS folder dialog, a
|
|
22
|
+
* remote one gets the in-page browser.
|
|
23
|
+
* 2. WHAT a failure means to the person holding the phone. Every refusal the
|
|
24
|
+
* management route can return maps to one sentence plus the exact way to fix
|
|
25
|
+
* it; a silent no-op is what this whole feature exists to remove.
|
|
26
|
+
*/
|
|
27
|
+
/** The management route that serves one directory level. */
|
|
28
|
+
const BROWSE_PATH = "/plugins/dsh-lan-guard/workspaces";
|
|
29
|
+
/**
|
|
30
|
+
* The management endpoint on DSH's own origin.
|
|
31
|
+
*
|
|
32
|
+
* Shared with the settings card so the picker can unlock the console IN PLACE
|
|
33
|
+
* instead of sending the operator hunting for the lock card in another tab.
|
|
34
|
+
*/
|
|
35
|
+
const CONFIG_PATH$1 = "/plugins/dsh-lan-guard/config";
|
|
36
|
+
/** The two directory-flow holes `ui-workspace` declares (`single` kind). */
|
|
37
|
+
const HERO_FLOW = "conversation.hero.workspace.directoryFlow";
|
|
38
|
+
const SIDEBAR_FLOW = "sidebar.workspaces.directoryFlow";
|
|
39
|
+
/** Whether a hostname names this machine's own loopback interface. */
|
|
40
|
+
function isLoopbackHostname(hostname) {
|
|
41
|
+
const normalized = hostname.trim().toLowerCase().replace(/^\[|\]$/g, "");
|
|
42
|
+
return normalized === "127.0.0.1" || normalized === "localhost" || normalized === "::1" || normalized === "";
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether this browser is sitting at the machine that runs DSH.
|
|
46
|
+
*
|
|
47
|
+
* This is the same evidence DSH's own connection client uses to decide that a
|
|
48
|
+
* page "owns the host", plus the desktop-shell markers: a preload picker or an
|
|
49
|
+
* Electron host means an OS dialog can actually be shown to the person looking
|
|
50
|
+
* at this window.
|
|
51
|
+
*
|
|
52
|
+
* @param env - the sampled DOM facts.
|
|
53
|
+
* @returns `native` to delegate to DSH's OS dialog, `browse` to render ours.
|
|
54
|
+
*/
|
|
55
|
+
function directoryFlowDecision(env) {
|
|
56
|
+
if (env.hasDesktopPicker) return "native";
|
|
57
|
+
if (env.hasNativeHost) return "native";
|
|
58
|
+
if (isLoopbackHostname(env.hostname)) return "native";
|
|
59
|
+
if (env.protocol === "file:" || env.protocol === "app:" || env.protocol === "vscode-webview:") return "native";
|
|
60
|
+
if (env.userAgent.includes("Electron")) return "native";
|
|
61
|
+
return "browse";
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Translate a refusal into something actionable.
|
|
65
|
+
*
|
|
66
|
+
* @param code - the `error` field of a management response, or a transport code.
|
|
67
|
+
* @returns the title and detail the page shows.
|
|
68
|
+
*/
|
|
69
|
+
function browseErrorNotice(code) {
|
|
70
|
+
switch (code) {
|
|
71
|
+
case "read_only_remote": return {
|
|
72
|
+
title: "远程设备当前只读",
|
|
73
|
+
detail: "在电脑上打开「设置 → 局域网访问 → 安全认证 → 远程设备管理权限」,选「密码解锁」(或「不锁定」),然后刷新本页。"
|
|
74
|
+
};
|
|
75
|
+
case "admin_required": return {
|
|
76
|
+
title: "需要先解锁管理控制台",
|
|
77
|
+
detail: "在「设置 → 局域网访问 → 安全认证」输入管理密码解锁,然后回到这里重试。"
|
|
78
|
+
};
|
|
79
|
+
case "rate_limited": return {
|
|
80
|
+
title: "请求过于频繁",
|
|
81
|
+
detail: "稍等几秒再试。"
|
|
82
|
+
};
|
|
83
|
+
case "blocked": return {
|
|
84
|
+
title: "该目录被安全策略禁止",
|
|
85
|
+
detail: "系统目录与凭据目录(.ssh、.aws、.env 等)不能浏览,也不能作为工作区。"
|
|
86
|
+
};
|
|
87
|
+
case "not_found": return {
|
|
88
|
+
title: "目录不存在",
|
|
89
|
+
detail: "它可能已经被移动或删除,返回上一层再选一次。"
|
|
90
|
+
};
|
|
91
|
+
case "not_a_directory": return {
|
|
92
|
+
title: "这不是一个文件夹",
|
|
93
|
+
detail: "工作区必须是一个目录。"
|
|
94
|
+
};
|
|
95
|
+
case "not_absolute":
|
|
96
|
+
case "invalid_path": return {
|
|
97
|
+
title: "路径无效",
|
|
98
|
+
detail: "请使用完整的绝对路径。"
|
|
99
|
+
};
|
|
100
|
+
case "unreadable": return {
|
|
101
|
+
title: "无法读取该目录",
|
|
102
|
+
detail: "权限不足或磁盘不可用。"
|
|
103
|
+
};
|
|
104
|
+
case "forbidden":
|
|
105
|
+
case "unauthorized": return {
|
|
106
|
+
title: "会话已失效",
|
|
107
|
+
detail: "刷新页面重新登录后再试。"
|
|
108
|
+
};
|
|
109
|
+
default: return {
|
|
110
|
+
title: "无法读取目录",
|
|
111
|
+
detail: code === "" ? "未知错误。" : code
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** An error carrying the server's stable code. */
|
|
116
|
+
var BrowseRequestError = class extends Error {
|
|
117
|
+
code;
|
|
118
|
+
constructor(code, message) {
|
|
119
|
+
super(message);
|
|
120
|
+
this.name = "BrowseRequestError";
|
|
121
|
+
this.code = code;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Turn one management response into a listing, or throw the stable code.
|
|
126
|
+
*
|
|
127
|
+
* @param status - the HTTP status.
|
|
128
|
+
* @param body - the parsed JSON body, when it parsed.
|
|
129
|
+
* @returns the listing.
|
|
130
|
+
*/
|
|
131
|
+
function readBrowseResponse(status, body) {
|
|
132
|
+
const record = typeof body === "object" && body !== null ? body : {};
|
|
133
|
+
if (status === 200 && record.ok === true) return {
|
|
134
|
+
path: typeof record.path === "string" ? record.path : "",
|
|
135
|
+
crumbs: Array.isArray(record.crumbs) ? record.crumbs : [],
|
|
136
|
+
quick: Array.isArray(record.quick) ? record.quick : [],
|
|
137
|
+
entries: Array.isArray(record.entries) ? record.entries : [],
|
|
138
|
+
truncated: record.truncated === true
|
|
139
|
+
};
|
|
140
|
+
const code = typeof record.error === "string" && record.error !== "" ? record.error : status === 401 ? "unauthorized" : status === 403 ? "forbidden" : `http_${String(status)}`;
|
|
141
|
+
throw new BrowseRequestError(code, code);
|
|
142
|
+
}
|
|
143
|
+
/** Sample the browser facts {@link directoryFlowDecision} needs. */
|
|
144
|
+
function readClientEnvironment() {
|
|
145
|
+
const scope = globalThis;
|
|
146
|
+
return {
|
|
147
|
+
hostname: scope.location?.hostname ?? "",
|
|
148
|
+
protocol: scope.location?.protocol ?? "",
|
|
149
|
+
userAgent: scope.navigator?.userAgent ?? "",
|
|
150
|
+
hasDesktopPicker: scope.__DSH_DIRECTORY_PICKER__ !== void 0,
|
|
151
|
+
hasNativeHost: scope.electron !== void 0 || scope.__DSH_NATIVE_HOST__ !== void 0
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Register the shadowing occupant into both directory-flow holes.
|
|
156
|
+
*
|
|
157
|
+
* `slots.inject` (not a bare `register`) because `ui-workspace` may declare the
|
|
158
|
+
* holes after this plugin applies — the same transactional nesting the official
|
|
159
|
+
* surface uses. The `priority` is what makes the whole feature possible: a
|
|
160
|
+
* `single` slot renders its LOWEST-priority occupant, so this registration
|
|
161
|
+
* shadows DSH's native surface without a duplicate-registration error, and the
|
|
162
|
+
* occupant itself decides per client which interaction runs.
|
|
163
|
+
*
|
|
164
|
+
* Lives here (not next to the component) so the contract is testable without a
|
|
165
|
+
* browser or React.
|
|
166
|
+
*
|
|
167
|
+
* @param slots - the client slot registry.
|
|
168
|
+
* @param component - the occupant component to register.
|
|
169
|
+
* @param injected - the `pick` / `browse` calls handed to that component.
|
|
170
|
+
*/
|
|
171
|
+
function registerDirectoryFlow(slots, component, injected) {
|
|
172
|
+
const inject = () => injected;
|
|
173
|
+
slots.inject(HERO_FLOW, () => slots.inject(SIDEBAR_FLOW, function* () {
|
|
174
|
+
yield slots.register({
|
|
175
|
+
name: HERO_FLOW,
|
|
176
|
+
priority: -20,
|
|
177
|
+
inject
|
|
178
|
+
}, component);
|
|
179
|
+
yield slots.register({
|
|
180
|
+
name: SIDEBAR_FLOW,
|
|
181
|
+
priority: -20,
|
|
182
|
+
inject
|
|
183
|
+
}, component);
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/client/workspace-flow.ts
|
|
188
|
+
/**
|
|
189
|
+
* dsh-lan-guard — the browser half of the remote workspace picker.
|
|
190
|
+
*
|
|
191
|
+
* DSH's directory-picker seam is resolved once per PROCESS
|
|
192
|
+
* (`@deepseek-ai/dsh-host-directory-picker-auto`), and because DSH's own web
|
|
193
|
+
* server binds loopback that resolution is `native` on macOS/Windows: the OS
|
|
194
|
+
* folder dialog opens on the HOST screen. A phone that reached this machine
|
|
195
|
+
* through the LAN gateway therefore cannot add a workspace at all.
|
|
196
|
+
*
|
|
197
|
+
* A `single` slot renders its LOWEST-priority occupant, so this module registers
|
|
198
|
+
* a shadowing occupant at {@link FLOW_PRIORITY} and decides per CLIENT:
|
|
199
|
+
*
|
|
200
|
+
* - a browser sitting at this machine delegates to DSH's own picker (the desktop
|
|
201
|
+
* preload when present, otherwise the official `uiWorkspace.pickDirectory()`),
|
|
202
|
+
* so the operator's OS dialog is untouched;
|
|
203
|
+
* - a remote browser gets this module's own bottom-sheet directory browser,
|
|
204
|
+
* backed by one management route (`GET …/workspaces?path=…`).
|
|
205
|
+
*
|
|
206
|
+
* The occupant is RENDERLESS until a pick is requested, and it never registers a
|
|
207
|
+
* workspace itself: it reports the chosen path through the owner's `onPicked`,
|
|
208
|
+
* and DSH's own workspace flow performs the (validated, persisted) registration.
|
|
209
|
+
*/
|
|
210
|
+
/** The stable code of a failed request. */
|
|
211
|
+
function codeOf(reason) {
|
|
212
|
+
if (reason instanceof BrowseRequestError) return reason.code;
|
|
213
|
+
if (reason instanceof Error) return reason.message;
|
|
214
|
+
return String(reason);
|
|
215
|
+
}
|
|
216
|
+
/** A human message for a thrown reason. */
|
|
217
|
+
function messageOf(reason) {
|
|
218
|
+
return reason instanceof Error ? reason.message : String(reason);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Unlock the management console from inside the picker.
|
|
222
|
+
*
|
|
223
|
+
* The unlock is the ONE management write that never requires an unlocked
|
|
224
|
+
* console (it IS the unlock), so this works under `password_unlock` even though
|
|
225
|
+
* every other route refuses. Doing it here removes the dead end where the sheet
|
|
226
|
+
* says "go unlock in Settings" and the operator has to find the lock card.
|
|
227
|
+
*
|
|
228
|
+
* @param password - the admin password (or the access password when no separate
|
|
229
|
+
* admin password is set, which is how the host falls back).
|
|
230
|
+
*/
|
|
231
|
+
async function postAdminUnlock(password) {
|
|
232
|
+
const response = await fetch(CONFIG_PATH$1, {
|
|
233
|
+
method: "POST",
|
|
234
|
+
credentials: "same-origin",
|
|
235
|
+
headers: {
|
|
236
|
+
"content-type": "application/json",
|
|
237
|
+
accept: "application/json"
|
|
238
|
+
},
|
|
239
|
+
body: JSON.stringify({ adminUnlock: password })
|
|
240
|
+
});
|
|
241
|
+
if (response.status === 401) throw new Error("管理密码不正确");
|
|
242
|
+
if (!response.ok) throw new Error(`解锁失败(HTTP ${String(response.status)})`);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Read one directory level from the management route.
|
|
246
|
+
*
|
|
247
|
+
* @param path - the directory to list; omitted lists the host's home directory.
|
|
248
|
+
* @returns the listing.
|
|
249
|
+
*/
|
|
250
|
+
async function fetchListing(path) {
|
|
251
|
+
const query = path === void 0 ? "" : `?path=${encodeURIComponent(path)}`;
|
|
252
|
+
const response = await fetch(`${BROWSE_PATH}${query}`, {
|
|
253
|
+
credentials: "same-origin",
|
|
254
|
+
headers: { accept: "application/json" }
|
|
255
|
+
});
|
|
256
|
+
let body = null;
|
|
257
|
+
try {
|
|
258
|
+
body = await response.json();
|
|
259
|
+
} catch {
|
|
260
|
+
body = null;
|
|
261
|
+
}
|
|
262
|
+
return readBrowseResponse(response.status, body);
|
|
263
|
+
}
|
|
264
|
+
/** Look a client service up without requiring it. */
|
|
265
|
+
function optionalService(ctx, name) {
|
|
266
|
+
try {
|
|
267
|
+
return ctx.get?.(name);
|
|
268
|
+
} catch {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The official picker for THIS browser, when it has one.
|
|
274
|
+
*
|
|
275
|
+
* Mirrors the official native surface: the desktop shell's preload picker wins,
|
|
276
|
+
* then the client service. Either way the dialog appears on the machine the
|
|
277
|
+
* browser is running on — which is exactly what makes this the LOCAL branch.
|
|
278
|
+
*
|
|
279
|
+
* @param ctx - the client context.
|
|
280
|
+
* @returns the pick function, or `undefined` when this host has none.
|
|
281
|
+
*/
|
|
282
|
+
function officialPick(ctx) {
|
|
283
|
+
const desktop = globalThis.__DSH_DIRECTORY_PICKER__;
|
|
284
|
+
if (desktop !== void 0 && typeof desktop.pick === "function") return () => desktop.pick?.() ?? Promise.resolve(null);
|
|
285
|
+
const ui = optionalService(ctx, "uiWorkspace");
|
|
286
|
+
if (ui !== void 0 && typeof ui.pickDirectory === "function") return () => ui.pickDirectory?.() ?? Promise.resolve(null);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Typography and materials come from the official tokens only, exactly as the
|
|
290
|
+
* settings card does; the sheet is a bottom sheet on phones and a centred card
|
|
291
|
+
* from 620px up.
|
|
292
|
+
*/
|
|
293
|
+
const FLOW_CSS = `
|
|
294
|
+
.lgp-scrim{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:flex-end;justify-content:center;
|
|
295
|
+
background:color-mix(in srgb, var(--dsw-alias-bg-mask,#000) 46%, transparent);backdrop-filter:blur(6px);
|
|
296
|
+
-webkit-backdrop-filter:blur(6px)}
|
|
297
|
+
/*
|
|
298
|
+
* FLEX SHRINK IS EXPLICIT ON EVERY FIXED ROW (user report 2026-09-26: the
|
|
299
|
+
* breadcrumb and the quick-access rows were crushed into one overlapping strip).
|
|
300
|
+
* A flex item's AUTOMATIC minimum size resolves to 0 as soon as its overflow is
|
|
301
|
+
* not visible, and both rows scroll horizontally — so the moment the sheet hit
|
|
302
|
+
* its max-height the browser shrank exactly those two rows to nothing while the
|
|
303
|
+
* list kept its floor. Only the list may flex; everything else is fixed.
|
|
304
|
+
*/
|
|
305
|
+
.lgp-sheet{box-sizing:border-box;width:100%;max-width:560px;max-height:86vh;display:flex;flex-direction:column;
|
|
306
|
+
overflow:hidden;
|
|
307
|
+
background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l2,#e5e6eb);
|
|
308
|
+
border-radius:20px 20px 0 0;box-shadow:0 -12px 40px color-mix(in srgb, #000 26%, transparent);
|
|
309
|
+
padding:16px 16px calc(16px + env(safe-area-inset-bottom,0px));gap:12px}
|
|
310
|
+
.lgp-head{flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;gap:12px}
|
|
311
|
+
.lgp-title{font:var(--dsw-font-base-16-strong,500 16px/24px sans-serif);color:var(--dsw-alias-label-primary,#1f2329);margin:0}
|
|
312
|
+
.lgp-x{flex:0 0 auto;width:32px;height:32px;border-radius:50%;border:0.5px solid var(--dsw-alias-border-l2,#e5e6eb);
|
|
313
|
+
background:transparent;color:var(--dsw-alias-label-primary,#1f2329);cursor:pointer;font-size:16px;line-height:1}
|
|
314
|
+
.lgp-crumbs,.lgp-quick{flex:0 0 auto;display:flex;align-items:center;gap:8px;overflow-x:auto;overflow-y:hidden;
|
|
315
|
+
padding-bottom:2px;scrollbar-width:none}
|
|
316
|
+
.lgp-crumbs::-webkit-scrollbar,.lgp-quick::-webkit-scrollbar,.lgp-list::-webkit-scrollbar{display:none}
|
|
317
|
+
.lgp-crumb{flex:0 0 auto;border:0;background:transparent;color:var(--dsw-alias-label-secondary,#4e5969);
|
|
318
|
+
font:var(--dsw-font-xs-13,13px/20px sans-serif);cursor:pointer;padding:4px 6px;border-radius:8px;white-space:nowrap}
|
|
319
|
+
.lgp-crumb[aria-current=true]{color:var(--dsw-alias-label-primary,#1f2329);font:var(--dsw-font-xs-13-strong,500 13px/20px sans-serif);
|
|
320
|
+
background:var(--dsw-alias-bg-layer-3,#f1f2f4)}
|
|
321
|
+
.lgp-quickbtn{flex:0 0 auto;border:0.5px solid var(--dsw-alias-border-l2,#e5e6eb);border-radius:999px;
|
|
322
|
+
background:transparent;color:var(--dsw-alias-label-primary,#1f2329);font:var(--dsw-font-xs-13,13px/20px sans-serif);
|
|
323
|
+
padding:6px 12px;cursor:pointer;white-space:nowrap}
|
|
324
|
+
/* The list is the ONLY flexible row: it absorbs every bit of shrinkage, so the
|
|
325
|
+
fixed rows above and the action buttons below stay whole on a short viewport. */
|
|
326
|
+
.lgp-list{flex:1 1 auto;min-height:0;overflow-y:auto;display:flex;flex-direction:column;gap:2px;
|
|
327
|
+
border:1px solid var(--dsw-alias-border-l2,#e5e6eb);border-radius:14px;padding:6px}
|
|
328
|
+
.lgp-row{display:flex;align-items:center;gap:8px;width:100%;text-align:left;border:0;background:transparent;
|
|
329
|
+
color:var(--dsw-alias-label-primary,#1f2329);font:var(--dsw-font-s-14,14px/22px sans-serif);
|
|
330
|
+
padding:10px 10px;border-radius:10px;cursor:pointer;min-height:44px}
|
|
331
|
+
.lgp-row:hover{background:var(--dsw-alias-bg-layer-3,#f1f2f4)}
|
|
332
|
+
.lgp-row .lgp-dir{flex:0 0 auto;opacity:.85}
|
|
333
|
+
.lgp-row .lgp-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
334
|
+
.lgp-row[data-hidden=true] .lgp-name{color:var(--dsw-alias-label-tertiary,#adb2b8)}
|
|
335
|
+
.lgp-hint{margin:0;padding:10px 4px;color:var(--dsw-alias-label-secondary,#4e5969);font:var(--dsw-font-xs-13,13px/20px sans-serif)}
|
|
336
|
+
.lgp-notice{flex:0 0 auto;border:1px solid var(--dsw-alias-border-l2,#e5e6eb);border-left:3px solid var(--dsw-alias-state-warning-primary,#d25f00);
|
|
337
|
+
border-radius:10px;padding:10px 12px;display:flex;flex-direction:column;gap:4px}
|
|
338
|
+
.lgp-notice h4{margin:0;font:var(--dsw-font-xs-13-strong,500 13px/20px sans-serif);color:var(--dsw-alias-label-primary,#1f2329)}
|
|
339
|
+
.lgp-notice p{margin:0;font:var(--dsw-font-xs-13,13px/20px sans-serif);color:var(--dsw-alias-label-secondary,#4e5969)}
|
|
340
|
+
.lgp-unlock{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin-top:6px}
|
|
341
|
+
.lgp-input{flex:1 1 12ch;min-width:0;height:40px;box-sizing:border-box;border-radius:10px;padding:0 12px;
|
|
342
|
+
border:1px solid var(--dsw-alias-border-l2,#e5e6eb);background:var(--dsw-alias-bg-layer-2,#fff);
|
|
343
|
+
color:var(--dsw-alias-label-primary,#1f2329);font:var(--dsw-font-s-14,14px/22px sans-serif)}
|
|
344
|
+
.lgp-btn-inline{flex:0 0 auto;min-width:88px;min-height:40px;padding:0 16px}
|
|
345
|
+
.lgp-code{font:var(--dsw-font-xxs-12,12px/18px ui-monospace,SFMono-Regular,Menlo,monospace);
|
|
346
|
+
color:var(--dsw-alias-label-tertiary,#adb2b8)}
|
|
347
|
+
.lgp-foot{flex:0 0 auto;display:flex;flex-direction:column;gap:10px}
|
|
348
|
+
.lgp-path{font:var(--dsw-font-xxs-12,12px/18px ui-monospace,SFMono-Regular,Menlo,monospace);
|
|
349
|
+
color:var(--dsw-alias-label-secondary,#4e5969);overflow-x:auto;white-space:nowrap;scrollbar-width:none}
|
|
350
|
+
.lgp-actions{display:flex;gap:10px}
|
|
351
|
+
.lgp-btn{flex:1 1 auto;min-height:44px;border-radius:12px;cursor:pointer;
|
|
352
|
+
font:var(--dsw-font-s-14-strong,500 14px/22px sans-serif);border:1px solid transparent}
|
|
353
|
+
.lgp-btn.primary{background:var(--dsw-alias-state-business-primary,#1a3f8f);color:#fff}
|
|
354
|
+
.lgp-btn.ghost{background:transparent;border-color:var(--dsw-alias-border-l2,#e5e6eb);color:var(--dsw-alias-label-primary,#1f2329)}
|
|
355
|
+
.lgp-btn[disabled]{opacity:.5;cursor:default}
|
|
356
|
+
.lgp-busy{align-self:center;margin:auto;padding:16px 20px;border-radius:14px;background:var(--dsw-alias-bg-layer-1,#fff);
|
|
357
|
+
color:var(--dsw-alias-label-primary,#1f2329);font:var(--dsw-font-s-14,14px/22px sans-serif)}
|
|
358
|
+
@media (min-width:620px){
|
|
359
|
+
.lgp-scrim{align-items:center}
|
|
360
|
+
.lgp-sheet{border-radius:20px;max-height:80vh;padding:18px 20px}
|
|
361
|
+
}
|
|
362
|
+
`;
|
|
363
|
+
/**
|
|
364
|
+
* The shadowing flow occupant.
|
|
365
|
+
*
|
|
366
|
+
* Renderless until the owner opens a pick. One pick per rising `open` edge, one
|
|
367
|
+
* outcome per pick — the same contract the official occupant implements, so the
|
|
368
|
+
* owner cannot tell the difference.
|
|
369
|
+
*
|
|
370
|
+
* @param props - the owner conversation plus the injected pick/browse calls.
|
|
371
|
+
* @returns the sheet while a remote pick is in flight, otherwise nothing.
|
|
372
|
+
*/
|
|
373
|
+
function DirectoryFlow(props) {
|
|
374
|
+
const { open, pick, browse } = props;
|
|
375
|
+
const latest = (0, react.useRef)(props);
|
|
376
|
+
latest.current = props;
|
|
377
|
+
const armed = (0, react.useRef)(false);
|
|
378
|
+
const alive = (0, react.useRef)(true);
|
|
379
|
+
const [listing, setListing] = (0, react.useState)(null);
|
|
380
|
+
const [notice, setNotice] = (0, react.useState)(null);
|
|
381
|
+
/** The server's stable code behind {@link notice}; drives the inline unlock. */
|
|
382
|
+
const [failureCode, setFailureCode] = (0, react.useState)(null);
|
|
383
|
+
const [loading, setLoading] = (0, react.useState)(false);
|
|
384
|
+
const [unlockPassword, setUnlockPassword] = (0, react.useState)("");
|
|
385
|
+
const [unlockBusy, setUnlockBusy] = (0, react.useState)(false);
|
|
386
|
+
const [unlockError, setUnlockError] = (0, react.useState)(null);
|
|
387
|
+
/** The path a retry should re-list (the last one shown, or the home directory). */
|
|
388
|
+
const lastPath = (0, react.useRef)(void 0);
|
|
389
|
+
(0, react.useEffect)(() => {
|
|
390
|
+
alive.current = true;
|
|
391
|
+
return () => {
|
|
392
|
+
alive.current = false;
|
|
393
|
+
};
|
|
394
|
+
}, []);
|
|
395
|
+
const load = (0, react.useCallback)((path) => {
|
|
396
|
+
lastPath.current = path ?? lastPath.current;
|
|
397
|
+
setLoading(true);
|
|
398
|
+
setNotice(null);
|
|
399
|
+
setFailureCode(null);
|
|
400
|
+
browse(path).then((next) => {
|
|
401
|
+
if (!alive.current || !latest.current.open) return;
|
|
402
|
+
setListing(next);
|
|
403
|
+
setLoading(false);
|
|
404
|
+
}, (reason) => {
|
|
405
|
+
if (!alive.current || !latest.current.open) return;
|
|
406
|
+
setNotice(browseErrorNotice(codeOf(reason)));
|
|
407
|
+
setFailureCode(codeOf(reason));
|
|
408
|
+
setLoading(false);
|
|
409
|
+
});
|
|
410
|
+
}, [browse]);
|
|
411
|
+
(0, react.useEffect)(() => {
|
|
412
|
+
if (!open) {
|
|
413
|
+
armed.current = false;
|
|
414
|
+
setListing(null);
|
|
415
|
+
setNotice(null);
|
|
416
|
+
setFailureCode(null);
|
|
417
|
+
setLoading(false);
|
|
418
|
+
setUnlockPassword("");
|
|
419
|
+
setUnlockError(null);
|
|
420
|
+
lastPath.current = void 0;
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (armed.current) return;
|
|
424
|
+
armed.current = true;
|
|
425
|
+
if (directoryFlowDecision(readClientEnvironment()) === "native") {
|
|
426
|
+
let pending;
|
|
427
|
+
try {
|
|
428
|
+
pending = pick();
|
|
429
|
+
} catch (reason) {
|
|
430
|
+
latest.current.onError(messageOf(reason));
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
pending.then((path) => {
|
|
434
|
+
if (!alive.current) return;
|
|
435
|
+
if (path === null) latest.current.onCancel();
|
|
436
|
+
else latest.current.onPicked(path);
|
|
437
|
+
}, (reason) => {
|
|
438
|
+
if (alive.current) latest.current.onError(messageOf(reason));
|
|
439
|
+
});
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
load(void 0);
|
|
443
|
+
}, [
|
|
444
|
+
open,
|
|
445
|
+
pick,
|
|
446
|
+
load
|
|
447
|
+
]);
|
|
448
|
+
(0, react.useEffect)(() => {
|
|
449
|
+
if (!open) return void 0;
|
|
450
|
+
const onKey = (event) => {
|
|
451
|
+
if (event.key === "Escape") latest.current.onCancel();
|
|
452
|
+
};
|
|
453
|
+
document.addEventListener("keydown", onKey);
|
|
454
|
+
return () => {
|
|
455
|
+
document.removeEventListener("keydown", onKey);
|
|
456
|
+
};
|
|
457
|
+
}, [open]);
|
|
458
|
+
if (!open) return null;
|
|
459
|
+
if (directoryFlowDecision(readClientEnvironment()) !== "browse") return null;
|
|
460
|
+
if (props.busy === true) return (0, react.createElement)("div", { className: "lgp-scrim" }, [(0, react.createElement)("style", { key: "css" }, FLOW_CSS), (0, react.createElement)("div", {
|
|
461
|
+
className: "lgp-busy",
|
|
462
|
+
role: "status",
|
|
463
|
+
key: "busy"
|
|
464
|
+
}, "正在添加工作区…")]);
|
|
465
|
+
const stop = (event) => {
|
|
466
|
+
event.stopPropagation();
|
|
467
|
+
};
|
|
468
|
+
const cancel = () => {
|
|
469
|
+
latest.current.onCancel();
|
|
470
|
+
};
|
|
471
|
+
/** Unlock in place, then list the same directory again. */
|
|
472
|
+
const submitUnlock = () => {
|
|
473
|
+
if (unlockPassword === "" || unlockBusy) return;
|
|
474
|
+
setUnlockBusy(true);
|
|
475
|
+
setUnlockError(null);
|
|
476
|
+
postAdminUnlock(unlockPassword).then(() => {
|
|
477
|
+
if (!alive.current) return;
|
|
478
|
+
setUnlockPassword("");
|
|
479
|
+
setUnlockBusy(false);
|
|
480
|
+
load(lastPath.current);
|
|
481
|
+
}, (reason) => {
|
|
482
|
+
if (!alive.current) return;
|
|
483
|
+
setUnlockError(messageOf(reason));
|
|
484
|
+
setUnlockBusy(false);
|
|
485
|
+
});
|
|
486
|
+
};
|
|
487
|
+
const crumbs = listing?.crumbs ?? [];
|
|
488
|
+
const rows = listing?.entries ?? [];
|
|
489
|
+
/** The console is locked: offer the unlock right here instead of a dead end. */
|
|
490
|
+
const needsUnlock = failureCode === "admin_required";
|
|
491
|
+
return (0, react.createElement)("div", {
|
|
492
|
+
className: "lgp-scrim",
|
|
493
|
+
key: "scrim",
|
|
494
|
+
onClick: cancel
|
|
495
|
+
}, [(0, react.createElement)("style", { key: "css" }, FLOW_CSS), (0, react.createElement)("div", {
|
|
496
|
+
key: "sheet",
|
|
497
|
+
className: "lgp-sheet",
|
|
498
|
+
role: "dialog",
|
|
499
|
+
"aria-modal": "true",
|
|
500
|
+
"aria-label": "选择工作区目录",
|
|
501
|
+
onClick: stop
|
|
502
|
+
}, [
|
|
503
|
+
(0, react.createElement)("div", {
|
|
504
|
+
className: "lgp-head",
|
|
505
|
+
key: "head"
|
|
506
|
+
}, [(0, react.createElement)("h3", {
|
|
507
|
+
className: "lgp-title",
|
|
508
|
+
key: "t"
|
|
509
|
+
}, "选择工作区目录"), (0, react.createElement)("button", {
|
|
510
|
+
key: "x",
|
|
511
|
+
type: "button",
|
|
512
|
+
className: "lgp-x",
|
|
513
|
+
"aria-label": "取消",
|
|
514
|
+
onClick: cancel
|
|
515
|
+
}, "✕")]),
|
|
516
|
+
notice === null ? null : (0, react.createElement)("div", {
|
|
517
|
+
className: "lgp-notice",
|
|
518
|
+
key: "notice",
|
|
519
|
+
role: "alert"
|
|
520
|
+
}, [
|
|
521
|
+
(0, react.createElement)("h4", { key: "t" }, notice.title),
|
|
522
|
+
(0, react.createElement)("p", { key: "d" }, notice.detail),
|
|
523
|
+
needsUnlock ? (0, react.createElement)("div", {
|
|
524
|
+
className: "lgp-unlock",
|
|
525
|
+
key: "unlock"
|
|
526
|
+
}, [
|
|
527
|
+
(0, react.createElement)("input", {
|
|
528
|
+
key: "i",
|
|
529
|
+
className: "lgp-input",
|
|
530
|
+
type: "password",
|
|
531
|
+
autoComplete: "current-password",
|
|
532
|
+
placeholder: "管理密码(未设置时用访问密码)",
|
|
533
|
+
value: unlockPassword,
|
|
534
|
+
disabled: unlockBusy,
|
|
535
|
+
onChange: (event) => {
|
|
536
|
+
setUnlockPassword(event.target.value);
|
|
537
|
+
},
|
|
538
|
+
onKeyDown: (event) => {
|
|
539
|
+
if (event.key === "Enter") submitUnlock();
|
|
540
|
+
}
|
|
541
|
+
}),
|
|
542
|
+
(0, react.createElement)("button", {
|
|
543
|
+
key: "b",
|
|
544
|
+
type: "button",
|
|
545
|
+
className: "lgp-btn primary lgp-btn-inline",
|
|
546
|
+
disabled: unlockBusy || unlockPassword === "",
|
|
547
|
+
onClick: submitUnlock
|
|
548
|
+
}, unlockBusy ? "解锁中…" : "解锁"),
|
|
549
|
+
unlockError === null ? null : (0, react.createElement)("p", {
|
|
550
|
+
className: "lgp-hint",
|
|
551
|
+
key: "e"
|
|
552
|
+
}, unlockError)
|
|
553
|
+
]) : (0, react.createElement)("div", {
|
|
554
|
+
className: "lgp-unlock",
|
|
555
|
+
key: "retry"
|
|
556
|
+
}, [(0, react.createElement)("button", {
|
|
557
|
+
key: "r",
|
|
558
|
+
type: "button",
|
|
559
|
+
className: "lgp-btn ghost lgp-btn-inline",
|
|
560
|
+
onClick: () => {
|
|
561
|
+
load(lastPath.current);
|
|
562
|
+
}
|
|
563
|
+
}, "重试"), (0, react.createElement)("span", {
|
|
564
|
+
className: "lgp-code",
|
|
565
|
+
key: "c"
|
|
566
|
+
}, failureCode ?? "")])
|
|
567
|
+
]),
|
|
568
|
+
crumbs.length === 0 ? null : (0, react.createElement)("div", {
|
|
569
|
+
className: "lgp-crumbs",
|
|
570
|
+
key: "crumbs"
|
|
571
|
+
}, crumbs.map((crumb, index) => (0, react.createElement)("button", {
|
|
572
|
+
key: crumb.path,
|
|
573
|
+
type: "button",
|
|
574
|
+
className: "lgp-crumb",
|
|
575
|
+
"aria-current": index === crumbs.length - 1,
|
|
576
|
+
onClick: () => {
|
|
577
|
+
load(crumb.path);
|
|
578
|
+
}
|
|
579
|
+
}, crumb.name))),
|
|
580
|
+
(listing?.quick?.length ?? 0) === 0 ? null : (0, react.createElement)("div", {
|
|
581
|
+
className: "lgp-quick",
|
|
582
|
+
key: "quick"
|
|
583
|
+
}, (listing?.quick ?? []).map((entry) => (0, react.createElement)("button", {
|
|
584
|
+
key: entry.path,
|
|
585
|
+
type: "button",
|
|
586
|
+
className: "lgp-quickbtn",
|
|
587
|
+
onClick: () => {
|
|
588
|
+
load(entry.path);
|
|
589
|
+
}
|
|
590
|
+
}, entry.name))),
|
|
591
|
+
(0, react.createElement)("div", {
|
|
592
|
+
className: "lgp-list",
|
|
593
|
+
key: "list"
|
|
594
|
+
}, loading ? [(0, react.createElement)("p", {
|
|
595
|
+
className: "lgp-hint",
|
|
596
|
+
key: "loading"
|
|
597
|
+
}, "正在读取…")] : listing === null ? [(0, react.createElement)("p", {
|
|
598
|
+
className: "lgp-hint",
|
|
599
|
+
key: "blocked"
|
|
600
|
+
}, "目录暂时无法读取,见上方提示。")] : rows.length === 0 ? [(0, react.createElement)("p", {
|
|
601
|
+
className: "lgp-hint",
|
|
602
|
+
key: "empty"
|
|
603
|
+
}, "这个文件夹里没有子文件夹")] : rows.map((entry) => (0, react.createElement)("button", {
|
|
604
|
+
key: entry.path,
|
|
605
|
+
type: "button",
|
|
606
|
+
className: "lgp-row",
|
|
607
|
+
"data-hidden": entry.hidden,
|
|
608
|
+
onClick: () => {
|
|
609
|
+
load(entry.path);
|
|
610
|
+
}
|
|
611
|
+
}, [(0, react.createElement)("span", {
|
|
612
|
+
className: "lgp-dir",
|
|
613
|
+
key: "i"
|
|
614
|
+
}, "📁"), (0, react.createElement)("span", {
|
|
615
|
+
className: "lgp-name",
|
|
616
|
+
key: "n"
|
|
617
|
+
}, entry.name)]))),
|
|
618
|
+
listing?.truncated === true ? (0, react.createElement)("p", {
|
|
619
|
+
className: "lgp-hint",
|
|
620
|
+
key: "trunc"
|
|
621
|
+
}, "子文件夹太多,只显示了前一部分。") : null,
|
|
622
|
+
(0, react.createElement)("div", {
|
|
623
|
+
className: "lgp-foot",
|
|
624
|
+
key: "foot"
|
|
625
|
+
}, [(0, react.createElement)("div", {
|
|
626
|
+
className: "lgp-path",
|
|
627
|
+
key: "p",
|
|
628
|
+
title: listing?.path ?? ""
|
|
629
|
+
}, listing?.path ?? ""), (0, react.createElement)("div", {
|
|
630
|
+
className: "lgp-actions",
|
|
631
|
+
key: "a"
|
|
632
|
+
}, [(0, react.createElement)("button", {
|
|
633
|
+
key: "cancel",
|
|
634
|
+
type: "button",
|
|
635
|
+
className: "lgp-btn ghost",
|
|
636
|
+
onClick: cancel
|
|
637
|
+
}, "取消"), (0, react.createElement)("button", {
|
|
638
|
+
key: "use",
|
|
639
|
+
type: "button",
|
|
640
|
+
className: "lgp-btn primary",
|
|
641
|
+
disabled: listing === null,
|
|
642
|
+
onClick: () => {
|
|
643
|
+
if (listing !== null) latest.current.onPicked(listing.path);
|
|
644
|
+
}
|
|
645
|
+
}, "使用此目录")])])
|
|
646
|
+
].filter(Boolean))]);
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Register the shadowing occupant into both directory-flow holes.
|
|
650
|
+
*
|
|
651
|
+
* @param ctx - the client plugin context.
|
|
652
|
+
*/
|
|
653
|
+
function applyDirectoryFlow(ctx) {
|
|
654
|
+
const pick = () => {
|
|
655
|
+
const official = officialPick(ctx);
|
|
656
|
+
if (official === void 0) throw new Error("这台主机没有可用的系统目录选择器");
|
|
657
|
+
return official();
|
|
658
|
+
};
|
|
659
|
+
registerDirectoryFlow(ctx.slots, DirectoryFlow, {
|
|
660
|
+
pick,
|
|
661
|
+
browse: fetchListing
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
//#endregion
|
|
8
665
|
//#region src/client.ts
|
|
9
666
|
/**
|
|
10
667
|
* dsh-lan-guard — the browser half: one section inside DSH's OFFICIAL settings
|
|
@@ -34,7 +691,7 @@ window.__ModuleLoader__.load({
|
|
|
34
691
|
/** The official additive settings seat. */
|
|
35
692
|
const SEAT = "settings.section";
|
|
36
693
|
/** The management endpoint on DSH's own origin. */
|
|
37
|
-
const CONFIG_PATH =
|
|
694
|
+
const CONFIG_PATH = CONFIG_PATH$1;
|
|
38
695
|
/** The four credential modes offered by the big-card selector. */
|
|
39
696
|
const MODE_CHOICES = [
|
|
40
697
|
{
|
|
@@ -53,6 +710,24 @@ window.__ModuleLoader__.load({
|
|
|
53
710
|
detail: "只接受免密链接,不接受密码登录"
|
|
54
711
|
}
|
|
55
712
|
];
|
|
713
|
+
/** Admin unlock policies. */
|
|
714
|
+
const POLICY_CHOICES = [
|
|
715
|
+
{
|
|
716
|
+
id: "password_unlock",
|
|
717
|
+
title: "密码解锁",
|
|
718
|
+
detail: "任何设备打开设置页都需要管理员密码解锁"
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
id: "local_only",
|
|
722
|
+
title: "仅本机",
|
|
723
|
+
detail: "只有本机回环访问可以管理,其他设备只读"
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
id: "open",
|
|
727
|
+
title: "不锁定",
|
|
728
|
+
detail: "不额外解锁,任何能打开设置页的人都能修改"
|
|
729
|
+
}
|
|
730
|
+
];
|
|
56
731
|
/** The three tabs of the section (user decision 2026-09-24). */
|
|
57
732
|
const TABS = [
|
|
58
733
|
{
|
|
@@ -164,9 +839,69 @@ window.__ModuleLoader__.load({
|
|
|
164
839
|
.lg-bar .lg-btn{flex:0 0 auto;white-space:nowrap;height:32px;padding:0 12px;
|
|
165
840
|
font:var(--dsw-font-xs-13,13px/20px sans-serif);font-weight:400}
|
|
166
841
|
.lg-bar-compact{margin-top:0;padding:6px 10px}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
842
|
+
/*
|
|
843
|
+
* COLOUR RULE FOR EVERY STATUS SURFACE (toast, bar, chip).
|
|
844
|
+
*
|
|
845
|
+
* Measured against DSH 0.1.7's real palette, in BOTH themes (the alias values
|
|
846
|
+
* come from @deepseek-ai/dsh-client-ui-theme):
|
|
847
|
+
*
|
|
848
|
+
* business-primary on business-tertiary light 3.60:1 dark 4.39:1 <- fails AA
|
|
849
|
+
* error-primary on a 5% hover tint light ~3:1 dark 3.68:1 <- fails AA
|
|
850
|
+
* label-primary on the same surfaces light 16:1 dark 9.8:1 <- passes
|
|
851
|
+
*
|
|
852
|
+
* Two consequences, applied everywhere below:
|
|
853
|
+
* 1. TEXT is always --dsw-alias-label-primary. A semantic colour is used for
|
|
854
|
+
* the ICON and the BORDER, where 3:1 is the bar (WCAG 1.4.11), not 4.5:1.
|
|
855
|
+
* 2. A hover TINT is never a surface. --dsw-alias-interactive-bg-hover-danger
|
|
856
|
+
* resolves to an 8-digit colour with alpha 0x0d (5%), so it is a wash over
|
|
857
|
+
* whatever sits behind it, not a background. Danger surfaces mix the
|
|
858
|
+
* semantic colour into bg-layer-1 instead, which stays opaque in both
|
|
859
|
+
* themes; the solid declaration comes first so an engine without color-mix
|
|
860
|
+
* keeps a plain, legible token surface.
|
|
861
|
+
*/
|
|
862
|
+
.lg-bar.info{background:var(--dsw-alias-state-business-tertiary,#e8f0fe);color:var(--dsw-alias-label-primary,#1f2329)}
|
|
863
|
+
.lg-bar.warn{background:var(--dsw-alias-state-warn-tertiary,#fffbeb);color:var(--dsw-alias-label-primary,#1f2329)}
|
|
864
|
+
.lg-bar.danger{background:var(--dsw-alias-bg-layer-2,#fef2f2);color:var(--dsw-alias-label-primary,#1f2329);
|
|
865
|
+
background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#b91c1c) 12%, var(--dsw-alias-bg-layer-1,#fff))}
|
|
866
|
+
/*
|
|
867
|
+
* Transient confirmations live in a FIXED top-right stack, not in the page
|
|
868
|
+
* flow. A bar above the tabs pushed every control down for two seconds, so a
|
|
869
|
+
* save made at the bottom of a long tab looked like the page had jumped and
|
|
870
|
+
* gave no clue whether anything had been saved (user feedback 2026-09-26).
|
|
871
|
+
* A fixed position costs no layout, and pointer-events keeps the empty stack
|
|
872
|
+
* from swallowing clicks on whatever sits underneath it.
|
|
873
|
+
*
|
|
874
|
+
* The toast is a NOTIFICATION, not a pill: a content-sized pill around two
|
|
875
|
+
* characters is easy to miss (same feedback round), so it has a real minimum
|
|
876
|
+
* width, a leading icon, its own close button and a countdown bar. The bar's
|
|
877
|
+
* duration is injected from TOAST_MS, so the animation and the dismissal timer
|
|
878
|
+
* can never disagree.
|
|
879
|
+
*/
|
|
880
|
+
.lg-toasts{position:fixed;top:16px;right:16px;z-index:2147483001;display:flex;flex-direction:column;gap:8px;
|
|
881
|
+
align-items:flex-end;pointer-events:none;max-width:min(360px,calc(100vw - 32px))}
|
|
882
|
+
.lg-toast{pointer-events:auto;box-sizing:border-box;position:relative;overflow:hidden;
|
|
883
|
+
min-width:min(240px,calc(100vw - 32px));padding:12px 14px 14px;border-radius:12px;
|
|
884
|
+
border:1px solid var(--dsw-alias-border-l2,#e5e6eb);box-shadow:0 8px 24px color-mix(in srgb, #000 18%, transparent);
|
|
885
|
+
font:var(--dsw-font-s-14,14px/22px sans-serif);animation:lg-toast-in .16s ease-out}
|
|
886
|
+
@keyframes lg-toast-in{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:none}}
|
|
887
|
+
@media (prefers-reduced-motion:reduce){.lg-toast{animation:none}}
|
|
888
|
+
.lg-toast-row{display:flex;align-items:center;gap:10px}
|
|
889
|
+
.lg-toast-icon{flex:0 0 auto;font-size:15px;line-height:1}
|
|
890
|
+
.lg-toast-text{flex:1 1 auto;min-width:0;overflow-wrap:anywhere}
|
|
891
|
+
.lg-toast.info{background:var(--dsw-alias-state-business-tertiary,#e8f0fe);color:var(--dsw-alias-label-primary,#1f2329)}
|
|
892
|
+
.lg-toast.info .lg-toast-icon{color:var(--dsw-alias-state-business-primary,#1a3f8f)}
|
|
893
|
+
.lg-toast.danger{background:var(--dsw-alias-bg-layer-2,#fef2f2);color:var(--dsw-alias-label-primary,#1f2329);
|
|
894
|
+
background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#b91c1c) 12%, var(--dsw-alias-bg-layer-1,#fff));
|
|
895
|
+
border-color:color-mix(in srgb, var(--dsw-alias-state-error-primary,#b91c1c) 38%, transparent)}
|
|
896
|
+
.lg-toast.danger .lg-toast-icon{color:var(--dsw-alias-state-error-primary,#b91c1c)}
|
|
897
|
+
.lg-toast-x{flex:0 0 auto;border:0;background:transparent;color:inherit;cursor:pointer;opacity:.7;
|
|
898
|
+
font-size:14px;line-height:1;padding:4px 6px;border-radius:6px}
|
|
899
|
+
.lg-toast-x:hover{opacity:1}
|
|
900
|
+
/* Countdown for an auto-dismissing toast; the duration is set on the element. */
|
|
901
|
+
.lg-toast-bar{position:absolute;left:0;bottom:0;height:2px;width:100%;background:currentColor;opacity:.4;
|
|
902
|
+
animation-name:lg-toast-shrink;animation-timing-function:linear;animation-fill-mode:forwards}
|
|
903
|
+
@keyframes lg-toast-shrink{from{width:100%}to{width:0}}
|
|
904
|
+
@media (prefers-reduced-motion:reduce){.lg-toast-bar{display:none}}
|
|
170
905
|
.lg-mono-sm{font:var(--dsw-font-xxs-12,12px/18px sans-serif)}
|
|
171
906
|
.lg-mono{margin-top:14px;padding:10px 12px;border-radius:12px;background:var(--dsw-alias-bg-base,#f1f2f4);
|
|
172
907
|
border:1px solid var(--dsw-alias-border-l2,#e5e6eb);
|
|
@@ -281,7 +1016,7 @@ window.__ModuleLoader__.load({
|
|
|
281
1016
|
.lg-sec-title{margin:18px 0 2px;font:var(--dsw-font-s-strong-14,500 14px/22px sans-serif);
|
|
282
1017
|
color:var(--dsw-alias-label-secondary,#adb2b8)}
|
|
283
1018
|
.lg-chip.ok,.lg-chip.wait,.lg-chip.ban{margin-left:5px;flex-shrink:0}
|
|
284
|
-
.lg-chip.wait{background:var(--dsw-alias-state-warn-tertiary,#3a2f16);color:var(--dsw-alias-
|
|
1019
|
+
.lg-chip.wait{background:var(--dsw-alias-state-warn-tertiary,#3a2f16);color:var(--dsw-alias-label-primary,#1f2329)}
|
|
285
1020
|
.lg-chip.ban{background:var(--dsw-static-red-600-a08,#ec13131f);color:var(--dsw-static-red-400,#f25a5a)}
|
|
286
1021
|
.lg-danger{color:var(--dsw-static-red-400,#f25a5a);border-color:var(--dsw-static-red-400,#f25a5a)}
|
|
287
1022
|
.lg-device{display:block;margin-top:12px;padding:10px 12px;border-radius:var(--dsw-radius-md,12px);
|
|
@@ -330,6 +1065,27 @@ window.__ModuleLoader__.load({
|
|
|
330
1065
|
if (!response.ok) throw new Error(parsed.error ?? `settings write failed: ${String(response.status)}`);
|
|
331
1066
|
return parsed;
|
|
332
1067
|
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Turn a management refusal into something the operator can act on.
|
|
1070
|
+
*
|
|
1071
|
+
* The host answers with stable codes; showing `read_only_remote` to a person
|
|
1072
|
+
* holding a phone is not an explanation. Anything unrecognised is passed through
|
|
1073
|
+
* unchanged, so a new code is still visible instead of being swallowed.
|
|
1074
|
+
*
|
|
1075
|
+
* @param raw - the error text from the management endpoint.
|
|
1076
|
+
* @returns the line the toast shows.
|
|
1077
|
+
*/
|
|
1078
|
+
function settingsErrorText(raw) {
|
|
1079
|
+
switch (raw) {
|
|
1080
|
+
case "read_only_remote": return "当前策略是「仅本机」:远程设备只读,请在电脑上修改";
|
|
1081
|
+
case "admin_required": return "需要先解锁管理控制台(「安全认证」里输入管理密码)";
|
|
1082
|
+
case "admin_password_invalid": return "管理密码不正确";
|
|
1083
|
+
case "csrf": return "请求被跨站校验拒绝,刷新页面后重试";
|
|
1084
|
+
case "current_password_required": return "需要先填写当前密码";
|
|
1085
|
+
case "gate_disabled_requires_loopback": return "关闭门禁时必须把监听范围改回「仅本机」";
|
|
1086
|
+
default: return raw;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
333
1089
|
/** One card. */
|
|
334
1090
|
function Card(props) {
|
|
335
1091
|
return (0, react.createElement)("section", { className: "lg-card" }, [props.title === void 0 ? null : (0, react.createElement)("div", {
|
|
@@ -383,10 +1139,28 @@ window.__ModuleLoader__.load({
|
|
|
383
1139
|
const [portCheck, setPortCheck] = (0, react.useState)(null);
|
|
384
1140
|
const [update, setUpdate] = (0, react.useState)(null);
|
|
385
1141
|
const [updateBusy, setUpdateBusy] = (0, react.useState)(false);
|
|
1142
|
+
const [doctor, setDoctor] = (0, react.useState)(null);
|
|
1143
|
+
const [doctorBusy, setDoctorBusy] = (0, react.useState)(false);
|
|
1144
|
+
const noticeTimer = (0, react.useRef)(null);
|
|
1145
|
+
const clearNoticeTimer = (0, react.useCallback)(() => {
|
|
1146
|
+
if (noticeTimer.current !== null) {
|
|
1147
|
+
clearTimeout(noticeTimer.current);
|
|
1148
|
+
noticeTimer.current = null;
|
|
1149
|
+
}
|
|
1150
|
+
}, []);
|
|
1151
|
+
const dismissNotice = (0, react.useCallback)(() => {
|
|
1152
|
+
clearNoticeTimer();
|
|
1153
|
+
setNotice(null);
|
|
1154
|
+
}, [clearNoticeTimer]);
|
|
386
1155
|
const flash = (0, react.useCallback)((message) => {
|
|
1156
|
+
clearNoticeTimer();
|
|
387
1157
|
setNotice(message);
|
|
388
|
-
setTimeout(() =>
|
|
389
|
-
|
|
1158
|
+
noticeTimer.current = setTimeout(() => {
|
|
1159
|
+
noticeTimer.current = null;
|
|
1160
|
+
setNotice(null);
|
|
1161
|
+
}, TOAST_MS);
|
|
1162
|
+
}, [clearNoticeTimer]);
|
|
1163
|
+
(0, react.useEffect)(() => clearNoticeTimer, [clearNoticeTimer]);
|
|
390
1164
|
const refresh = (0, react.useCallback)(async () => {
|
|
391
1165
|
try {
|
|
392
1166
|
setSnapshot(await loadSnapshot());
|
|
@@ -500,6 +1274,72 @@ window.__ModuleLoader__.load({
|
|
|
500
1274
|
setPortCheck("检查失败");
|
|
501
1275
|
}
|
|
502
1276
|
}, []);
|
|
1277
|
+
/**
|
|
1278
|
+
* Run the on-page half of the connection health check (P5).
|
|
1279
|
+
*
|
|
1280
|
+
* Everything here is measured in the VISITOR's own browser, which is the only
|
|
1281
|
+
* place the interesting facts live: which APIs this engine lacks (that is what
|
|
1282
|
+
* leaves a session stuck on 「载入历史…」 with no error), whether the injected
|
|
1283
|
+
* patches are present, and how long a real WebSocket handshake to this origin
|
|
1284
|
+
* takes. The host's own counters come from the snapshot, not from here.
|
|
1285
|
+
*/
|
|
1286
|
+
const runDoctor = (0, react.useCallback)(async () => {
|
|
1287
|
+
setDoctorBusy(true);
|
|
1288
|
+
const lines = [];
|
|
1289
|
+
try {
|
|
1290
|
+
const patches = globalThis.__DSH_LAN_GUARD__ ?? {};
|
|
1291
|
+
lines.push(`页面补丁:官方设置页解锁 ${patches.settingsUnlock === true ? "✓" : "—"} · 移动端兼容垫片 ${patches.mobileCompat === true ? "✓" : "—"} · 断线看门狗 ${patches.socketWatchdog === true ? "✓" : "—"}`);
|
|
1292
|
+
const missing = [];
|
|
1293
|
+
if (typeof AbortSignal.any !== "function") missing.push("AbortSignal.any");
|
|
1294
|
+
if (typeof AbortSignal.timeout !== "function") missing.push("AbortSignal.timeout");
|
|
1295
|
+
if (typeof Promise.withResolvers !== "function") missing.push("Promise.withResolvers");
|
|
1296
|
+
if (typeof globalThis.Iterator === "undefined") missing.push("Iterator");
|
|
1297
|
+
lines.push(missing.length === 0 ? "浏览器引擎能力:✓ 会话流需要的 API 齐全" : `浏览器引擎能力:缺 ${missing.join("、")}(垫片未生效时,会话记录会停在「载入历史…」且没有报错)`);
|
|
1298
|
+
lines.push(`页面来源:${location.origin}${location.origin.startsWith("https://127.0.0.1") || location.origin.startsWith("http://127.0.0.1") ? "(本机回环)" : "(经局域网入口)"}`);
|
|
1299
|
+
const agent = navigator.userAgent;
|
|
1300
|
+
lines.push(`浏览器:${agent.slice(0, 120)}`);
|
|
1301
|
+
const started = Date.now();
|
|
1302
|
+
const outcome = await new Promise((resolve) => {
|
|
1303
|
+
let socket;
|
|
1304
|
+
try {
|
|
1305
|
+
socket = new WebSocket(`${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}/api/remote.mux`);
|
|
1306
|
+
} catch (failure) {
|
|
1307
|
+
resolve(`✗ 无法创建 WebSocket:${failure.message}`);
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
const timer = setTimeout(() => {
|
|
1311
|
+
try {
|
|
1312
|
+
socket.close();
|
|
1313
|
+
} catch {}
|
|
1314
|
+
resolve("✗ 12 秒内没有完成握手(WebKit 后台恢复后卡在 CONNECTING 的典型形状)");
|
|
1315
|
+
}, 12e3);
|
|
1316
|
+
socket.addEventListener("open", () => {
|
|
1317
|
+
clearTimeout(timer);
|
|
1318
|
+
resolve(`✓ 握手成功,用时 ${String(Date.now() - started)} ms`);
|
|
1319
|
+
try {
|
|
1320
|
+
socket.close();
|
|
1321
|
+
} catch {}
|
|
1322
|
+
});
|
|
1323
|
+
socket.addEventListener("error", () => {
|
|
1324
|
+
clearTimeout(timer);
|
|
1325
|
+
resolve("✗ WebSocket 握手失败(门禁拒绝或证书不受信任)");
|
|
1326
|
+
});
|
|
1327
|
+
socket.addEventListener("close", (event) => {
|
|
1328
|
+
if (event.code === 1006) return;
|
|
1329
|
+
});
|
|
1330
|
+
});
|
|
1331
|
+
lines.push(`会话 WebSocket(${location.host}):${outcome}`);
|
|
1332
|
+
const relay = snapshot?.connection;
|
|
1333
|
+
if (relay !== void 0) {
|
|
1334
|
+
lines.push(`代理侧:在活连接 ${String(relay.wsActive)} · 累计升级 ${String(relay.wsUpgrades)} · 被拒 ${String(relay.wsRefused)} · 代答心跳 ${String(relay.heartbeatAnswered)} 次`);
|
|
1335
|
+
const last = relay.recent[0];
|
|
1336
|
+
if (last !== void 0) lines.push(`最近一条:${last.upgraded ? "已升级" : `被拒 ${String(last.status ?? "?")}`} · 存活 ${String(Math.round(last.durationMs / 1e3))}s · 上行 ${String(Math.round(last.bytesToUpstream / 1024))}KB / 下行 ${String(Math.round(last.bytesToVisitor / 1024))}KB${last.upgraded && !last.sawCloseFrame ? " · 异常断开(无 Close 帧)" : ""}`);
|
|
1337
|
+
}
|
|
1338
|
+
setDoctor(lines);
|
|
1339
|
+
} finally {
|
|
1340
|
+
setDoctorBusy(false);
|
|
1341
|
+
}
|
|
1342
|
+
}, [snapshot]);
|
|
503
1343
|
/** Submit the admin unlock, keeping the button an ENABLED primary action. */
|
|
504
1344
|
const submitUnlock = async () => {
|
|
505
1345
|
if (unlockPassword === "") {
|
|
@@ -738,6 +1578,37 @@ window.__ModuleLoader__.load({
|
|
|
738
1578
|
disabled: busy,
|
|
739
1579
|
onClick: () => void write({ preferences: { allowLoopback: !preferences.allowLoopback } })
|
|
740
1580
|
}, (0, react.createElement)("span", null))]),
|
|
1581
|
+
(0, react.createElement)("div", {
|
|
1582
|
+
className: "lg-field",
|
|
1583
|
+
key: "policy"
|
|
1584
|
+
}, [
|
|
1585
|
+
(0, react.createElement)("span", {
|
|
1586
|
+
className: "lg-label",
|
|
1587
|
+
key: "l"
|
|
1588
|
+
}, "远程设备管理权限"),
|
|
1589
|
+
(0, react.createElement)("p", {
|
|
1590
|
+
className: "lg-hint",
|
|
1591
|
+
key: "d"
|
|
1592
|
+
}, "「仅本机」下局域网设备只读;想让它们在手机上浏览目录并添加工作区,选「密码解锁」(需先解锁)或「不锁定」。"),
|
|
1593
|
+
(0, react.createElement)(ChoiceGrid, {
|
|
1594
|
+
key: "g",
|
|
1595
|
+
choices: POLICY_CHOICES,
|
|
1596
|
+
value: preferences.adminPolicy,
|
|
1597
|
+
disabled: busy,
|
|
1598
|
+
onPick: (id) => void write({ preferences: { adminPolicy: id } })
|
|
1599
|
+
})
|
|
1600
|
+
]),
|
|
1601
|
+
(0, react.createElement)("div", {
|
|
1602
|
+
className: "lg-toggle",
|
|
1603
|
+
key: "admin-protection"
|
|
1604
|
+
}, [(0, react.createElement)("span", { key: "l" }, "管理操作需要先解锁"), (0, react.createElement)("button", {
|
|
1605
|
+
key: "s",
|
|
1606
|
+
type: "button",
|
|
1607
|
+
className: "lg-switch",
|
|
1608
|
+
"aria-checked": preferences.adminProtection,
|
|
1609
|
+
disabled: busy,
|
|
1610
|
+
onClick: () => void write({ preferences: { adminProtection: !preferences.adminProtection } })
|
|
1611
|
+
}, (0, react.createElement)("span", null))]),
|
|
741
1612
|
(0, react.createElement)("p", {
|
|
742
1613
|
className: "lg-hint",
|
|
743
1614
|
key: "h"
|
|
@@ -836,6 +1707,102 @@ window.__ModuleLoader__.load({
|
|
|
836
1707
|
]
|
|
837
1708
|
})]);
|
|
838
1709
|
const connectionTab = (0, react.createElement)("div", { className: "lg-tabbody" }, locked ? [lockCard] : [(0, react.createElement)(Card, {
|
|
1710
|
+
key: "mobile",
|
|
1711
|
+
title: "手机连接与自愈",
|
|
1712
|
+
subtitle: "长连接为什么会断,以及断了以后怎么恢复",
|
|
1713
|
+
children: [
|
|
1714
|
+
(0, react.createElement)("p", {
|
|
1715
|
+
className: "lg-hint",
|
|
1716
|
+
key: "why"
|
|
1717
|
+
}, "会话记录(「载入历史…」那一段)只走 WebSocket:DSH 每 2 秒发一次心跳,连续两次没被回应就断开——实测 6 秒。手机锁屏或切走时页面被系统挂起,回不了心跳,于是会话就会「载入不全、甚至断开」。下面三项默认开启,逐项都可以关。"),
|
|
1718
|
+
(0, react.createElement)("div", {
|
|
1719
|
+
className: "lg-field",
|
|
1720
|
+
key: "heartbeat"
|
|
1721
|
+
}, [(0, react.createElement)("div", {
|
|
1722
|
+
className: "lg-toggle",
|
|
1723
|
+
key: "t"
|
|
1724
|
+
}, [(0, react.createElement)("span", { key: "l" }, "代理代答心跳"), (0, react.createElement)("button", {
|
|
1725
|
+
key: "s",
|
|
1726
|
+
type: "button",
|
|
1727
|
+
className: "lg-switch",
|
|
1728
|
+
"aria-checked": preferences.answerHeartbeat,
|
|
1729
|
+
disabled: busy,
|
|
1730
|
+
onClick: () => void write({ preferences: { answerHeartbeat: !preferences.answerHeartbeat } })
|
|
1731
|
+
}, (0, react.createElement)("span", null))]), (0, react.createElement)("p", {
|
|
1732
|
+
className: "lg-hint",
|
|
1733
|
+
key: "h"
|
|
1734
|
+
}, "手机挂起期间由代理替它回心跳,宿主就不再回收这条连接(已实测:停回心跳 6 秒被切断 vs 代答后 20 秒以上存活)。手机自己回的心跳到达时是重复包,没有副作用。")]),
|
|
1735
|
+
(0, react.createElement)("div", {
|
|
1736
|
+
className: "lg-field",
|
|
1737
|
+
key: "watchdog"
|
|
1738
|
+
}, [(0, react.createElement)("div", {
|
|
1739
|
+
className: "lg-toggle",
|
|
1740
|
+
key: "t"
|
|
1741
|
+
}, [(0, react.createElement)("span", { key: "l" }, "断线看门狗(页面补丁)"), (0, react.createElement)("button", {
|
|
1742
|
+
key: "s",
|
|
1743
|
+
type: "button",
|
|
1744
|
+
className: "lg-switch",
|
|
1745
|
+
"aria-checked": preferences.socketWatchdog,
|
|
1746
|
+
disabled: busy,
|
|
1747
|
+
onClick: () => void write({ preferences: { socketWatchdog: !preferences.socketWatchdog } })
|
|
1748
|
+
}, (0, react.createElement)("span", null))]), (0, react.createElement)("p", {
|
|
1749
|
+
className: "lg-hint",
|
|
1750
|
+
key: "h"
|
|
1751
|
+
}, "卡在「连接中」超过 8 秒的 WebSocket 会被关掉;从后台回来 10 秒后仍然一条都没连上时,页面自动重载一次(每标签最多连续 3 次,冷却 20 秒起)。只影响真的连不上的页面。")]),
|
|
1752
|
+
(0, react.createElement)("div", {
|
|
1753
|
+
className: "lg-field",
|
|
1754
|
+
key: "compat"
|
|
1755
|
+
}, [(0, react.createElement)("div", {
|
|
1756
|
+
className: "lg-toggle",
|
|
1757
|
+
key: "t"
|
|
1758
|
+
}, [(0, react.createElement)("span", { key: "l" }, "移动端兼容垫片"), (0, react.createElement)("button", {
|
|
1759
|
+
key: "s",
|
|
1760
|
+
type: "button",
|
|
1761
|
+
className: "lg-switch",
|
|
1762
|
+
"aria-checked": preferences.mobileCompat,
|
|
1763
|
+
disabled: busy,
|
|
1764
|
+
onClick: () => void write({ preferences: { mobileCompat: !preferences.mobileCompat } })
|
|
1765
|
+
}, (0, react.createElement)("span", null))]), (0, react.createElement)("p", {
|
|
1766
|
+
className: "lg-hint",
|
|
1767
|
+
key: "h"
|
|
1768
|
+
}, "为老引擎补 AbortSignal.any / AbortSignal.timeout / Promise.withResolvers / Iterator,并补上移动端 meta。缺这些 API 时 DSH 客户端会在会话流里抛错,而界面上只会一直显示「载入历史…」、连报错都没有。现代浏览器上这些分支不生效。")]),
|
|
1769
|
+
(0, react.createElement)("div", {
|
|
1770
|
+
className: "lg-field",
|
|
1771
|
+
key: "scrollfix"
|
|
1772
|
+
}, [(0, react.createElement)("div", {
|
|
1773
|
+
className: "lg-toggle",
|
|
1774
|
+
key: "t"
|
|
1775
|
+
}, [(0, react.createElement)("span", { key: "l" }, "手机滚动矫正(窄屏)"), (0, react.createElement)("button", {
|
|
1776
|
+
key: "s",
|
|
1777
|
+
type: "button",
|
|
1778
|
+
className: "lg-switch",
|
|
1779
|
+
"aria-checked": preferences.mobileScrollFix,
|
|
1780
|
+
disabled: busy,
|
|
1781
|
+
onClick: () => void write({ preferences: { mobileScrollFix: !preferences.mobileScrollFix } })
|
|
1782
|
+
}, (0, react.createElement)("span", null))]), (0, react.createElement)("p", {
|
|
1783
|
+
className: "lg-hint",
|
|
1784
|
+
key: "h"
|
|
1785
|
+
}, "手机上 DSH 自己的外壳会把对话列压在固定的输入框/目标条/快捷回复浮层后面,导致内容可见但**滑不动**(同一视口在桌面 Chrome 里能滚,属 iOS 布局/触摸差异)。开启后,页面会在「整页不可滚 + 发现被裁剪的层」时把那几层改成可触摸滚动;能正常滚动的页面一律不碰。打开页面时加 ?lgdiag=1 会显示一屏布局诊断。")]),
|
|
1786
|
+
(0, react.createElement)("div", {
|
|
1787
|
+
className: "lg-row",
|
|
1788
|
+
key: "doctor"
|
|
1789
|
+
}, [(0, react.createElement)("button", {
|
|
1790
|
+
key: "b",
|
|
1791
|
+
type: "button",
|
|
1792
|
+
className: "lg-btn",
|
|
1793
|
+
disabled: doctorBusy,
|
|
1794
|
+
onClick: () => void runDoctor()
|
|
1795
|
+
}, doctorBusy ? "体检中…" : "运行连接体检")]),
|
|
1796
|
+
(0, react.createElement)("p", {
|
|
1797
|
+
className: "lg-hint",
|
|
1798
|
+
key: "doctor-hint"
|
|
1799
|
+
}, "体检在这个浏览器里跑:检查引擎缺哪些 API、页面拿到了哪些补丁,并对本页地址做一次真实的 WebSocket 握手。"),
|
|
1800
|
+
doctor === null ? null : (0, react.createElement)("div", {
|
|
1801
|
+
className: "lg-mono lg-mono-sm",
|
|
1802
|
+
key: "doctor-out"
|
|
1803
|
+
}, doctor.map((line, index) => (0, react.createElement)("div", { key: `l${String(index)}` }, line)))
|
|
1804
|
+
]
|
|
1805
|
+
}), (0, react.createElement)(Card, {
|
|
839
1806
|
key: "connection",
|
|
840
1807
|
title: "连接与证书",
|
|
841
1808
|
subtitle: "监听范围、端口与传输安全",
|
|
@@ -1097,14 +2064,63 @@ window.__ModuleLoader__.load({
|
|
|
1097
2064
|
}, entry.label)));
|
|
1098
2065
|
return (0, react.createElement)("div", { className: "lg-root" }, [
|
|
1099
2066
|
(0, react.createElement)("style", { key: "css" }, CSS),
|
|
1100
|
-
error === null ? null : (0, react.createElement)("div", {
|
|
1101
|
-
className: "lg-
|
|
2067
|
+
error === null && notice === null ? null : (0, react.createElement)("div", {
|
|
2068
|
+
className: "lg-toasts",
|
|
2069
|
+
key: "toasts"
|
|
2070
|
+
}, [error === null ? null : (0, react.createElement)("div", {
|
|
2071
|
+
className: "lg-toast danger",
|
|
2072
|
+
role: "alert",
|
|
1102
2073
|
key: "err"
|
|
1103
|
-
},
|
|
1104
|
-
|
|
1105
|
-
|
|
2074
|
+
}, [(0, react.createElement)("div", {
|
|
2075
|
+
className: "lg-toast-row",
|
|
2076
|
+
key: "row"
|
|
2077
|
+
}, [
|
|
2078
|
+
(0, react.createElement)("span", {
|
|
2079
|
+
className: "lg-toast-icon",
|
|
2080
|
+
key: "i"
|
|
2081
|
+
}, "⚠"),
|
|
2082
|
+
(0, react.createElement)("span", {
|
|
2083
|
+
className: "lg-toast-text",
|
|
2084
|
+
key: "t"
|
|
2085
|
+
}, settingsErrorText(error)),
|
|
2086
|
+
(0, react.createElement)("button", {
|
|
2087
|
+
key: "x",
|
|
2088
|
+
type: "button",
|
|
2089
|
+
className: "lg-toast-x",
|
|
2090
|
+
"aria-label": "关闭",
|
|
2091
|
+
onClick: () => {
|
|
2092
|
+
setError(null);
|
|
2093
|
+
}
|
|
2094
|
+
}, "✕")
|
|
2095
|
+
])]), notice === null ? null : (0, react.createElement)("div", {
|
|
2096
|
+
className: "lg-toast info",
|
|
2097
|
+
role: "status",
|
|
1106
2098
|
key: "ok"
|
|
1107
|
-
},
|
|
2099
|
+
}, [(0, react.createElement)("div", {
|
|
2100
|
+
className: "lg-toast-row",
|
|
2101
|
+
key: "row"
|
|
2102
|
+
}, [
|
|
2103
|
+
(0, react.createElement)("span", {
|
|
2104
|
+
className: "lg-toast-icon",
|
|
2105
|
+
key: "i"
|
|
2106
|
+
}, "✓"),
|
|
2107
|
+
(0, react.createElement)("span", {
|
|
2108
|
+
className: "lg-toast-text",
|
|
2109
|
+
key: "t"
|
|
2110
|
+
}, notice),
|
|
2111
|
+
(0, react.createElement)("button", {
|
|
2112
|
+
key: "x",
|
|
2113
|
+
type: "button",
|
|
2114
|
+
className: "lg-toast-x",
|
|
2115
|
+
"aria-label": "关闭",
|
|
2116
|
+
onClick: dismissNotice
|
|
2117
|
+
}, "✕")
|
|
2118
|
+
]), (0, react.createElement)("span", {
|
|
2119
|
+
className: "lg-toast-bar",
|
|
2120
|
+
key: "bar",
|
|
2121
|
+
"aria-hidden": true,
|
|
2122
|
+
style: { animationDuration: `${String(TOAST_MS)}ms` }
|
|
2123
|
+
})])].filter(Boolean)),
|
|
1108
2124
|
unlockBanner,
|
|
1109
2125
|
readOnlyBanner,
|
|
1110
2126
|
updateChip,
|
|
@@ -1116,6 +2132,14 @@ window.__ModuleLoader__.load({
|
|
|
1116
2132
|
/** Default port shown as a hint in the port field. */
|
|
1117
2133
|
const DEFAULT_PORT_HINT = 3081;
|
|
1118
2134
|
/**
|
|
2135
|
+
* How long a transient confirmation stays on screen.
|
|
2136
|
+
*
|
|
2137
|
+
* The single source of truth: the countdown bar's `animation-duration` is
|
|
2138
|
+
* injected from this value, so the bar can never outlive (or predecease) the
|
|
2139
|
+
* dismissal timer.
|
|
2140
|
+
*/
|
|
2141
|
+
const TOAST_MS = 2600;
|
|
2142
|
+
/**
|
|
1119
2143
|
* Register the settings section.
|
|
1120
2144
|
*
|
|
1121
2145
|
* @param ctx - the client plugin context (injects `slots`).
|
|
@@ -1127,6 +2151,7 @@ window.__ModuleLoader__.load({
|
|
|
1127
2151
|
order: 100,
|
|
1128
2152
|
label: "局域网访问"
|
|
1129
2153
|
}, SettingsSection));
|
|
2154
|
+
applyDirectoryFlow(ctx);
|
|
1130
2155
|
}
|
|
1131
2156
|
module.exports = {
|
|
1132
2157
|
name: PLUGIN_ID,
|