Compare commits
2
Commits
2cbed0dcdf
...
5bb24d714a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bb24d714a | ||
|
|
6fd6e9cbaa |
No files matched your search
@@ -673,6 +673,9 @@ BOOL CScreenManager::OnReconnect()
|
|||||||
if (!m_bIsWorking) {
|
if (!m_bIsWorking) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
// 断线期间主控端的 keyup 可能已经丢了;重连前先把按着的键松开,
|
||||||
|
// 否则远程要等到用户再按一次同一个修饰键才恢复。
|
||||||
|
ReleaseInjectedKeys();
|
||||||
auto duration = GetTickCount64() - m_nReconnectTime;
|
auto duration = GetTickCount64() - m_nReconnectTime;
|
||||||
if (duration <= 3000)
|
if (duration <= 3000)
|
||||||
Sleep(3000 - duration);
|
Sleep(3000 - duration);
|
||||||
@@ -841,6 +844,8 @@ VOID CScreenManager::SendBitMapInfo()
|
|||||||
CScreenManager::~CScreenManager()
|
CScreenManager::~CScreenManager()
|
||||||
{
|
{
|
||||||
Mprintf("ScreenManager 析构函数\n");
|
Mprintf("ScreenManager 析构函数\n");
|
||||||
|
// 会话结束:主控端不会再送来 keyup,把还按着的键松开。
|
||||||
|
ReleaseInjectedKeys();
|
||||||
if (!m_Signature.empty())
|
if (!m_Signature.empty())
|
||||||
UninitFileUpload();
|
UninitFileUpload();
|
||||||
m_bIsWorking = FALSE;
|
m_bIsWorking = FALSE;
|
||||||
@@ -1841,6 +1846,69 @@ bool IsExtendedKey(WPARAM vKey)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 辅助判断是否为修饰键(VK_SHIFT/CONTROL/MENU 以及左右专有码、Win 键)
|
||||||
|
static bool IsModifierKeyVK(WORD vk)
|
||||||
|
{
|
||||||
|
switch (vk) {
|
||||||
|
case VK_SHIFT:
|
||||||
|
case VK_LSHIFT:
|
||||||
|
case VK_RSHIFT:
|
||||||
|
case VK_CONTROL:
|
||||||
|
case VK_LCONTROL:
|
||||||
|
case VK_RCONTROL:
|
||||||
|
case VK_MENU:
|
||||||
|
case VK_LMENU:
|
||||||
|
case VK_RMENU:
|
||||||
|
case VK_LWIN:
|
||||||
|
case VK_RWIN:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注入按键的身份:VK 在低 16 位,扫描码在 16..23,扩展位在 bit24。左右
|
||||||
|
// Shift/Ctrl/Alt 的 VK 完全相同,只有扫描码(Shift)或扩展位(右 Ctrl/Alt)
|
||||||
|
// 能区分;补发 keyup 必须复用按下时的身份,否则右 Shift 抬起的是左 Shift,
|
||||||
|
// 远程右侧修饰键仍然保持按下。
|
||||||
|
static DWORD MakeInjectedKeyId(WORD vk, WORD scan, bool extended)
|
||||||
|
{
|
||||||
|
return (DWORD)vk | ((DWORD)(scan & 0xFF) << 16) | (extended ? (1UL << 24) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CScreenManager::TrackInjectedKey(DWORD keyId, bool down)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_InjectedKeysMutex);
|
||||||
|
if (down) m_InjectedKeys.insert(keyId);
|
||||||
|
else m_InjectedKeys.erase(keyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 补发所有未收到 keyup 的按键:先普通键再修饰键。主控端丢 keyup 或直接断开时
|
||||||
|
// 调用,避免远程系统把 Ctrl/Shift/Alt 一直当成按下("打字很怪"的根因)。
|
||||||
|
void CScreenManager::ReleaseInjectedKeys()
|
||||||
|
{
|
||||||
|
std::set<DWORD> keys;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_InjectedKeysMutex);
|
||||||
|
keys.swap(m_InjectedKeys);
|
||||||
|
}
|
||||||
|
if (keys.empty()) return;
|
||||||
|
Mprintf("ScreenManager: 补发 %zu 个按键的 keyup\n", keys.size());
|
||||||
|
INPUT k_input = { 0 };
|
||||||
|
k_input.type = INPUT_KEYBOARD;
|
||||||
|
for (int pass = 0; pass < 2; ++pass) {
|
||||||
|
for (DWORD id : keys) {
|
||||||
|
WORD vk = (WORD)(id & 0xFFFF);
|
||||||
|
if (IsModifierKeyVK(vk) != (pass == 1)) continue;
|
||||||
|
k_input.ki.wVk = vk;
|
||||||
|
k_input.ki.wScan = (WORD)((id >> 16) & 0xFF);
|
||||||
|
k_input.ki.dwFlags = KEYEVENTF_KEYUP;
|
||||||
|
if (id & (1UL << 24)) k_input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
|
SendInput(1, &k_input, sizeof(INPUT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VOID CScreenManager::ProcessCommand(LPBYTE szBuffer, ULONG ulLength)
|
VOID CScreenManager::ProcessCommand(LPBYTE szBuffer, ULONG ulLength)
|
||||||
{
|
{
|
||||||
// 记录大小判定:现代控制端(本服务端)统一发 48 字节 MSG64;28 字节 MSG32 仅为兼容
|
// 记录大小判定:现代控制端(本服务端)统一发 48 字节 MSG64;28 字节 MSG32 仅为兼容
|
||||||
@@ -2353,7 +2421,9 @@ VOID CScreenManager::ProcessCommand(LPBYTE szBuffer, ULONG ulLength)
|
|||||||
k_input.ki.dwFlags = 0;
|
k_input.ki.dwFlags = 0;
|
||||||
if ((Msg->lParam >> 24) & 1) // 从 lParam bit24 取扩展键标志
|
if ((Msg->lParam >> 24) & 1) // 从 lParam bit24 取扩展键标志
|
||||||
k_input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
k_input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
SendInput(1, &k_input, sizeof(INPUT));
|
if (SendInput(1, &k_input, sizeof(INPUT)) == 1)
|
||||||
|
TrackInjectedKey(MakeInjectedKeyId((WORD)Msg->wParam, k_input.ki.wScan,
|
||||||
|
(k_input.ki.dwFlags & KEYEVENTF_EXTENDEDKEY) != 0), true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
@@ -2365,7 +2435,9 @@ VOID CScreenManager::ProcessCommand(LPBYTE szBuffer, ULONG ulLength)
|
|||||||
k_input.ki.dwFlags = KEYEVENTF_KEYUP;
|
k_input.ki.dwFlags = KEYEVENTF_KEYUP;
|
||||||
if ((Msg->lParam >> 24) & 1) // 从 lParam bit24 取扩展键标志
|
if ((Msg->lParam >> 24) & 1) // 从 lParam bit24 取扩展键标志
|
||||||
k_input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
k_input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
SendInput(1, &k_input, sizeof(INPUT));
|
if (SendInput(1, &k_input, sizeof(INPUT)) == 1)
|
||||||
|
TrackInjectedKey(MakeInjectedKeyId((WORD)Msg->wParam, k_input.ki.wScan,
|
||||||
|
(k_input.ki.dwFlags & KEYEVENTF_EXTENDEDKEY) != 0), false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ bool IsWindows8orHigher();
|
|||||||
|
|
||||||
#include "ScreenSpy.h"
|
#include "ScreenSpy.h"
|
||||||
#include "ScreenCapture.h"
|
#include "ScreenCapture.h"
|
||||||
|
#include <set>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
// WASAPI 前向声明 (COM 接口)
|
// WASAPI 前向声明 (COM 接口)
|
||||||
struct IMMDevice;
|
struct IMMDevice;
|
||||||
@@ -61,6 +63,13 @@ public:
|
|||||||
VOID SendNextScreen(const char* szBuffer, ULONG ulNextSendLength);
|
VOID SendNextScreen(const char* szBuffer, ULONG ulNextSendLength);
|
||||||
|
|
||||||
VOID ProcessCommand(LPBYTE szBuffer, ULONG ulLength);
|
VOID ProcessCommand(LPBYTE szBuffer, ULONG ulLength);
|
||||||
|
// 已注入、尚未收到 keyup 的按键。主控端丢 keyup(浏览器失焦/断线、控制端
|
||||||
|
// 切换窗口)时远程系统会把 Ctrl/Shift/Alt 一直当成按下,表现为"打字很怪"。
|
||||||
|
// 会话结束或重连时在这里补发 keyup 兜底。
|
||||||
|
// keyId 编码 VK+扫描码+扩展位(见 MakeInjectedKeyId):左右 Shift/Ctrl/Alt
|
||||||
|
// 的 VK 相同,必须按注入时的同一身份补发,否则抬起的是另一边的键。
|
||||||
|
void TrackInjectedKey(DWORD keyId, bool down);
|
||||||
|
void ReleaseInjectedKeys();
|
||||||
UserParam *m_pUserParam = NULL;
|
UserParam *m_pUserParam = NULL;
|
||||||
INT_PTR m_ptrUser;
|
INT_PTR m_ptrUser;
|
||||||
HDESK g_hDesk;
|
HDESK g_hDesk;
|
||||||
@@ -118,6 +127,8 @@ public:
|
|||||||
POINT m_rclickPoint; // 右键点击坐标
|
POINT m_rclickPoint; // 右键点击坐标
|
||||||
HWND m_rclickWnd; // 右键窗口
|
HWND m_rclickWnd; // 右键窗口
|
||||||
int m_nSwitchWindowIndex = 0; // 切换窗口索引
|
int m_nSwitchWindowIndex = 0; // 切换窗口索引
|
||||||
|
std::set<DWORD> m_InjectedKeys; // 注入后未收到 keyup 的键(VK+扫描码+扩展位)
|
||||||
|
std::mutex m_InjectedKeysMutex; // ProcessCommand 与析构/重连可能并发
|
||||||
|
|
||||||
// ========== 系统音频捕获 (WASAPI Loopback) ==========
|
// ========== 系统音频捕获 (WASAPI Loopback) ==========
|
||||||
volatile BOOL m_bAudioThreadRunning = FALSE;// 音频线程运行标志(独立于视频线程)
|
volatile BOOL m_bAudioThreadRunning = FALSE;// 音频线程运行标志(独立于视频线程)
|
||||||
|
|||||||
+49
-2
@@ -10,6 +10,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <set>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -420,6 +421,27 @@ public:
|
|||||||
m_captureThread.join();
|
m_captureThread.join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 会话结束:控制端不会再来 keyup,把还按着的键松开(修饰键最后放),
|
||||||
|
// 否则 X 服务器一直认为 Ctrl/Shift/Alt 按下,表现为"远程打字很怪"。
|
||||||
|
if (m_inputDisplay && m_x11.pXTestFakeKeyEvent) {
|
||||||
|
std::set<unsigned int> keys, modifierKeys;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_injectedKeysMutex);
|
||||||
|
keys.swap(m_injectedKeys);
|
||||||
|
modifierKeys.swap(m_injectedModifierKeys);
|
||||||
|
}
|
||||||
|
for (auto& kc : modifierKeys) keys.erase(kc);
|
||||||
|
bool any = false;
|
||||||
|
for (unsigned int keycode : keys) {
|
||||||
|
m_x11.pXTestFakeKeyEvent(m_inputDisplay, keycode, False, 0);
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
|
for (unsigned int keycode : modifierKeys) {
|
||||||
|
m_x11.pXTestFakeKeyEvent(m_inputDisplay, keycode, False, 0);
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
|
if (any) m_x11.pXFlush(m_inputDisplay);
|
||||||
|
}
|
||||||
if (m_inputDisplay && m_x11.pXCloseDisplay) {
|
if (m_inputDisplay && m_x11.pXCloseDisplay) {
|
||||||
m_x11.pXCloseDisplay(m_inputDisplay);
|
m_x11.pXCloseDisplay(m_inputDisplay);
|
||||||
m_inputDisplay = nullptr;
|
m_inputDisplay = nullptr;
|
||||||
@@ -866,7 +888,8 @@ public:
|
|||||||
if (keysym) {
|
if (keysym) {
|
||||||
unsigned int keycode = m_x11.pXKeysymToKeycode(m_inputDisplay, keysym);
|
unsigned int keycode = m_x11.pXKeysymToKeycode(m_inputDisplay, keysym);
|
||||||
if (keycode) {
|
if (keycode) {
|
||||||
m_x11.pXTestFakeKeyEvent(m_inputDisplay, keycode, True, 0);
|
if (m_x11.pXTestFakeKeyEvent(m_inputDisplay, keycode, True, 0))
|
||||||
|
TrackInjectedKey(keycode, IsModifierVK(vk), true);
|
||||||
m_x11.pXFlush(m_inputDisplay);
|
m_x11.pXFlush(m_inputDisplay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -880,7 +903,8 @@ public:
|
|||||||
if (keysym) {
|
if (keysym) {
|
||||||
unsigned int keycode = m_x11.pXKeysymToKeycode(m_inputDisplay, keysym);
|
unsigned int keycode = m_x11.pXKeysymToKeycode(m_inputDisplay, keysym);
|
||||||
if (keycode) {
|
if (keycode) {
|
||||||
m_x11.pXTestFakeKeyEvent(m_inputDisplay, keycode, False, 0);
|
if (m_x11.pXTestFakeKeyEvent(m_inputDisplay, keycode, False, 0))
|
||||||
|
TrackInjectedKey(keycode, false, false);
|
||||||
m_x11.pXFlush(m_inputDisplay);
|
m_x11.pXFlush(m_inputDisplay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -889,7 +913,30 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 注入后尚未收到 keyup 的按键(X keycode)。控制端丢 keyup 或直接断开时
|
||||||
|
// 在析构里补发 keyup,避免 X 服务器一直认为修饰键按下。
|
||||||
|
static bool IsModifierVK(unsigned int vk)
|
||||||
|
{
|
||||||
|
// Shift / Ctrl / Alt / LWin / RWin
|
||||||
|
return vk == 16 || vk == 17 || vk == 18 || vk == 91 || vk == 92;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackInjectedKey(unsigned int keycode, bool isModifier, bool down)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_injectedKeysMutex);
|
||||||
|
if (down) {
|
||||||
|
m_injectedKeys.insert(keycode);
|
||||||
|
if (isModifier) m_injectedModifierKeys.insert(keycode);
|
||||||
|
} else {
|
||||||
|
m_injectedKeys.erase(keycode);
|
||||||
|
m_injectedModifierKeys.erase(keycode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::set<unsigned int> m_injectedKeys; // 注入后未收到 keyup 的 X keycode
|
||||||
|
std::set<unsigned int> m_injectedModifierKeys; // 其中属于修饰键的部分(最后释放)
|
||||||
|
std::mutex m_injectedKeysMutex; // OnReceive 回调与析构可能并发
|
||||||
IOCPClient* m_client;
|
IOCPClient* m_client;
|
||||||
std::atomic<bool> m_running;
|
std::atomic<bool> m_running;
|
||||||
std::atomic<bool> m_destroyed; // Flag to prevent Start() after destruction begins
|
std::atomic<bool> m_destroyed; // Flag to prevent Start() after destruction begins
|
||||||
|
|||||||
+491
-8
@@ -860,6 +860,9 @@
|
|||||||
}
|
}
|
||||||
.stats-bar {
|
.stats-bar {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
position: relative;
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
@@ -883,6 +886,137 @@
|
|||||||
accent-color: #e94560;
|
accent-color: #e94560;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
/* 分组过滤器:桌面端把各分组平铺在 Total 行(chip),手机端收进下拉面板。 */
|
||||||
|
.stats-bar .group-filter {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.group-filter-label { color: #666; }
|
||||||
|
.group-chip {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
max-width: 220px;
|
||||||
|
padding: 2px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||||
|
background: transparent;
|
||||||
|
color: #bbb;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.6;
|
||||||
|
cursor: pointer;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.group-chip:hover { border-color: rgba(233, 69, 96, 0.5); color: #fff; }
|
||||||
|
.group-chip.active {
|
||||||
|
background: #e94560;
|
||||||
|
border-color: #e94560;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.group-chip-name {
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.group-chip .group-chip-count { flex: 0 0 auto; font-size: 11px; opacity: 0.65; }
|
||||||
|
/* 手机端:分组下拉(面板里用按钮行,避免 label+checkbox 的重复触发) */
|
||||||
|
.group-dd { display: inline-flex; }
|
||||||
|
.group-dd-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
max-width: 55vw;
|
||||||
|
padding: 6px 12px;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||||
|
background: rgba(0, 0, 0, 0.2);
|
||||||
|
color: #bbb;
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
.group-dd-btn.active { border-color: #e94560; color: #e94560; }
|
||||||
|
.group-dd-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
||||||
|
.group-dd-caret { font-size: 10px; opacity: 0.7; }
|
||||||
|
/* 面板锚在 Total 这一行的左边缘(.stats-bar 为定位祖先),而不是按钮本身:
|
||||||
|
按钮在窄屏上常靠右,按按钮定位会让面板探出屏幕右缘。 */
|
||||||
|
.group-dd-panel {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 6px);
|
||||||
|
left: 16px;
|
||||||
|
right: 16px;
|
||||||
|
max-width: 320px;
|
||||||
|
z-index: 60;
|
||||||
|
max-height: 60vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 6px;
|
||||||
|
border: 1px solid #0f3460;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #16213e;
|
||||||
|
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
|
||||||
|
}
|
||||||
|
.group-dd-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
width: 100%;
|
||||||
|
padding: 9px 8px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: transparent;
|
||||||
|
color: #ddd;
|
||||||
|
font-size: 13px;
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.group-dd-item:active { background: rgba(255, 255, 255, 0.06); }
|
||||||
|
.group-dd-item.active { color: #fff; }
|
||||||
|
.group-dd-check {
|
||||||
|
flex: 0 0 16px;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
line-height: 16px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.25);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.group-dd-item.active .group-dd-check { background: #e94560; border-color: #e94560; }
|
||||||
|
.group-dd-name {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.group-dd-count { color: #888; font-size: 11px; }
|
||||||
|
.group-dd-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 4px;
|
||||||
|
padding-top: 6px;
|
||||||
|
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
}
|
||||||
|
.group-dd-clear,
|
||||||
|
.group-dd-done {
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||||
|
background: transparent;
|
||||||
|
color: #bbb;
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.group-dd-clear:disabled { opacity: 0.4; cursor: default; }
|
||||||
|
.group-dd-done { border-color: rgba(233, 69, 96, 0.5); color: #e94560; }
|
||||||
|
|
||||||
#screen-page {
|
#screen-page {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@@ -1748,6 +1882,7 @@
|
|||||||
<div id="stats-bar" class="stats-bar">
|
<div id="stats-bar" class="stats-bar">
|
||||||
<div class="stat">Total: <strong id="stat-total">0</strong></div>
|
<div class="stat">Total: <strong id="stat-total">0</strong></div>
|
||||||
<div class="stat">Showing: <strong id="stat-showing">0</strong></div>
|
<div class="stat">Showing: <strong id="stat-showing">0</strong></div>
|
||||||
|
<div class="stat group-filter" id="group-filter"></div>
|
||||||
<label class="stat offline-toggle" id="offline-toggle"
|
<label class="stat offline-toggle" id="offline-toggle"
|
||||||
title="Show devices that have connected before but are offline now">
|
title="Show devices that have connected before but are offline now">
|
||||||
<input type="checkbox" id="show-offline" onchange="onOfflineToggle(this.checked)">
|
<input type="checkbox" id="show-offline" onchange="onOfflineToggle(this.checked)">
|
||||||
@@ -2261,6 +2396,18 @@
|
|||||||
try {
|
try {
|
||||||
showOffline = localStorage.getItem(SHOW_OFFLINE_STORAGE_KEY) === '1';
|
showOffline = localStorage.getItem(SHOW_OFFLINE_STORAGE_KEY) === '1';
|
||||||
} catch (e) { /* 隐私模式下 localStorage 可能不可用 */ }
|
} catch (e) { /* 隐私模式下 localStorage 可能不可用 */ }
|
||||||
|
|
||||||
|
// 分组过滤器:只存浏览器偏好(localStorage),服务端无感知。
|
||||||
|
// 分组键用设备上报的 group 原值,空字符串代表"未分组";空数组 = 不过滤。
|
||||||
|
const GROUP_FILTER_STORAGE_KEY = 'deviceGroupFilter';
|
||||||
|
let selectedGroups = [];
|
||||||
|
try {
|
||||||
|
const savedGroups = JSON.parse(localStorage.getItem(GROUP_FILTER_STORAGE_KEY) || '[]');
|
||||||
|
if (Array.isArray(savedGroups)) {
|
||||||
|
selectedGroups = savedGroups.filter(g => typeof g === 'string');
|
||||||
|
}
|
||||||
|
} catch (e) { /* 隐私模式 / 脏数据:退回"全部" */ }
|
||||||
|
let groupDropdownOpen = false;
|
||||||
let wall = {
|
let wall = {
|
||||||
active: false,
|
active: false,
|
||||||
layout: isTouchDevice ? 4 : 9,
|
layout: isTouchDevice ? 4 : 9,
|
||||||
@@ -2647,6 +2794,10 @@
|
|||||||
ws.onclose = () => {
|
ws.onclose = () => {
|
||||||
stopPingInterval();
|
stopPingInterval();
|
||||||
updateWsStatus('disconnected');
|
updateWsStatus('disconnected');
|
||||||
|
// 连接已断,补发 keyup 已不可能。把此刻仍按着的键移到 stale 集合,
|
||||||
|
// 重连并确认屏幕恢复后再补发;直接清空会使断线期间抬起的键永远
|
||||||
|
// 留在远程按下状态。
|
||||||
|
stashRemoteKeys();
|
||||||
stopAllAudio();
|
stopAllAudio();
|
||||||
audioFormat = null;
|
audioFormat = null;
|
||||||
// WS 断开:关闭所有墙解码器释放 GPU 资源,保留 tile 布局。
|
// WS 断开:关闭所有墙解码器释放 GPU 资源,保留 tile 布局。
|
||||||
@@ -2759,6 +2910,9 @@
|
|||||||
if (msg.ok) {
|
if (msg.ok) {
|
||||||
// Resolution may not be available yet (first connection)
|
// Resolution may not be available yet (first connection)
|
||||||
if (msg.width && msg.height) {
|
if (msg.width && msg.height) {
|
||||||
|
// 屏幕会话已确认在线(缓存会话),先补发断线期间遗留
|
||||||
|
// 的 keyup,再进入正常控制。
|
||||||
|
releaseStaleRemoteKeys();
|
||||||
updateScreenStatus('connected');
|
updateScreenStatus('connected');
|
||||||
isTopDown = msg.top_down === true;
|
isTopDown = msg.top_down === true;
|
||||||
isAndroidRemote = msg.client_type === 'APK';
|
isAndroidRemote = msg.client_type === 'APK';
|
||||||
@@ -2853,6 +3007,9 @@
|
|||||||
if (!isFocus) break;
|
if (!isFocus) break;
|
||||||
|
|
||||||
updateScreenStatus('connected');
|
updateScreenStatus('connected');
|
||||||
|
// 冷启动重连时 connect_result 还没有尺寸,等这里(TOKEN_BITMAPINFO
|
||||||
|
// 已到、屏幕子连接已绑定)再补发断线前遗留的 keyup。
|
||||||
|
releaseStaleRemoteKeys();
|
||||||
isTopDown = msg.top_down === true;
|
isTopDown = msg.top_down === true;
|
||||||
if (msg.client_type !== undefined) {
|
if (msg.client_type !== undefined) {
|
||||||
isAndroidRemote = msg.client_type === 'APK';
|
isAndroidRemote = msg.client_type === 'APK';
|
||||||
@@ -4366,6 +4523,171 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function groupKeyOf(d) { return d.group || ''; }
|
||||||
|
|
||||||
|
function groupLabel(key) { return key === '' ? 'Ungrouped' : key; }
|
||||||
|
|
||||||
|
// 分组清单按当前范围推导(未勾选 Offline 时只看在线设备),再并上
|
||||||
|
// 已选分组:设备掉线/分组暂时消失时,已选中的 chip 仍然可见、可取消,
|
||||||
|
// 不会把用户的过滤选择悄悄抹掉。命名分组在前,未分组垫底。
|
||||||
|
function groupKeys() {
|
||||||
|
const set = new Set();
|
||||||
|
for (const d of scopeDevices()) set.add(groupKeyOf(d));
|
||||||
|
for (const g of selectedGroups) set.add(g);
|
||||||
|
return Array.from(set).sort((a, b) => {
|
||||||
|
if (a === b) return 0;
|
||||||
|
if (a === '') return 1;
|
||||||
|
if (b === '') return -1;
|
||||||
|
return a.localeCompare(b);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function groupCounts() {
|
||||||
|
const counts = new Map();
|
||||||
|
for (const d of scopeDevices()) {
|
||||||
|
const k = groupKeyOf(d);
|
||||||
|
counts.set(k, (counts.get(k) || 0) + 1);
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveGroupFilter() {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(GROUP_FILTER_STORAGE_KEY, JSON.stringify(selectedGroups));
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeAttr(text) {
|
||||||
|
return escapeHtml(text).replace(/"/g, '"').replace(/'/g, ''');
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderGroupChips(keys, counts, sel) {
|
||||||
|
return '<span class="group-filter-label">Groups:</span>' + keys.map(k => {
|
||||||
|
const active = sel.has(k);
|
||||||
|
return '<button type="button" class="group-chip' + (active ? ' active' : '') + '"' +
|
||||||
|
' data-group="' + escapeAttr(k) + '"' +
|
||||||
|
' title="' + escapeAttr(groupLabel(k)) + '">' +
|
||||||
|
'<span class="group-chip-name">' + escapeHtml(groupLabel(k)) + '</span>' +
|
||||||
|
'<span class="group-chip-count">' + (counts.get(k) || 0) + '</span>' +
|
||||||
|
'</button>';
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderGroupDropdown(keys, counts, sel) {
|
||||||
|
let title;
|
||||||
|
if (!selectedGroups.length) title = 'All groups';
|
||||||
|
else if (selectedGroups.length === 1) title = groupLabel(selectedGroups[0]);
|
||||||
|
else title = selectedGroups.length + ' groups';
|
||||||
|
|
||||||
|
let html = '<div class="group-dd">' +
|
||||||
|
'<button type="button" class="group-dd-btn' + (selectedGroups.length ? ' active' : '') + '"' +
|
||||||
|
' data-dd-toggle="1" aria-haspopup="true" aria-expanded="' + (groupDropdownOpen ? 'true' : 'false') + '">' +
|
||||||
|
'<span class="group-dd-title">' + escapeHtml(title) + '</span>' +
|
||||||
|
'<span class="group-dd-caret">▾</span>' +
|
||||||
|
'</button>';
|
||||||
|
if (groupDropdownOpen) {
|
||||||
|
html += '<div class="group-dd-panel">' + keys.map(k => {
|
||||||
|
const active = sel.has(k);
|
||||||
|
return '<button type="button" class="group-dd-item' + (active ? ' active' : '') + '"' +
|
||||||
|
' data-group="' + escapeAttr(k) + '">' +
|
||||||
|
'<span class="group-dd-check">' + (active ? '✓' : '') + '</span>' +
|
||||||
|
'<span class="group-dd-name">' + escapeHtml(groupLabel(k)) + '</span>' +
|
||||||
|
'<span class="group-dd-count">' + (counts.get(k) || 0) + '</span>' +
|
||||||
|
'</button>';
|
||||||
|
}).join('') +
|
||||||
|
'<div class="group-dd-footer">' +
|
||||||
|
'<button type="button" class="group-dd-clear" data-group-clear="1"' +
|
||||||
|
(selectedGroups.length ? '' : ' disabled') + '>Clear</button>' +
|
||||||
|
'<button type="button" class="group-dd-done" data-dd-toggle="1">Done</button>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
return html + '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 内容没变就不重建 DOM:搜索框每敲一个字都会走到这里,重建会丢掉
|
||||||
|
// 分组按钮上的键盘焦点,也白白重排一遍。
|
||||||
|
let groupFilterHtml = null;
|
||||||
|
|
||||||
|
function renderGroupFilter() {
|
||||||
|
const el = document.getElementById('group-filter');
|
||||||
|
if (!el) return;
|
||||||
|
const keys = groupKeys();
|
||||||
|
// 没有设备,或只有"未分组"一类且没有已选分组时,过滤器没有意义。
|
||||||
|
if (!devices.length || keys.length === 0 || (keys.length === 1 && keys[0] === '')) {
|
||||||
|
el.style.display = 'none';
|
||||||
|
if (groupFilterHtml !== null) {
|
||||||
|
el.innerHTML = '';
|
||||||
|
groupFilterHtml = null;
|
||||||
|
}
|
||||||
|
groupDropdownOpen = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
el.style.display = '';
|
||||||
|
const counts = groupCounts();
|
||||||
|
const sel = new Set(selectedGroups);
|
||||||
|
const html = isTouchDevice
|
||||||
|
? renderGroupDropdown(keys, counts, sel)
|
||||||
|
: renderGroupChips(keys, counts, sel);
|
||||||
|
if (html !== groupFilterHtml) {
|
||||||
|
el.innerHTML = html;
|
||||||
|
groupFilterHtml = html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onGroupFilterClick(e) {
|
||||||
|
if (e.target.closest('[data-dd-toggle]')) {
|
||||||
|
// 阻止冒泡:重渲染会让 e.target 脱离文档,document 上的
|
||||||
|
// "点外面关闭"监听会误判为外部点击。
|
||||||
|
e.stopPropagation();
|
||||||
|
groupDropdownOpen = !groupDropdownOpen;
|
||||||
|
renderGroupFilter();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.target.closest('[data-group-clear]')) {
|
||||||
|
e.stopPropagation();
|
||||||
|
clearGroupFilter();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const item = e.target.closest('[data-group]');
|
||||||
|
if (!item) return;
|
||||||
|
e.stopPropagation();
|
||||||
|
toggleGroup(item.getAttribute('data-group'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleGroup(key) {
|
||||||
|
const hadFocus = !!(document.activeElement && document.activeElement.closest('#group-filter'));
|
||||||
|
const i = selectedGroups.indexOf(key);
|
||||||
|
if (i >= 0) selectedGroups.splice(i, 1);
|
||||||
|
else selectedGroups.push(key);
|
||||||
|
saveGroupFilter();
|
||||||
|
currentPage = 1;
|
||||||
|
renderDeviceList();
|
||||||
|
// 重渲染换掉了按钮节点:把键盘焦点还给同一个分组。
|
||||||
|
if (hadFocus) {
|
||||||
|
const btn = Array.from(document.querySelectorAll('#group-filter [data-group]'))
|
||||||
|
.find(b => b.getAttribute('data-group') === key);
|
||||||
|
if (btn) btn.focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearGroupFilter() {
|
||||||
|
if (!selectedGroups.length) return;
|
||||||
|
selectedGroups = [];
|
||||||
|
saveGroupFilter();
|
||||||
|
currentPage = 1;
|
||||||
|
renderDeviceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('group-filter').addEventListener('click', onGroupFilterClick);
|
||||||
|
// 手机端下拉:点面板外任意位置收起(面板内点击已被上面的处理器 stopPropagation)。
|
||||||
|
document.addEventListener('click', (e) => {
|
||||||
|
if (!groupDropdownOpen) return;
|
||||||
|
if (e.target.closest('#group-filter')) return;
|
||||||
|
groupDropdownOpen = false;
|
||||||
|
renderGroupFilter();
|
||||||
|
});
|
||||||
|
|
||||||
function scopeDevices() {
|
function scopeDevices() {
|
||||||
// Total / Showing 都基于当前范围:未勾选 Offline 时只统计在线设备。
|
// Total / Showing 都基于当前范围:未勾选 Offline 时只统计在线设备。
|
||||||
if (showOffline) return devices;
|
if (showOffline) return devices;
|
||||||
@@ -4374,6 +4696,10 @@
|
|||||||
|
|
||||||
function getFilteredDevices() {
|
function getFilteredDevices() {
|
||||||
let filtered = scopeDevices();
|
let filtered = scopeDevices();
|
||||||
|
if (selectedGroups.length) {
|
||||||
|
const sel = new Set(selectedGroups);
|
||||||
|
filtered = filtered.filter(d => sel.has(groupKeyOf(d)));
|
||||||
|
}
|
||||||
if (searchQuery) {
|
if (searchQuery) {
|
||||||
const q = searchQuery.toLowerCase();
|
const q = searchQuery.toLowerCase();
|
||||||
filtered = filtered.filter(d =>
|
filtered = filtered.filter(d =>
|
||||||
@@ -4511,6 +4837,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderDeviceList() {
|
function renderDeviceList() {
|
||||||
|
renderGroupFilter();
|
||||||
const filtered = getFilteredDevices();
|
const filtered = getFilteredDevices();
|
||||||
const ps = getPageSize();
|
const ps = getPageSize();
|
||||||
const totalPages = Math.ceil(filtered.length / ps) || 1;
|
const totalPages = Math.ceil(filtered.length / ps) || 1;
|
||||||
@@ -4520,7 +4847,7 @@
|
|||||||
const pageDevices = filtered.slice(start, start + ps);
|
const pageDevices = filtered.slice(start, start + ps);
|
||||||
|
|
||||||
// Update stats. Total is the current scope (online-only unless the
|
// Update stats. Total is the current scope (online-only unless the
|
||||||
// Offline toggle is on); Showing is after the search filter.
|
// Offline toggle is on); Showing is after the group + search filters.
|
||||||
const scope = scopeDevices();
|
const scope = scopeDevices();
|
||||||
document.getElementById('device-count').textContent = scope.length;
|
document.getElementById('device-count').textContent = scope.length;
|
||||||
document.getElementById('stat-total').textContent = scope.length;
|
document.getElementById('stat-total').textContent = scope.length;
|
||||||
@@ -4630,6 +4957,8 @@
|
|||||||
if (pageId !== 'screen-page') {
|
if (pageId !== 'screen-page') {
|
||||||
const sp = document.getElementById('screen-page');
|
const sp = document.getElementById('screen-page');
|
||||||
if (sp && sp.classList.contains('active')) {
|
if (sp && sp.classList.contains('active')) {
|
||||||
|
// 离开远程页面:远程随后的 keyup 不会再到达,补发按着的键。
|
||||||
|
releaseRemoteKeys();
|
||||||
if (document.fullscreenElement || document.webkitFullscreenElement) {
|
if (document.fullscreenElement || document.webkitFullscreenElement) {
|
||||||
const exit = document.exitFullscreen || document.webkitExitFullscreen;
|
const exit = document.exitFullscreen || document.webkitExitFullscreen;
|
||||||
if (exit) exit.call(document).catch(() => {});
|
if (exit) exit.call(document).catch(() => {});
|
||||||
@@ -4708,6 +5037,8 @@
|
|||||||
}
|
}
|
||||||
function confirmLogout() {
|
function confirmLogout() {
|
||||||
document.getElementById('logout-confirm-modal').classList.remove('active');
|
document.getElementById('logout-confirm-modal').classList.remove('active');
|
||||||
|
// 立即断开前先补发 keyup(socket 一关就没机会了)。
|
||||||
|
releaseRemoteKeys();
|
||||||
// 彻底清理屏幕墙(tile/session/订阅引用)并清除持久化布局。
|
// 彻底清理屏幕墙(tile/session/订阅引用)并清除持久化布局。
|
||||||
wallTeardown(true);
|
wallTeardown(true);
|
||||||
// Close and reconnect WebSocket to get new challenge
|
// Close and reconnect WebSocket to get new challenge
|
||||||
@@ -4721,6 +5052,10 @@
|
|||||||
currentUserRole = 'viewer';
|
currentUserRole = 'viewer';
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
localStorage.removeItem('role');
|
localStorage.removeItem('role');
|
||||||
|
// 分组过滤器是按账号的临时偏好:换账号不应继承上一个账号的选择。
|
||||||
|
selectedGroups = [];
|
||||||
|
groupDropdownOpen = false;
|
||||||
|
saveGroupFilter();
|
||||||
devices = [];
|
devices = [];
|
||||||
showPage('login-page');
|
showPage('login-page');
|
||||||
// Hide admin-only buttons
|
// Hide admin-only buttons
|
||||||
@@ -4742,6 +5077,9 @@
|
|||||||
let appDialogResolve = null;
|
let appDialogResolve = null;
|
||||||
|
|
||||||
function openAppDialog(opts) {
|
function openAppDialog(opts) {
|
||||||
|
// 弹窗抢走键盘焦点,之后收不到 keyup;先把远程按着的键补发。
|
||||||
|
// socket 已断时保留 stale,等重连确认屏幕后补发。
|
||||||
|
releaseRemoteKeysIfOnline();
|
||||||
// A pending dialog is superseded (e.g. an async error arrives while
|
// A pending dialog is superseded (e.g. an async error arrives while
|
||||||
// a confirm is open): resolve it as cancelled so no caller hangs.
|
// a confirm is open): resolve it as cancelled so no caller hangs.
|
||||||
if (appDialogResolve) {
|
if (appDialogResolve) {
|
||||||
@@ -5155,6 +5493,7 @@
|
|||||||
const sid = String(id);
|
const sid = String(id);
|
||||||
// 同页直接切设备(正常 UI 不会发生):先释放旧 focus 引用。
|
// 同页直接切设备(正常 UI 不会发生):先释放旧 focus 引用。
|
||||||
if (currentDevice && String(currentDevice.id) !== sid) {
|
if (currentDevice && String(currentDevice.id) !== sid) {
|
||||||
|
releaseRemoteKeys(); // 旧设备上按着的键要在换设备前补发抬起
|
||||||
releaseStream(currentDevice.id, 'focus');
|
releaseStream(currentDevice.id, 'focus');
|
||||||
}
|
}
|
||||||
currentDevice = dev;
|
currentDevice = dev;
|
||||||
@@ -5405,6 +5744,104 @@
|
|||||||
// Control mode state (mouse/keyboard control)
|
// Control mode state (mouse/keyboard control)
|
||||||
let controlEnabled = false;
|
let controlEnabled = false;
|
||||||
|
|
||||||
|
// ===== 远程按键状态跟踪 =====
|
||||||
|
// 浏览器并不保证每个 keydown 都有对应的 keyup 送到页面:切窗口/切标签、
|
||||||
|
// 地址栏或查找栏抢走焦点、浏览器快捷键(Ctrl+T/W/F)、断线时都会丢。
|
||||||
|
// 丢掉一个 Ctrl 的 keyup,远程就"一直按着 Ctrl",表现为打字结果全成了
|
||||||
|
// 组合键——再按一下 Ctrl 才恢复。这里记下已经下发的按下键,在失焦/断开/
|
||||||
|
// 关闭控制时补发 keyup;下一次按键或点击时再按事件里的修饰键状态校正一次。
|
||||||
|
const remoteDownKeys = new Set();
|
||||||
|
// 断线(ws.onclose)那一刻仍按着的键:socket 已经关了,补发不出去,只能
|
||||||
|
// 先搬到一边;重连并确认屏幕恢复(connect_result 带尺寸 / 收到
|
||||||
|
// resolution_changed)后再补发 keyup,否则断线期间抬起的键会一直按在远程。
|
||||||
|
const staleRemoteKeys = new Set();
|
||||||
|
let staleRemoteKeysDevice = undefined; // stale 键属于哪台设备
|
||||||
|
const MODIFIER_KEYS = [[16, 'shiftKey'], [17, 'ctrlKey'], [18, 'altKey']];
|
||||||
|
|
||||||
|
function isModifierKey(keyCode) {
|
||||||
|
return keyCode === 16 || keyCode === 17 || keyCode === 18;
|
||||||
|
}
|
||||||
|
|
||||||
|
function trackRemoteKey(keyCode, isDown) {
|
||||||
|
if (isDown) remoteDownKeys.add(keyCode);
|
||||||
|
else remoteDownKeys.delete(keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 补发一组 keyup(先普通键,再修饰键)。
|
||||||
|
function sendRemoteKeyups(keys) {
|
||||||
|
if (!keys.length) return;
|
||||||
|
keys.sort((a, b) => (isModifierKey(a) ? 1 : 0) - (isModifierKey(b) ? 1 : 0));
|
||||||
|
for (const keyCode of keys) {
|
||||||
|
// 不走 sendKey:关闭控制/离开页面时 controlEnabled 已是 false,
|
||||||
|
// 但补发的 keyup 仍必须发出去(ws 已关则由 sendKeyRaw 丢弃)。
|
||||||
|
sendKeyRaw(keyCode, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 补发所有未收到 keyup 的按键,并清空跟踪集合。断线前遗留的键一并补发。
|
||||||
|
function releaseRemoteKeys() {
|
||||||
|
// 遗留的键只有在还是同一台设备时才补发:切到别的设备上补发会把用户
|
||||||
|
// 正按着的修饰键误松开。
|
||||||
|
const dev = currentDeviceId();
|
||||||
|
if (staleRemoteKeys.size && dev !== undefined &&
|
||||||
|
String(dev) === String(staleRemoteKeysDevice)) {
|
||||||
|
for (const keyCode of staleRemoteKeys) remoteDownKeys.add(keyCode);
|
||||||
|
}
|
||||||
|
staleRemoteKeys.clear();
|
||||||
|
staleRemoteKeysDevice = undefined;
|
||||||
|
if (!remoteDownKeys.size) return;
|
||||||
|
const keys = Array.from(remoteDownKeys);
|
||||||
|
remoteDownKeys.clear();
|
||||||
|
sendRemoteKeyups(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只补发断线前遗留的键,不动重连后新按下的键(那些可能还真的按着)。
|
||||||
|
function releaseStaleRemoteKeys() {
|
||||||
|
if (!staleRemoteKeys.size) return;
|
||||||
|
const dev = currentDeviceId();
|
||||||
|
const sameDevice = dev !== undefined &&
|
||||||
|
String(dev) === String(staleRemoteKeysDevice);
|
||||||
|
const keys = Array.from(staleRemoteKeys);
|
||||||
|
staleRemoteKeys.clear();
|
||||||
|
staleRemoteKeysDevice = undefined;
|
||||||
|
if (!sameDevice) return; // 已经不在那台设备上了:不能发给别人
|
||||||
|
sendRemoteKeyups(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
// socket 已断时补发不出去:这时保留 stale,等重连确认屏幕恢复后再补发。
|
||||||
|
function releaseRemoteKeysIfOnline() {
|
||||||
|
if (!ws || ws.readyState !== WebSocket.OPEN) return;
|
||||||
|
releaseRemoteKeys();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 断线瞬间把仍在按着的键挪到 stale 集合(socket 已关,补发不出去)。
|
||||||
|
function stashRemoteKeys() {
|
||||||
|
skipNextCtrlVKeyup = false; // V 的物理 keyup 也收不到了,标记作废
|
||||||
|
if (!remoteDownKeys.size) return;
|
||||||
|
const dev = currentDeviceId();
|
||||||
|
if (dev === undefined) {
|
||||||
|
remoteDownKeys.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (staleRemoteKeys.size && String(staleRemoteKeysDevice) !== String(dev)) {
|
||||||
|
staleRemoteKeys.clear(); // 上一台设备遗留的键已无处可补
|
||||||
|
}
|
||||||
|
for (const keyCode of remoteDownKeys) staleRemoteKeys.add(keyCode);
|
||||||
|
remoteDownKeys.clear();
|
||||||
|
staleRemoteKeysDevice = dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 浏览器事件里的修饰键状态才是真实状态。若远程还按着、事件却说已经松开,
|
||||||
|
// 说明对应的 keyup 丢了,就地补发,不必再让用户按一次 Ctrl 才恢复。
|
||||||
|
function releaseStaleModifiers(e) {
|
||||||
|
if (!controlEnabled) return;
|
||||||
|
for (const [keyCode, flag] of MODIFIER_KEYS) {
|
||||||
|
if (remoteDownKeys.has(keyCode) && !e[flag]) {
|
||||||
|
sendKeyRaw(keyCode, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remote cursor mapping (Windows cursor index -> CSS cursor)
|
// Remote cursor mapping (Windows cursor index -> CSS cursor)
|
||||||
// Index matches CursorInfo.h: IDC_APPSTARTING(0) to IDC_WAIT(15), 254=custom, 255=unsupported
|
// Index matches CursorInfo.h: IDC_APPSTARTING(0) to IDC_WAIT(15), 254=custom, 255=unsupported
|
||||||
// Custom I-beam cursor with white fill and black stroke for visibility on any background
|
// Custom I-beam cursor with white fill and black stroke for visibility on any background
|
||||||
@@ -5797,6 +6234,9 @@
|
|||||||
|
|
||||||
function toggleControl() {
|
function toggleControl() {
|
||||||
controlEnabled = !controlEnabled;
|
controlEnabled = !controlEnabled;
|
||||||
|
// 关闭控制:远程之后收不到任何 keyup,按着的 Ctrl/Shift/Alt 必须现在补发,
|
||||||
|
// 否则就会"打字很怪、再按一下 Ctrl 才好"。socket 已断时保留下来等重连补发。
|
||||||
|
if (!controlEnabled) releaseRemoteKeysIfOnline();
|
||||||
// Update floating toolbar buttons
|
// Update floating toolbar buttons
|
||||||
const btnMouse = document.getElementById('btn-mouse');
|
const btnMouse = document.getElementById('btn-mouse');
|
||||||
btnMouse.classList.toggle('active', controlEnabled);
|
btnMouse.classList.toggle('active', controlEnabled);
|
||||||
@@ -6155,9 +6595,15 @@
|
|||||||
if (!controlEnabled) return; // Control mode required
|
if (!controlEnabled) return; // Control mode required
|
||||||
// Filter Windows keys (handled locally, not sent to remote)
|
// Filter Windows keys (handled locally, not sent to remote)
|
||||||
if (keyCode === 91 || keyCode === 92) return; // VK_LWIN, VK_RWIN
|
if (keyCode === 91 || keyCode === 92) return; // VK_LWIN, VK_RWIN
|
||||||
|
if (sendKeyPacket(keyCode, isDown, altKey)) trackRemoteKey(keyCode, isDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendKeyPacket(keyCode, isDown, altKey) {
|
||||||
if (ws && ws.readyState === WebSocket.OPEN && token) {
|
if (ws && ws.readyState === WebSocket.OPEN && token) {
|
||||||
ws.send(JSON.stringify({ cmd: 'key', token, id: currentDeviceId(), keyCode, down: isDown, alt: !!altKey }));
|
ws.send(JSON.stringify({ cmd: 'key', token, id: currentDeviceId(), keyCode, down: isDown, alt: !!altKey }));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 本地剪贴板 → 远程:读浏览器剪贴板,先 clipboard_set 到远程,再合成一次完整 Ctrl+V。
|
// 本地剪贴板 → 远程:读浏览器剪贴板,先 clipboard_set 到远程,再合成一次完整 Ctrl+V。
|
||||||
@@ -6185,9 +6631,7 @@
|
|||||||
// 直接注入单个按键到远程(不经过 sendKey 的 controlEnabled 门槛)。
|
// 直接注入单个按键到远程(不经过 sendKey 的 controlEnabled 门槛)。
|
||||||
// "I" 组合框和 1/2/3…/中 同属输入辅助栏,不应要求先开鼠标控制。
|
// "I" 组合框和 1/2/3…/中 同属输入辅助栏,不应要求先开鼠标控制。
|
||||||
function sendKeyRaw(keyCode, isDown) {
|
function sendKeyRaw(keyCode, isDown) {
|
||||||
if (ws && ws.readyState === WebSocket.OPEN && token) {
|
if (sendKeyPacket(keyCode, isDown, false)) trackRemoteKey(keyCode, isDown);
|
||||||
ws.send(JSON.stringify({ cmd: 'key', token, id: currentDeviceId(), keyCode, down: isDown, alt: false }));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// "I" 手机输入法组合框:一次性把文本经剪贴板桥发到远程光标处。
|
// "I" 手机输入法组合框:一次性把文本经剪贴板桥发到远程光标处。
|
||||||
@@ -6869,6 +7313,7 @@
|
|||||||
|
|
||||||
canvas.addEventListener('mousedown', function(e) {
|
canvas.addEventListener('mousedown', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
releaseStaleModifiers(e);
|
||||||
const pos = getMousePos(e);
|
const pos = getMousePos(e);
|
||||||
sendMouse('down', pos.x, pos.y, e.button);
|
sendMouse('down', pos.x, pos.y, e.button);
|
||||||
});
|
});
|
||||||
@@ -6905,6 +7350,7 @@
|
|||||||
|
|
||||||
canvas.addEventListener('wheel', function(e) {
|
canvas.addEventListener('wheel', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
releaseStaleModifiers(e);
|
||||||
const pos = getMousePos(e);
|
const pos = getMousePos(e);
|
||||||
sendMouse('wheel', pos.x, pos.y, 0, e.deltaY, e.deltaMode);
|
sendMouse('wheel', pos.x, pos.y, 0, e.deltaY, e.deltaMode);
|
||||||
}, { passive: false });
|
}, { passive: false });
|
||||||
@@ -6916,6 +7362,12 @@
|
|||||||
if (!document.getElementById('screen-page').classList.contains('active')) return;
|
if (!document.getElementById('screen-page').classList.contains('active')) return;
|
||||||
// Keys belong to an open in-app dialog (buttons are not INPUT/TEXTAREA).
|
// Keys belong to an open in-app dialog (buttons are not INPUT/TEXTAREA).
|
||||||
if (document.getElementById('app-dialog').classList.contains('active')) return;
|
if (document.getElementById('app-dialog').classList.contains('active')) return;
|
||||||
|
|
||||||
|
// 上一次的 keyup 可能被浏览器吞掉了:按事件里的真实修饰键状态先校正。
|
||||||
|
// 必须放在输入框判断之前——失焦丢 keyup 后点进输入框继续打字时,
|
||||||
|
// keydown 会提前 return,校正就永远不生效。
|
||||||
|
releaseStaleModifiers(e);
|
||||||
|
|
||||||
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
|
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
|
||||||
// F11 belongs to the local fullscreen toggle UNLESS we're actively
|
// F11 belongs to the local fullscreen toggle UNLESS we're actively
|
||||||
// controlling the remote — see the F11 handler above. Skip here
|
// controlling the remote — see the F11 handler above. Skip here
|
||||||
@@ -6945,8 +7397,15 @@
|
|||||||
|
|
||||||
document.addEventListener('keyup', function(e) {
|
document.addEventListener('keyup', function(e) {
|
||||||
if (!document.getElementById('screen-page').classList.contains('active')) return;
|
if (!document.getElementById('screen-page').classList.contains('active')) return;
|
||||||
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
|
|
||||||
if (e.key === 'F11' && !controlEnabled) return;
|
if (e.key === 'F11' && !controlEnabled) return;
|
||||||
|
// 焦点跑到输入框时本地按键不再转发;但按住时在画布按下的键,它的
|
||||||
|
// keyup 必须补发,否则远程一直按着(典型:按住 Ctrl 再点输入框)。
|
||||||
|
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
|
||||||
|
// Ctrl+V 桥的抑制标记若在这里错过,会一直留着吞掉下一次 V 的抬起。
|
||||||
|
if (e.keyCode === 86 && skipNextCtrlVKeyup) skipNextCtrlVKeyup = false;
|
||||||
|
if (remoteDownKeys.has(e.keyCode)) sendKeyRaw(e.keyCode, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 由 pasteToRemote 合成的完整 Ctrl+V 按下:物理 keyup 不再转发,避免 down/up 乱序
|
// 由 pasteToRemote 合成的完整 Ctrl+V 按下:物理 keyup 不再转发,避免 down/up 乱序
|
||||||
if (e.keyCode === 86 && skipNextCtrlVKeyup) {
|
if (e.keyCode === 86 && skipNextCtrlVKeyup) {
|
||||||
skipNextCtrlVKeyup = false;
|
skipNextCtrlVKeyup = false;
|
||||||
@@ -6957,6 +7416,26 @@
|
|||||||
sendKey(e.keyCode, false, e.altKey);
|
sendKey(e.keyCode, false, e.altKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 失焦(切窗口、点地址栏/查找栏、开开发者工具)或标签页隐藏/关闭时,
|
||||||
|
// 浏览器不再派发 keyup;不补发的话远程会一直按着最后按下的修饰键。
|
||||||
|
// 此时如果 socket 已断则补发不出去:保留 stale 等重连后再补。
|
||||||
|
window.addEventListener('blur', function() {
|
||||||
|
// 物理 keyup 不会再来,Ctrl+V 桥的一次性标记也作废,否则会吞掉
|
||||||
|
// 重连后下一次 V 的抬起,远程 V 一直按下。
|
||||||
|
skipNextCtrlVKeyup = false;
|
||||||
|
if (controlEnabled) releaseRemoteKeysIfOnline();
|
||||||
|
});
|
||||||
|
document.addEventListener('visibilitychange', function() {
|
||||||
|
if (document.hidden) {
|
||||||
|
skipNextCtrlVKeyup = false;
|
||||||
|
releaseRemoteKeysIfOnline();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener('pagehide', function() {
|
||||||
|
skipNextCtrlVKeyup = false;
|
||||||
|
releaseRemoteKeysIfOnline();
|
||||||
|
});
|
||||||
|
|
||||||
// 字符 → Win32 VK 映射表(提到 listener 外避免每次输入重建)。
|
// 字符 → Win32 VK 映射表(提到 listener 外避免每次输入重建)。
|
||||||
// US 键盘上"不需要 Shift"的 OEM 符号 ASCII 码 ≠ VK 码,必须显式映射。
|
// US 键盘上"不需要 Shift"的 OEM 符号 ASCII 码 ≠ VK 码,必须显式映射。
|
||||||
const SHIFT_SYMBOLS = '~!@#$%^&*()_+{}|:"<>?';
|
const SHIFT_SYMBOLS = '~!@#$%^&*()_+{}|:"<>?';
|
||||||
@@ -7006,6 +7485,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function disconnect() {
|
function disconnect() {
|
||||||
|
// 先把还在"按下"状态的键补发 keyup:断开后远程再也收不到 keyup,
|
||||||
|
// 修饰键会一直按着(ws/currentDevice 必须还活着,故放在最前面)。
|
||||||
|
releaseRemoteKeys();
|
||||||
|
skipNextCtrlVKeyup = false; // 会话级标记,不能跨设备残留
|
||||||
// Reset throughput / resolution read-outs
|
// Reset throughput / resolution read-outs
|
||||||
currentWidth = 0; currentHeight = 0;
|
currentWidth = 0; currentHeight = 0;
|
||||||
bwBytesAccum = 0; bwBytesPerSec = 0;
|
bwBytesAccum = 0; bwBytesPerSec = 0;
|
||||||
@@ -7226,9 +7709,9 @@
|
|||||||
// Input shortcut buttons event handlers
|
// Input shortcut buttons event handlers
|
||||||
// Shortcuts only visible when keyboard is open, so no extra check needed
|
// Shortcuts only visible when keyboard is open, so no extra check needed
|
||||||
function sendShortcutKey(keyCode, isDown) {
|
function sendShortcutKey(keyCode, isDown) {
|
||||||
if (ws && ws.readyState === WebSocket.OPEN && token) {
|
// 与输入辅助栏同一条通道:统一走 sendKeyRaw(含按下状态跟踪);
|
||||||
ws.send(JSON.stringify({ cmd: 'key', token, id: currentDeviceId(), keyCode, down: isDown, alt: false }));
|
// 成对发出,正常不会留下未抬起的键。
|
||||||
}
|
sendKeyRaw(keyCode, isDown);
|
||||||
}
|
}
|
||||||
const shortcutBtns = document.querySelectorAll('.shortcut-btn');
|
const shortcutBtns = document.querySelectorAll('.shortcut-btn');
|
||||||
shortcutBtns.forEach(function(btn) {
|
shortcutBtns.forEach(function(btn) {
|
||||||
|
|||||||
Reference in new issue
Block a user