dsh-lan-guard 0.3.5 → 0.3.6
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 +66 -0
- package/README.md +14 -1
- package/README.zh.md +14 -1
- package/lib/client.js +874 -13
- package/lib/client.js.map +1 -1
- package/lib/index.js +497 -11
- 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,26 @@ 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 noticeTimer = (0, react.useRef)(null);
|
|
1143
|
+
const clearNoticeTimer = (0, react.useCallback)(() => {
|
|
1144
|
+
if (noticeTimer.current !== null) {
|
|
1145
|
+
clearTimeout(noticeTimer.current);
|
|
1146
|
+
noticeTimer.current = null;
|
|
1147
|
+
}
|
|
1148
|
+
}, []);
|
|
1149
|
+
const dismissNotice = (0, react.useCallback)(() => {
|
|
1150
|
+
clearNoticeTimer();
|
|
1151
|
+
setNotice(null);
|
|
1152
|
+
}, [clearNoticeTimer]);
|
|
386
1153
|
const flash = (0, react.useCallback)((message) => {
|
|
1154
|
+
clearNoticeTimer();
|
|
387
1155
|
setNotice(message);
|
|
388
|
-
setTimeout(() =>
|
|
389
|
-
|
|
1156
|
+
noticeTimer.current = setTimeout(() => {
|
|
1157
|
+
noticeTimer.current = null;
|
|
1158
|
+
setNotice(null);
|
|
1159
|
+
}, TOAST_MS);
|
|
1160
|
+
}, [clearNoticeTimer]);
|
|
1161
|
+
(0, react.useEffect)(() => clearNoticeTimer, [clearNoticeTimer]);
|
|
390
1162
|
const refresh = (0, react.useCallback)(async () => {
|
|
391
1163
|
try {
|
|
392
1164
|
setSnapshot(await loadSnapshot());
|
|
@@ -738,6 +1510,37 @@ window.__ModuleLoader__.load({
|
|
|
738
1510
|
disabled: busy,
|
|
739
1511
|
onClick: () => void write({ preferences: { allowLoopback: !preferences.allowLoopback } })
|
|
740
1512
|
}, (0, react.createElement)("span", null))]),
|
|
1513
|
+
(0, react.createElement)("div", {
|
|
1514
|
+
className: "lg-field",
|
|
1515
|
+
key: "policy"
|
|
1516
|
+
}, [
|
|
1517
|
+
(0, react.createElement)("span", {
|
|
1518
|
+
className: "lg-label",
|
|
1519
|
+
key: "l"
|
|
1520
|
+
}, "远程设备管理权限"),
|
|
1521
|
+
(0, react.createElement)("p", {
|
|
1522
|
+
className: "lg-hint",
|
|
1523
|
+
key: "d"
|
|
1524
|
+
}, "「仅本机」下局域网设备只读;想让它们在手机上浏览目录并添加工作区,选「密码解锁」(需先解锁)或「不锁定」。"),
|
|
1525
|
+
(0, react.createElement)(ChoiceGrid, {
|
|
1526
|
+
key: "g",
|
|
1527
|
+
choices: POLICY_CHOICES,
|
|
1528
|
+
value: preferences.adminPolicy,
|
|
1529
|
+
disabled: busy,
|
|
1530
|
+
onPick: (id) => void write({ preferences: { adminPolicy: id } })
|
|
1531
|
+
})
|
|
1532
|
+
]),
|
|
1533
|
+
(0, react.createElement)("div", {
|
|
1534
|
+
className: "lg-toggle",
|
|
1535
|
+
key: "admin-protection"
|
|
1536
|
+
}, [(0, react.createElement)("span", { key: "l" }, "管理操作需要先解锁"), (0, react.createElement)("button", {
|
|
1537
|
+
key: "s",
|
|
1538
|
+
type: "button",
|
|
1539
|
+
className: "lg-switch",
|
|
1540
|
+
"aria-checked": preferences.adminProtection,
|
|
1541
|
+
disabled: busy,
|
|
1542
|
+
onClick: () => void write({ preferences: { adminProtection: !preferences.adminProtection } })
|
|
1543
|
+
}, (0, react.createElement)("span", null))]),
|
|
741
1544
|
(0, react.createElement)("p", {
|
|
742
1545
|
className: "lg-hint",
|
|
743
1546
|
key: "h"
|
|
@@ -1097,14 +1900,63 @@ window.__ModuleLoader__.load({
|
|
|
1097
1900
|
}, entry.label)));
|
|
1098
1901
|
return (0, react.createElement)("div", { className: "lg-root" }, [
|
|
1099
1902
|
(0, react.createElement)("style", { key: "css" }, CSS),
|
|
1100
|
-
error === null ? null : (0, react.createElement)("div", {
|
|
1101
|
-
className: "lg-
|
|
1903
|
+
error === null && notice === null ? null : (0, react.createElement)("div", {
|
|
1904
|
+
className: "lg-toasts",
|
|
1905
|
+
key: "toasts"
|
|
1906
|
+
}, [error === null ? null : (0, react.createElement)("div", {
|
|
1907
|
+
className: "lg-toast danger",
|
|
1908
|
+
role: "alert",
|
|
1102
1909
|
key: "err"
|
|
1103
|
-
},
|
|
1104
|
-
|
|
1105
|
-
|
|
1910
|
+
}, [(0, react.createElement)("div", {
|
|
1911
|
+
className: "lg-toast-row",
|
|
1912
|
+
key: "row"
|
|
1913
|
+
}, [
|
|
1914
|
+
(0, react.createElement)("span", {
|
|
1915
|
+
className: "lg-toast-icon",
|
|
1916
|
+
key: "i"
|
|
1917
|
+
}, "⚠"),
|
|
1918
|
+
(0, react.createElement)("span", {
|
|
1919
|
+
className: "lg-toast-text",
|
|
1920
|
+
key: "t"
|
|
1921
|
+
}, settingsErrorText(error)),
|
|
1922
|
+
(0, react.createElement)("button", {
|
|
1923
|
+
key: "x",
|
|
1924
|
+
type: "button",
|
|
1925
|
+
className: "lg-toast-x",
|
|
1926
|
+
"aria-label": "关闭",
|
|
1927
|
+
onClick: () => {
|
|
1928
|
+
setError(null);
|
|
1929
|
+
}
|
|
1930
|
+
}, "✕")
|
|
1931
|
+
])]), notice === null ? null : (0, react.createElement)("div", {
|
|
1932
|
+
className: "lg-toast info",
|
|
1933
|
+
role: "status",
|
|
1106
1934
|
key: "ok"
|
|
1107
|
-
},
|
|
1935
|
+
}, [(0, react.createElement)("div", {
|
|
1936
|
+
className: "lg-toast-row",
|
|
1937
|
+
key: "row"
|
|
1938
|
+
}, [
|
|
1939
|
+
(0, react.createElement)("span", {
|
|
1940
|
+
className: "lg-toast-icon",
|
|
1941
|
+
key: "i"
|
|
1942
|
+
}, "✓"),
|
|
1943
|
+
(0, react.createElement)("span", {
|
|
1944
|
+
className: "lg-toast-text",
|
|
1945
|
+
key: "t"
|
|
1946
|
+
}, notice),
|
|
1947
|
+
(0, react.createElement)("button", {
|
|
1948
|
+
key: "x",
|
|
1949
|
+
type: "button",
|
|
1950
|
+
className: "lg-toast-x",
|
|
1951
|
+
"aria-label": "关闭",
|
|
1952
|
+
onClick: dismissNotice
|
|
1953
|
+
}, "✕")
|
|
1954
|
+
]), (0, react.createElement)("span", {
|
|
1955
|
+
className: "lg-toast-bar",
|
|
1956
|
+
key: "bar",
|
|
1957
|
+
"aria-hidden": true,
|
|
1958
|
+
style: { animationDuration: `${String(TOAST_MS)}ms` }
|
|
1959
|
+
})])].filter(Boolean)),
|
|
1108
1960
|
unlockBanner,
|
|
1109
1961
|
readOnlyBanner,
|
|
1110
1962
|
updateChip,
|
|
@@ -1116,6 +1968,14 @@ window.__ModuleLoader__.load({
|
|
|
1116
1968
|
/** Default port shown as a hint in the port field. */
|
|
1117
1969
|
const DEFAULT_PORT_HINT = 3081;
|
|
1118
1970
|
/**
|
|
1971
|
+
* How long a transient confirmation stays on screen.
|
|
1972
|
+
*
|
|
1973
|
+
* The single source of truth: the countdown bar's `animation-duration` is
|
|
1974
|
+
* injected from this value, so the bar can never outlive (or predecease) the
|
|
1975
|
+
* dismissal timer.
|
|
1976
|
+
*/
|
|
1977
|
+
const TOAST_MS = 2600;
|
|
1978
|
+
/**
|
|
1119
1979
|
* Register the settings section.
|
|
1120
1980
|
*
|
|
1121
1981
|
* @param ctx - the client plugin context (injects `slots`).
|
|
@@ -1127,6 +1987,7 @@ window.__ModuleLoader__.load({
|
|
|
1127
1987
|
order: 100,
|
|
1128
1988
|
label: "局域网访问"
|
|
1129
1989
|
}, SettingsSection));
|
|
1990
|
+
applyDirectoryFlow(ctx);
|
|
1130
1991
|
}
|
|
1131
1992
|
module.exports = {
|
|
1132
1993
|
name: PLUGIN_ID,
|