@andy.ian/dsh-homing 2.1.10 → 2.1.12
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/lib/vendor/vnc.bundle.js +89 -47
- package/lib/vnc-app.js +97 -37
- package/lib/vnc-boot.js +1 -1
- package/package.json +1 -1
package/lib/vendor/vnc.bundle.js
CHANGED
|
@@ -14209,6 +14209,8 @@ var lastClickAt = 0;
|
|
|
14209
14209
|
var pollTimer = null;
|
|
14210
14210
|
var knownWindows = /* @__PURE__ */ new Set();
|
|
14211
14211
|
var windowView = null;
|
|
14212
|
+
var viewMode = "width";
|
|
14213
|
+
var lastFbSize = "";
|
|
14212
14214
|
var lastForeground = null;
|
|
14213
14215
|
var clickBaseForeground = null;
|
|
14214
14216
|
var pendingForeground = null;
|
|
@@ -14263,7 +14265,8 @@ function clearTransform() {
|
|
|
14263
14265
|
screenEl.style.overflow = "hidden";
|
|
14264
14266
|
windowView = null;
|
|
14265
14267
|
}
|
|
14266
|
-
function setViewMode(mode) {
|
|
14268
|
+
function setViewMode(mode, silent = false) {
|
|
14269
|
+
viewMode = mode;
|
|
14267
14270
|
clearTransform();
|
|
14268
14271
|
exitFocusUi();
|
|
14269
14272
|
if (rfb !== null) {
|
|
@@ -14294,7 +14297,16 @@ function setViewMode(mode) {
|
|
|
14294
14297
|
} else if (mode === "native") {
|
|
14295
14298
|
screenEl.style.overflow = "auto";
|
|
14296
14299
|
}
|
|
14297
|
-
setStatus("\u89C6\u56FE\uFF1A" + ({ width: "\u9002\u5408\u5BBD\u5EA6", screen: "\u6574\u5C4F", native: "\u539F\u59CB\u5927\u5C0F" }[mode] ?? mode));
|
|
14300
|
+
if (!silent) setStatus("\u89C6\u56FE\uFF1A" + ({ width: "\u9002\u5408\u5BBD\u5EA6", screen: "\u6574\u5C4F", native: "\u539F\u59CB\u5927\u5C0F" }[mode] ?? mode));
|
|
14301
|
+
}
|
|
14302
|
+
function refreshFramebufferView() {
|
|
14303
|
+
const canvas = canvasOf();
|
|
14304
|
+
if (!canvas || !canvas.width || !canvas.height) return;
|
|
14305
|
+
const size = canvas.width + "x" + canvas.height;
|
|
14306
|
+
if (size === lastFbSize) return;
|
|
14307
|
+
lastFbSize = size;
|
|
14308
|
+
if (windowView) focusWindowRect(windowView);
|
|
14309
|
+
else setViewMode(viewMode, true);
|
|
14298
14310
|
}
|
|
14299
14311
|
function raiseWindow(hwnd) {
|
|
14300
14312
|
fetch("/remote/input", {
|
|
@@ -14403,6 +14415,7 @@ async function pollWindows() {
|
|
|
14403
14415
|
}
|
|
14404
14416
|
if (Date.now() - lastClickAt > 5e3) pendingForeground = null;
|
|
14405
14417
|
knownWindows = ids;
|
|
14418
|
+
refreshFramebufferView();
|
|
14406
14419
|
} catch {
|
|
14407
14420
|
pollPausedUntil = Date.now() + 5e3;
|
|
14408
14421
|
}
|
|
@@ -14517,19 +14530,10 @@ async function rotateDesktop(mode) {
|
|
|
14517
14530
|
setStatus("\u5207\u6362\u5931\u8D25\uFF1A" + (data.detail || "\u672A\u77E5\u539F\u56E0"), "bad");
|
|
14518
14531
|
return;
|
|
14519
14532
|
}
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
14524
|
-
}
|
|
14525
|
-
setStatus(mode === "portrait" ? "\u5DF2\u5207\u7AD6\u5C4F\uFF0C\u91CD\u8FDE\u4E2D\u2026" : "\u5DF2\u5207\u6A2A\u5C4F\uFF0C\u91CD\u8FDE\u4E2D\u2026", "ok");
|
|
14526
|
-
setTimeout(() => {
|
|
14527
|
-
try {
|
|
14528
|
-
cleanup();
|
|
14529
|
-
connect();
|
|
14530
|
-
} catch {
|
|
14531
|
-
}
|
|
14532
|
-
}, 1200);
|
|
14533
|
+
setStatus(mode === "portrait" ? "\u5DF2\u5207\u7AD6\u5C4F\uFF0C\u753B\u9762\u81EA\u52A8\u9002\u914D\u4E2D\u2026" : "\u5DF2\u5207\u6A2A\u5C4F\uFF0C\u753B\u9762\u81EA\u52A8\u9002\u914D\u4E2D\u2026", "ok");
|
|
14534
|
+
lastFbSize = "";
|
|
14535
|
+
setTimeout(refreshFramebufferView, 1200);
|
|
14536
|
+
setTimeout(refreshFramebufferView, 3e3);
|
|
14533
14537
|
} catch (error) {
|
|
14534
14538
|
setStatus("\u5207\u6362\u5931\u8D25\uFF1A" + (error?.message ?? error), "bad");
|
|
14535
14539
|
}
|
|
@@ -14539,7 +14543,7 @@ function focusKeyboard() {
|
|
|
14539
14543
|
if (!keyboardInput) return;
|
|
14540
14544
|
try {
|
|
14541
14545
|
keyboardInput.focus({ preventScroll: true });
|
|
14542
|
-
setStatus("\u952E\u76D8\u5DF2\u6253\u5F00
|
|
14546
|
+
setStatus("\u952E\u76D8\u5DF2\u6253\u5F00", "ok");
|
|
14543
14547
|
} catch {
|
|
14544
14548
|
}
|
|
14545
14549
|
}
|
|
@@ -14660,6 +14664,14 @@ function markClick(event) {
|
|
|
14660
14664
|
if (event && event.pointerType && event.pointerType !== "mouse") focusKeyboard();
|
|
14661
14665
|
}
|
|
14662
14666
|
canvasOfGuard();
|
|
14667
|
+
var viewResizeTimer = null;
|
|
14668
|
+
window.addEventListener("resize", () => {
|
|
14669
|
+
if (viewResizeTimer !== null) clearTimeout(viewResizeTimer);
|
|
14670
|
+
viewResizeTimer = setTimeout(() => {
|
|
14671
|
+
viewResizeTimer = null;
|
|
14672
|
+
if (!windowView && viewMode === "width") setViewMode("width", true);
|
|
14673
|
+
}, 250);
|
|
14674
|
+
});
|
|
14663
14675
|
function canvasOfGuard() {
|
|
14664
14676
|
screenEl.addEventListener("pointerdown", markClick, true);
|
|
14665
14677
|
for (const type of ["pointerup", "mouseup", "click"]) {
|
|
@@ -14671,13 +14683,38 @@ function canvasOfGuard() {
|
|
|
14671
14683
|
}, true);
|
|
14672
14684
|
}
|
|
14673
14685
|
}
|
|
14686
|
+
var reconnectTimer = null;
|
|
14687
|
+
var reconnectTries = 0;
|
|
14688
|
+
var userClosed = false;
|
|
14689
|
+
function clearReconnect() {
|
|
14690
|
+
if (reconnectTimer !== null) {
|
|
14691
|
+
clearTimeout(reconnectTimer);
|
|
14692
|
+
reconnectTimer = null;
|
|
14693
|
+
}
|
|
14694
|
+
}
|
|
14695
|
+
function scheduleReconnect() {
|
|
14696
|
+
if (userClosed || reconnectTimer !== null) return;
|
|
14697
|
+
reconnectTries += 1;
|
|
14698
|
+
if (reconnectTries > 6) {
|
|
14699
|
+
setStatus("\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u8BF7\u70B9\u300C\u8FDE\u63A5\u300D\u91CD\u8BD5", "bad");
|
|
14700
|
+
return;
|
|
14701
|
+
}
|
|
14702
|
+
const delay = Math.min(800 * reconnectTries, 4e3);
|
|
14703
|
+
setStatus("\u8FDE\u63A5\u4E2D\u65AD\uFF0C" + (delay / 1e3).toFixed(1) + " \u79D2\u540E\u91CD\u8FDE\u2026", "bad");
|
|
14704
|
+
reconnectTimer = setTimeout(() => {
|
|
14705
|
+
reconnectTimer = null;
|
|
14706
|
+
if (rfb === null && !userClosed) connect();
|
|
14707
|
+
}, delay);
|
|
14708
|
+
}
|
|
14674
14709
|
function cleanup() {
|
|
14710
|
+
clearReconnect();
|
|
14675
14711
|
if (rfb !== null) {
|
|
14712
|
+
const old = rfb;
|
|
14713
|
+
rfb = null;
|
|
14676
14714
|
try {
|
|
14677
|
-
|
|
14715
|
+
old.disconnect();
|
|
14678
14716
|
} catch {
|
|
14679
14717
|
}
|
|
14680
|
-
rfb = null;
|
|
14681
14718
|
}
|
|
14682
14719
|
connected = false;
|
|
14683
14720
|
stopPolling();
|
|
@@ -14687,11 +14724,21 @@ function cleanup() {
|
|
|
14687
14724
|
passwordEl.disabled = false;
|
|
14688
14725
|
}
|
|
14689
14726
|
function connect() {
|
|
14690
|
-
|
|
14727
|
+
userClosed = false;
|
|
14728
|
+
clearReconnect();
|
|
14729
|
+
if (rfb !== null) {
|
|
14730
|
+
const old = rfb;
|
|
14731
|
+
rfb = null;
|
|
14732
|
+
try {
|
|
14733
|
+
old.disconnect();
|
|
14734
|
+
} catch {
|
|
14735
|
+
}
|
|
14736
|
+
}
|
|
14691
14737
|
setStatus("\u8FDE\u63A5\u4E2D\u2026");
|
|
14692
14738
|
connectBtn.disabled = true;
|
|
14739
|
+
let client = null;
|
|
14693
14740
|
try {
|
|
14694
|
-
|
|
14741
|
+
client = new RFB(screenEl, wsUrl(), {
|
|
14695
14742
|
wsProtocols: ["binary"]
|
|
14696
14743
|
});
|
|
14697
14744
|
} catch (error) {
|
|
@@ -14699,13 +14746,17 @@ function connect() {
|
|
|
14699
14746
|
cleanup();
|
|
14700
14747
|
return;
|
|
14701
14748
|
}
|
|
14702
|
-
rfb
|
|
14703
|
-
|
|
14704
|
-
|
|
14705
|
-
|
|
14749
|
+
rfb = client;
|
|
14750
|
+
client.scaleViewport = false;
|
|
14751
|
+
client.clipViewport = false;
|
|
14752
|
+
client.showDotCursor = false;
|
|
14753
|
+
client.focusOnClick = true;
|
|
14706
14754
|
setViewMode("width");
|
|
14707
|
-
|
|
14755
|
+
client.addEventListener("connect", () => {
|
|
14756
|
+
if (rfb !== client) return;
|
|
14757
|
+
reconnectTries = 0;
|
|
14708
14758
|
connected = true;
|
|
14759
|
+
lastFbSize = "";
|
|
14709
14760
|
report("connect-ok", "ok");
|
|
14710
14761
|
disconnectBtn.disabled = false;
|
|
14711
14762
|
passwordEl.disabled = true;
|
|
@@ -14719,40 +14770,31 @@ function connect() {
|
|
|
14719
14770
|
});
|
|
14720
14771
|
}
|
|
14721
14772
|
});
|
|
14722
|
-
|
|
14773
|
+
client.addEventListener("disconnect", (event) => {
|
|
14774
|
+
if (rfb !== client) return;
|
|
14723
14775
|
const clean = event.detail?.clean ?? false;
|
|
14724
|
-
report("disconnect", clean ? "clean" : "dirty", { detail: event.detail ?? null, reason:
|
|
14725
|
-
|
|
14776
|
+
report("disconnect", clean ? "clean" : "dirty", { detail: event.detail ?? null, reason: client._lastFailReason ?? null });
|
|
14777
|
+
rfb = null;
|
|
14726
14778
|
cleanup();
|
|
14779
|
+
if (clean || userClosed) {
|
|
14780
|
+
setStatus("\u5DF2\u65AD\u5F00", clean ? "" : "bad");
|
|
14781
|
+
return;
|
|
14782
|
+
}
|
|
14783
|
+
scheduleReconnect();
|
|
14727
14784
|
});
|
|
14728
|
-
|
|
14785
|
+
client.addEventListener("securityfailure", (event) => {
|
|
14786
|
+
if (rfb !== client) return;
|
|
14729
14787
|
setStatus("\u8BA4\u8BC1\u5931\u8D25\uFF1A" + (event.detail?.reason ?? "\u5BC6\u7801\u9519\u8BEF"), "bad");
|
|
14788
|
+
rfb = null;
|
|
14730
14789
|
cleanup();
|
|
14731
14790
|
});
|
|
14732
14791
|
}
|
|
14733
14792
|
connectBtn.addEventListener("click", connect);
|
|
14734
14793
|
disconnectBtn.addEventListener("click", () => {
|
|
14794
|
+
userClosed = true;
|
|
14735
14795
|
cleanup();
|
|
14736
14796
|
setStatus("\u5DF2\u65AD\u5F00");
|
|
14737
14797
|
});
|
|
14738
|
-
window.addEventListener("pagehide", () => {
|
|
14739
|
-
try {
|
|
14740
|
-
if (localStorage.getItem("dsh-vnc-portrait") === "1") {
|
|
14741
|
-
localStorage.removeItem("dsh-vnc-portrait");
|
|
14742
|
-
const body = new Blob([JSON.stringify({ kind: "rotate", mode: "landscape" })], { type: "application/json" });
|
|
14743
|
-
if (navigator.sendBeacon) navigator.sendBeacon("/remote/input", body);
|
|
14744
|
-
else fetch("/remote/input", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ kind: "rotate", mode: "landscape" }), keepalive: true }).catch(() => {
|
|
14745
|
-
});
|
|
14746
|
-
}
|
|
14747
|
-
} catch {
|
|
14748
|
-
}
|
|
14749
|
-
if (rfb !== null) {
|
|
14750
|
-
try {
|
|
14751
|
-
rfb.disconnect();
|
|
14752
|
-
} catch {
|
|
14753
|
-
}
|
|
14754
|
-
}
|
|
14755
|
-
});
|
|
14756
14798
|
setupMobileKeyboard();
|
|
14757
14799
|
setupToolbar();
|
|
14758
14800
|
function autoConnect() {
|
package/lib/vnc-app.js
CHANGED
|
@@ -37,6 +37,8 @@ let lastClickAt = 0
|
|
|
37
37
|
let pollTimer = null
|
|
38
38
|
let knownWindows = new Set()
|
|
39
39
|
let windowView = null
|
|
40
|
+
let viewMode = 'width'
|
|
41
|
+
let lastFbSize = ''
|
|
40
42
|
let lastForeground = null
|
|
41
43
|
let clickBaseForeground = null
|
|
42
44
|
let pendingForeground = null
|
|
@@ -112,7 +114,8 @@ function clearTransform() {
|
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
/** 视图:width=铺满宽度可竖滚;screen=整屏;native=1:1 可平移 */
|
|
115
|
-
function setViewMode(mode) {
|
|
117
|
+
function setViewMode(mode, silent = false) {
|
|
118
|
+
viewMode = mode
|
|
116
119
|
clearTransform()
|
|
117
120
|
exitFocusUi()
|
|
118
121
|
if (rfb !== null) {
|
|
@@ -145,7 +148,19 @@ function setViewMode(mode) {
|
|
|
145
148
|
} else if (mode === 'native') {
|
|
146
149
|
screenEl.style.overflow = 'auto'
|
|
147
150
|
}
|
|
148
|
-
setStatus('视图:' + ({ width: '适合宽度', screen: '整屏', native: '原始大小' }[mode] ?? mode))
|
|
151
|
+
if (!silent) setStatus('视图:' + ({ width: '适合宽度', screen: '整屏', native: '原始大小' }[mode] ?? mode))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** 设备像素比/帧缓冲变化后重新应用视图(转屏、窗口缩放都会触发) */
|
|
155
|
+
function refreshFramebufferView() {
|
|
156
|
+
const canvas = canvasOf()
|
|
157
|
+
if (!canvas || !canvas.width || !canvas.height) return
|
|
158
|
+
const size = canvas.width + 'x' + canvas.height
|
|
159
|
+
if (size === lastFbSize) return
|
|
160
|
+
lastFbSize = size
|
|
161
|
+
// 正在看某个窗口 → 按新帧缓冲重新裁剪;否则按当前视图模式重新缩放
|
|
162
|
+
if (windowView) focusWindowRect(windowView)
|
|
163
|
+
else setViewMode(viewMode, true)
|
|
149
164
|
}
|
|
150
165
|
|
|
151
166
|
/** 把视图裁剪/缩放到指定窗口矩形(自动切窗时用) */
|
|
@@ -288,6 +303,7 @@ async function pollWindows() {
|
|
|
288
303
|
if (Date.now() - lastClickAt > 5000) pendingForeground = null
|
|
289
304
|
|
|
290
305
|
knownWindows = ids
|
|
306
|
+
refreshFramebufferView()
|
|
291
307
|
} catch {
|
|
292
308
|
// 窗口代理卡住/超时:暂停轮询 5 秒,别把请求链继续堆满
|
|
293
309
|
pollPausedUntil = Date.now() + 5000
|
|
@@ -410,14 +426,12 @@ async function rotateDesktop(mode) {
|
|
|
410
426
|
setStatus('切换失败:' + (data.detail || '未知原因'), 'bad')
|
|
411
427
|
return
|
|
412
428
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
setTimeout(
|
|
419
|
-
try { cleanup(); connect() } catch { /* 忽略 */ }
|
|
420
|
-
}, 1200)
|
|
429
|
+
// 不再强制重连:noVNC 会随帧缓冲尺寸变化自动适配;
|
|
430
|
+
// 若 TightVNC 因分辨率变化断开,由下面的自动重连逻辑接管。
|
|
431
|
+
setStatus(mode === 'portrait' ? '已切竖屏,画面自动适配中…' : '已切横屏,画面自动适配中…', 'ok')
|
|
432
|
+
lastFbSize = '' // 强制下一轮重新计算缩放
|
|
433
|
+
setTimeout(refreshFramebufferView, 1200)
|
|
434
|
+
setTimeout(refreshFramebufferView, 3000)
|
|
421
435
|
} catch (error) {
|
|
422
436
|
setStatus('切换失败:' + (error?.message ?? error), 'bad')
|
|
423
437
|
}
|
|
@@ -430,7 +444,7 @@ function focusKeyboard() {
|
|
|
430
444
|
if (!keyboardInput) return
|
|
431
445
|
try {
|
|
432
446
|
keyboardInput.focus({ preventScroll: true })
|
|
433
|
-
setStatus('
|
|
447
|
+
setStatus('键盘已打开', 'ok')
|
|
434
448
|
} catch { /* 忽略 */ }
|
|
435
449
|
}
|
|
436
450
|
|
|
@@ -557,6 +571,16 @@ function markClick(event) {
|
|
|
557
571
|
|
|
558
572
|
canvasOfGuard()
|
|
559
573
|
|
|
574
|
+
let viewResizeTimer = null
|
|
575
|
+
window.addEventListener('resize', () => {
|
|
576
|
+
if (viewResizeTimer !== null) clearTimeout(viewResizeTimer)
|
|
577
|
+
viewResizeTimer = setTimeout(() => {
|
|
578
|
+
viewResizeTimer = null
|
|
579
|
+
if (!windowView && viewMode === 'width') setViewMode('width', true)
|
|
580
|
+
}, 250)
|
|
581
|
+
})
|
|
582
|
+
|
|
583
|
+
|
|
560
584
|
function canvasOfGuard() {
|
|
561
585
|
// 画布由 noVNC 创建,这里只挂事件委托
|
|
562
586
|
screenEl.addEventListener('pointerdown', markClick, true)
|
|
@@ -571,10 +595,39 @@ function canvasOfGuard() {
|
|
|
571
595
|
}
|
|
572
596
|
}
|
|
573
597
|
|
|
598
|
+
let reconnectTimer = null
|
|
599
|
+
let reconnectTries = 0
|
|
600
|
+
let userClosed = false
|
|
601
|
+
|
|
602
|
+
function clearReconnect() {
|
|
603
|
+
if (reconnectTimer !== null) {
|
|
604
|
+
clearTimeout(reconnectTimer)
|
|
605
|
+
reconnectTimer = null
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/** 非用户主动断开:退避重连(TightVNC 在分辨率变化时可能断开连接) */
|
|
610
|
+
function scheduleReconnect() {
|
|
611
|
+
if (userClosed || reconnectTimer !== null) return
|
|
612
|
+
reconnectTries += 1
|
|
613
|
+
if (reconnectTries > 6) {
|
|
614
|
+
setStatus('连接中断,请点「连接」重试', 'bad')
|
|
615
|
+
return
|
|
616
|
+
}
|
|
617
|
+
const delay = Math.min(800 * reconnectTries, 4000)
|
|
618
|
+
setStatus('连接中断,' + (delay / 1000).toFixed(1) + ' 秒后重连…', 'bad')
|
|
619
|
+
reconnectTimer = setTimeout(() => {
|
|
620
|
+
reconnectTimer = null
|
|
621
|
+
if (rfb === null && !userClosed) connect()
|
|
622
|
+
}, delay)
|
|
623
|
+
}
|
|
624
|
+
|
|
574
625
|
function cleanup() {
|
|
626
|
+
clearReconnect()
|
|
575
627
|
if (rfb !== null) {
|
|
576
|
-
|
|
628
|
+
const old = rfb
|
|
577
629
|
rfb = null
|
|
630
|
+
try { old.disconnect() } catch { /* 已断开 */ }
|
|
578
631
|
}
|
|
579
632
|
connected = false
|
|
580
633
|
stopPolling()
|
|
@@ -585,12 +638,20 @@ function cleanup() {
|
|
|
585
638
|
}
|
|
586
639
|
|
|
587
640
|
function connect() {
|
|
588
|
-
|
|
641
|
+
userClosed = false
|
|
642
|
+
clearReconnect()
|
|
643
|
+
if (rfb !== null) {
|
|
644
|
+
const old = rfb
|
|
645
|
+
rfb = null
|
|
646
|
+
try { old.disconnect() } catch { /* 已断开 */ }
|
|
647
|
+
}
|
|
589
648
|
setStatus('连接中…')
|
|
590
649
|
connectBtn.disabled = true
|
|
650
|
+
|
|
651
|
+
let client = null
|
|
591
652
|
try {
|
|
592
653
|
// 密码由服务端代认证(lib/vnc-auth-proxy.mjs),浏览器不持有密码
|
|
593
|
-
|
|
654
|
+
client = new RFB(screenEl, wsUrl(), {
|
|
594
655
|
wsProtocols: ['binary'],
|
|
595
656
|
})
|
|
596
657
|
} catch (error) {
|
|
@@ -598,15 +659,18 @@ function connect() {
|
|
|
598
659
|
cleanup()
|
|
599
660
|
return
|
|
600
661
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
662
|
+
rfb = client
|
|
663
|
+
client.scaleViewport = false
|
|
664
|
+
client.clipViewport = false
|
|
665
|
+
client.showDotCursor = false
|
|
666
|
+
client.focusOnClick = true
|
|
606
667
|
setViewMode('width')
|
|
607
668
|
|
|
608
|
-
|
|
669
|
+
client.addEventListener('connect', () => {
|
|
670
|
+
if (rfb !== client) return
|
|
671
|
+
reconnectTries = 0
|
|
609
672
|
connected = true
|
|
673
|
+
lastFbSize = ''
|
|
610
674
|
report('connect-ok', 'ok')
|
|
611
675
|
disconnectBtn.disabled = false
|
|
612
676
|
passwordEl.disabled = true
|
|
@@ -618,37 +682,33 @@ function connect() {
|
|
|
618
682
|
focusByHwnd(focus).then((found) => { if (!found) setStatus('未找到对应窗口,已显示整屏') })
|
|
619
683
|
}
|
|
620
684
|
})
|
|
621
|
-
|
|
685
|
+
client.addEventListener('disconnect', (event) => {
|
|
686
|
+
if (rfb !== client) return // 旧连接的迟到事件不能影响新连接
|
|
622
687
|
const clean = event.detail?.clean ?? false
|
|
623
|
-
report('disconnect', clean ? 'clean' : 'dirty', { detail: event.detail ?? null, reason:
|
|
624
|
-
|
|
688
|
+
report('disconnect', clean ? 'clean' : 'dirty', { detail: event.detail ?? null, reason: client._lastFailReason ?? null })
|
|
689
|
+
rfb = null
|
|
625
690
|
cleanup()
|
|
691
|
+
if (clean || userClosed) {
|
|
692
|
+
setStatus('已断开', clean ? '' : 'bad')
|
|
693
|
+
return
|
|
694
|
+
}
|
|
695
|
+
scheduleReconnect()
|
|
626
696
|
})
|
|
627
|
-
|
|
697
|
+
client.addEventListener('securityfailure', (event) => {
|
|
698
|
+
if (rfb !== client) return
|
|
628
699
|
setStatus('认证失败:' + (event.detail?.reason ?? '密码错误'), 'bad')
|
|
700
|
+
rfb = null
|
|
629
701
|
cleanup()
|
|
630
702
|
})
|
|
631
703
|
}
|
|
632
704
|
|
|
633
705
|
connectBtn.addEventListener('click', connect)
|
|
634
706
|
disconnectBtn.addEventListener('click', () => {
|
|
707
|
+
userClosed = true
|
|
635
708
|
cleanup()
|
|
636
709
|
setStatus('已断开')
|
|
637
710
|
})
|
|
638
711
|
|
|
639
|
-
window.addEventListener('pagehide', () => {
|
|
640
|
-
// 离开页面时如果竖屏是我们切的,恢复横屏,避免把 PC 留在竖屏
|
|
641
|
-
try {
|
|
642
|
-
if (localStorage.getItem('dsh-vnc-portrait') === '1') {
|
|
643
|
-
localStorage.removeItem('dsh-vnc-portrait')
|
|
644
|
-
const body = new Blob([JSON.stringify({ kind: 'rotate', mode: 'landscape' })], { type: 'application/json' })
|
|
645
|
-
if (navigator.sendBeacon) navigator.sendBeacon('/remote/input', body)
|
|
646
|
-
else fetch('/remote/input', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ kind: 'rotate', mode: 'landscape' }), keepalive: true }).catch(() => {})
|
|
647
|
-
}
|
|
648
|
-
} catch { /* 忽略 */ }
|
|
649
|
-
if (rfb !== null) { try { rfb.disconnect() } catch { /* 忽略 */ } }
|
|
650
|
-
})
|
|
651
|
-
|
|
652
712
|
setupMobileKeyboard()
|
|
653
713
|
setupToolbar()
|
|
654
714
|
|
package/lib/vnc-boot.js
CHANGED