agent-loft 0.2.41 → 0.2.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/package.json +2 -1
- package/src/channels/web/api.ts +1 -0
- package/src/channels/web/desktop.ts +115 -6
- package/src/channels/web/server.ts +1 -1
- package/src/core/config.ts +3 -0
- package/src/core/desktop.ts +3 -2
- package/src/core/vnc-auth.ts +193 -0
- package/src/core/vnc-transcode.ts +765 -0
- package/web/lib/dom.js +1 -0
- package/web/settings/general.js +11 -1
- package/web/views/desktop.js +65 -4
package/web/lib/dom.js
CHANGED
|
@@ -59,6 +59,7 @@ export const ICON = {
|
|
|
59
59
|
pointer: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 3l14 7-6 2-2 6Z"/></svg>',
|
|
60
60
|
hand: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 11V5a1.5 1.5 0 0 1 3 0v5"/><path d="M12 10V4a1.5 1.5 0 0 1 3 0v6"/><path d="M15 10V6a1.5 1.5 0 0 1 3 0v8a7 7 0 0 1-7 7h-.5a6 6 0 0 1-4.6-2.2L3.4 15a1.6 1.6 0 0 1 2.4-2.1L9 15.5V11"/></svg>',
|
|
61
61
|
help: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M9.5 9.2a2.6 2.6 0 0 1 5 .9c0 1.7-2.5 2.3-2.5 3.9M12 17h.01"/></svg>',
|
|
62
|
+
gauge: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m12 14 4-4"/><path d="M3.34 19a10 10 0 1 1 17.32 0"/></svg>',
|
|
62
63
|
maximize: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/></svg>',
|
|
63
64
|
restore: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 14h6v6M20 10h-6V4M14 10l7-7M3 21l7-7"/></svg>',
|
|
64
65
|
laptop: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="5" width="16" height="11" rx="1.5"/><path d="M2 19h20"/></svg>',
|
package/web/settings/general.js
CHANGED
|
@@ -66,17 +66,26 @@ export function remoteTab(cfg, page) {
|
|
|
66
66
|
const display = h("input", { value: r.display ?? "", placeholder: "留空自动找,如 :0", autocapitalize: "off", spellcheck: "false" });
|
|
67
67
|
const host = h("input", { value: r.vncHost ?? "127.0.0.1", autocapitalize: "off", spellcheck: "false" });
|
|
68
68
|
const port = h("input", { type: "number", min: 1, max: 65535, value: r.vncPort ?? 5900 });
|
|
69
|
+
const username = h("input", { value: r.vncUsername ?? "", placeholder: "留空用 VNC 密码", autocomplete: "off", autocapitalize: "off", spellcheck: "false" });
|
|
69
70
|
const password = h("input", { type: "password", value: r.vncPassword ?? "", autocomplete: "new-password", placeholder: "VNC 密码" });
|
|
71
|
+
const syncPassword = () => (password.placeholder = username.value.trim() ? "Mac 的登录密码" : "VNC 密码");
|
|
72
|
+
username.addEventListener("input", syncPassword);
|
|
73
|
+
syncPassword();
|
|
70
74
|
const autoBox = h("div", { class: "field-group" }, field("X 显示", display, "一台机器上有好几个桌面(比如登录界面 :0、登录后的桌面 :1)时可以指定"));
|
|
71
75
|
const vncBox = h(
|
|
72
76
|
"div",
|
|
73
77
|
{ class: "field-group" },
|
|
74
78
|
field("地址", host),
|
|
75
79
|
field("端口", port),
|
|
80
|
+
field(
|
|
81
|
+
"Mac 用户名",
|
|
82
|
+
username,
|
|
83
|
+
"macOS 屏幕共享没开 VNC 密码时填这里:用 Mac 的用户名和登录密码登录(苹果认证)。由服务端登录,密码不会发到页面",
|
|
84
|
+
),
|
|
76
85
|
field(
|
|
77
86
|
"密码",
|
|
78
87
|
password,
|
|
79
|
-
"
|
|
88
|
+
"没填用户名时是 VNC 密码:屏幕共享 →「电脑设置…」里勾选「VNC 显示程序可以使用密码控制屏幕」并设这个密码,开通了远程控制的成员连桌面时页面会拿到它。填了用户名时是这个 Mac 用户的登录密码",
|
|
80
89
|
),
|
|
81
90
|
);
|
|
82
91
|
// 桌面关着时,桌面来源那几项用不上,收起来
|
|
@@ -132,6 +141,7 @@ export function remoteTab(cfg, page) {
|
|
|
132
141
|
display: display.value.trim(),
|
|
133
142
|
vncHost: host.value.trim(),
|
|
134
143
|
vncPort: Number(port.value),
|
|
144
|
+
vncUsername: username.value.trim(),
|
|
135
145
|
vncPassword: password.value,
|
|
136
146
|
},
|
|
137
147
|
});
|
package/web/views/desktop.js
CHANGED
|
@@ -12,9 +12,20 @@ import { createTouch } from "./desktop-touch.js";
|
|
|
12
12
|
// 进来时不自动连,点了「连接」才连(Linux 上会起 x11vnc)。
|
|
13
13
|
// 离开远程控制页时连接不断,画面在后台照常更新;断线了自己重连,点了「断开」才不连。
|
|
14
14
|
// 手机上:触摸事件由 desktop-touch.js 接管(触控板 / 触摸两种模式、双指本地放大),下面多一排按键。
|
|
15
|
+
// 画质:除了「原画」,服务端都会把画面缩小、压成 JPEG 再发过来(vnc-transcode.ts),换画质要重连。
|
|
16
|
+
|
|
17
|
+
/** 画质档位:和服务端 DESKTOP_QUALITIES 对应,original 是原样转发 */
|
|
18
|
+
const QUALITIES = [
|
|
19
|
+
["smooth", "流畅", "长边 1280,最省流量"],
|
|
20
|
+
["standard", "标准", "长边 1920"],
|
|
21
|
+
["high", "高清", "长边 2560"],
|
|
22
|
+
["original", "原画", "不缩放、无损,很费流量,只适合局域网"],
|
|
23
|
+
];
|
|
24
|
+
const savedQuality = localStorage.getItem("aim.deskQuality");
|
|
15
25
|
|
|
16
26
|
const D = {
|
|
17
27
|
rfb: null,
|
|
28
|
+
quality: QUALITIES.some(([id]) => id === savedQuality) ? savedQuality : "standard",
|
|
18
29
|
/** idle / connecting / connected / error */
|
|
19
30
|
state: "idle",
|
|
20
31
|
message: "",
|
|
@@ -100,7 +111,7 @@ async function connect() {
|
|
|
100
111
|
// 等密码的这会儿里点了断开,或者又发起了一次连接(切回前台、点了重连):这次作罢
|
|
101
112
|
if (!D.want || D.rfb) return;
|
|
102
113
|
const proto = location.protocol === "https:" ? "wss" : "ws";
|
|
103
|
-
const rfb = new RFB(D.screen, `${proto}://${location.host}/ws/desktop`, { credentials: { password }, shared: true, wsProtocols: [] });
|
|
114
|
+
const rfb = new RFB(D.screen, `${proto}://${location.host}/ws/desktop?q=${D.quality}`, { credentials: { password }, shared: true, wsProtocols: [] });
|
|
104
115
|
D.rfb = rfb;
|
|
105
116
|
rfb.scaleViewport = D.fit;
|
|
106
117
|
// 不裁剪:原始大小时 noVNC 的画面容器自己出滚动条
|
|
@@ -112,7 +123,16 @@ async function connect() {
|
|
|
112
123
|
rfb.background = "#111";
|
|
113
124
|
rfb.qualityLevel = 6;
|
|
114
125
|
rfb.compressionLevel = 2;
|
|
126
|
+
// 握手卡住了(VNC 服务不回话之类):别一直「正在连接」,断开后按退避重连
|
|
127
|
+
const stuck = setTimeout(() => {
|
|
128
|
+
if (D.rfb !== rfb || D.state !== "connecting") return;
|
|
129
|
+
D.rfb = null;
|
|
130
|
+
rfb.disconnect();
|
|
131
|
+
fail("连了 20 秒还没连上桌面,正在重试…", true);
|
|
132
|
+
}, 20_000);
|
|
133
|
+
rfb.addEventListener("disconnect", () => clearTimeout(stuck));
|
|
115
134
|
rfb.addEventListener("connect", () => {
|
|
135
|
+
clearTimeout(stuck);
|
|
116
136
|
D.state = "connected";
|
|
117
137
|
D.backoff = 1000;
|
|
118
138
|
setLive(true);
|
|
@@ -145,11 +165,32 @@ async function connect() {
|
|
|
145
165
|
() => fail("连不上服务器,正在重连…", true),
|
|
146
166
|
);
|
|
147
167
|
});
|
|
148
|
-
|
|
168
|
+
// 只给得出密码:要用户名的认证(macOS 屏幕共享没开 VNC 密码时只剩苹果自己的认证)、没填密码却要密码的,
|
|
169
|
+
// 再交一次也还是缺,noVNC 会一直要下去,页面停在「正在连接桌面…」:直接说清楚
|
|
170
|
+
rfb.addEventListener("credentialsrequired", (e) => {
|
|
171
|
+
const types = e.detail?.types ?? ["password"];
|
|
172
|
+
if (!types.includes("username") && (password || !types.includes("password"))) return rfb.sendCredentials({ password });
|
|
173
|
+
D.want = false;
|
|
174
|
+
D.rfb = null;
|
|
175
|
+
rfb.disconnect();
|
|
176
|
+
fail(
|
|
177
|
+
types.includes("username")
|
|
178
|
+
? "这个 VNC 服务要用户名登录(macOS 屏幕共享没开 VNC 密码):在 设置 → 远程控制 里填上 Mac 的用户名和登录密码"
|
|
179
|
+
: "VNC 服务要密码,但设置里还没填:在 设置 → 远程控制 里填上 VNC 密码",
|
|
180
|
+
false,
|
|
181
|
+
);
|
|
182
|
+
});
|
|
149
183
|
rfb.addEventListener("securityfailure", (e) => {
|
|
150
184
|
D.want = false;
|
|
151
|
-
|
|
152
|
-
|
|
185
|
+
// noVNC 按单字节读原因:服务端(苹果认证)给的是 UTF-8 的中文,转回来
|
|
186
|
+
let reason = String(e.detail?.reason ?? "");
|
|
187
|
+
try {
|
|
188
|
+
reason = new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(reason, (c) => c.charCodeAt(0)));
|
|
189
|
+
} catch {
|
|
190
|
+
// 本来就不是 UTF-8:原样用
|
|
191
|
+
}
|
|
192
|
+
reason = reason.replace(/[\s!!.。]+$/, "");
|
|
193
|
+
fail(`VNC 认证失败${reason ? `(${reason})` : ""}。用的是已有的 VNC 服务的话,检查设置里的用户名和密码`, false);
|
|
153
194
|
});
|
|
154
195
|
rfb.addEventListener("clipboard", (e) => (D.remoteClip = e.detail.text ?? ""));
|
|
155
196
|
rfb.addEventListener("desktopname", (e) => {
|
|
@@ -263,6 +304,7 @@ function renderTools() {
|
|
|
263
304
|
tool("剪贴板", "clipboard", openClipboard, { disabled: !on }),
|
|
264
305
|
tool("发送按键", "command", (e) => openKeysMenu(e.currentTarget), { disabled: !on || D.viewOnly }),
|
|
265
306
|
tool(D.viewOnly ? "只看(点一下恢复控制)" : "只看不控制", "eye", toggleViewOnly, { on: D.viewOnly }),
|
|
307
|
+
tool(`画质:${QUALITIES.find(([id]) => id === D.quality)[1]}`, "gauge", (e) => openQualityMenu(e.currentTarget)),
|
|
266
308
|
// 手机上靠双指放大,不切原始大小
|
|
267
309
|
isTouch ? null : tool(D.fit ? "原始大小" : "缩放到窗口", D.fit ? "maximize" : "restore", toggleFit),
|
|
268
310
|
tool("全屏", "expand", () => setFull(true)),
|
|
@@ -318,6 +360,25 @@ function toggleViewOnly() {
|
|
|
318
360
|
renderTools();
|
|
319
361
|
}
|
|
320
362
|
|
|
363
|
+
/** 选画质:存下来,连着的话马上按新画质重连 */
|
|
364
|
+
function openQualityMenu(anchor) {
|
|
365
|
+
const r = anchor.getBoundingClientRect();
|
|
366
|
+
showMenu(
|
|
367
|
+
{ x: r.right - 240, y: r.bottom + 4 },
|
|
368
|
+
QUALITIES.map(([id, name, hint]) => ({
|
|
369
|
+
label: `${id === D.quality ? "✓ " : " "}${name} · ${hint}`,
|
|
370
|
+
onclick: () => {
|
|
371
|
+
if (id === D.quality) return;
|
|
372
|
+
D.quality = id;
|
|
373
|
+
localStorage.setItem("aim.deskQuality", id);
|
|
374
|
+
renderTools();
|
|
375
|
+
toast(`画质:${name}`);
|
|
376
|
+
if (D.want) reconnect();
|
|
377
|
+
},
|
|
378
|
+
})),
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
321
382
|
function toggleFit() {
|
|
322
383
|
D.fit = !D.fit;
|
|
323
384
|
localStorage.setItem("aim.deskFit", D.fit ? "1" : "0");
|