mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4df95ea271 | ||
|
|
be7dba4669 | ||
|
|
61dfb2edf5 | ||
|
|
d4483e2bbd | ||
|
|
0de74566a9 | ||
|
|
edee53a022 | ||
|
|
fd3caf0d15 | ||
|
|
ce7906510f |
No files matched your search
@@ -106,6 +106,7 @@ viewer does not reconnect them automatically.
|
||||
| `~/.config/uuremote/host_settings.json` | persisted 安全 settings: auto_lock, keep_mute, mute_permanent |
|
||||
| `UU_DESKTOP_BACKEND` | `auto` (default) / `x11` / `wayland` / `portal` / `kms` (experimental feature) / `none` (headless: no display; desktop offers ignored; tool peers get a nominal 1920x1080 screen + Allow permissions, which the port-mapping viewer requires) |
|
||||
| `UU_INPUT_BACKEND` | `auto` (uinput on Wayland/portal when `/dev/uinput` is accessible, udev `uaccess` rule in README) / `uinput` / `native`. X11 keeps XTest (held-key autorepeat handling) |
|
||||
| Mac viewer Cmd | With 「使用 macOS 快捷键」 off the Mac viewer sends Cmd=VK_LWIN 0x5B, Option=0xA4, Ctrl=0xA2; connect header `controller_platform`=4 is macOS. For Mac controllers Cmd is held back: Cmd+C/V/A/F/X/Z → Ctrl+key (terminal: Cmd+C/V → Ctrl+Shift+C/V), other combos/alone → Super |
|
||||
| `UU_TERMINAL_SHORTCUTS=0` | disable Ctrl+V → Ctrl+Shift+V in focused X11 terminals (Mac Cmd and Ctrl both arrive as VK_LCONTROL) |
|
||||
| `contrib/virtual-desktop/` | Xvfb + session (`UU_VIRTUAL_SESSION`, `UU_VIRTUAL_BUS=user|private`) for monitorless hosts; serve it with `DISPLAY=:99` |
|
||||
| `UU_VIDEO_ENCODER` | `cpu`: libx264; `vaapi`: explicit Intel/AMD; `nvenc`: force; unset: NVENC→CPU only if `/proc/driver/nvidia/version` or `/dev/nvidia0` exists, else CPU (#10) |
|
||||
|
||||
Generated
+1
-1
@@ -2649,7 +2649,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.1.11"
|
||||
version = "0.1.14"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.1.11"
|
||||
version = "0.1.14"
|
||||
edition = "2021"
|
||||
authors = ["uu-remote-linux contributors"]
|
||||
description = "Unofficial Linux host for NetEase UU Remote: control a Linux desktop from the official clients"
|
||||
|
||||
+5
-2
@@ -35,7 +35,7 @@
|
||||
| Remote assistance (experimental) | Like the official client: share the **device ID + verification code**; the other person enters them under 开始协助 in UU Remote. Works before sign-in (guest identity) and after; see below |
|
||||
| Remote desktop | H.264 video, NVENC hardware encoding on NVIDIA GPUs, libx264 otherwise; the viewer draws its local pointer, so there is no double cursor |
|
||||
| Mouse / keyboard | Absolute and relative motion, clicks, wheel, keys; no spurious key repeat on high-latency links; optional uinput virtual devices on Wayland (layout independent, see below) |
|
||||
| Terminal shortcuts | Mac viewers send both Cmd and Ctrl as Ctrl. In a focused terminal window Ctrl+V / Cmd+V become Ctrl+Shift+V (paste); Ctrl+C always interrupts, copy with Cmd+Shift+C (X11) |
|
||||
| Mac shortcuts | **Recommended**: turn off 「使用 macOS 快捷键」 (use macOS shortcuts) in the Mac viewer's remote-window menu; then Cmd+C/V/A/F/X/Z work as on a Mac (Cmd+C/V become Ctrl+Shift+C/V in terminals) and Ctrl+C always interrupts. With the option on, the viewer sends Cmd as Ctrl: in a terminal Ctrl+V / Cmd+V paste, Ctrl+C interrupts, copy is Cmd+Shift+C (X11) |
|
||||
| Pointer shape | Remote cursor shape is mirrored to the viewer (X11) |
|
||||
| Clipboard | Two-way text sync |
|
||||
| Quality / frame rate / resolution | Auto, Original 20M, Ultra 8M, HD 2M, custom; 30/60/90/144 fps; "other resolutions" are scaled by the encoder, the host monitor is left untouched |
|
||||
@@ -94,7 +94,7 @@ mapping and hardware acceleration remain unverified. This is not zero-copy VAAPI
|
||||
| Privacy screen on the host | Not implemented |
|
||||
| Microphone (viewer audio played on the host) | Not implemented (needs a virtual sound card) |
|
||||
| Plugins such as the WoW queue notifier | Not supported; the client is told that no plugins exist |
|
||||
| Access before login (greeter / no user logged in) | The greeter cannot be controlled; without a logged-in user use headless mode or a virtual desktop (see below) |
|
||||
| Linux login screen | The system login screen (before anyone logs in to the Linux desktop) cannot be controlled yet; use headless mode or a virtual desktop (see below). This is about the Linux login: **without a UU account** the host can now be used through remote assistance |
|
||||
| Relay connections on restrictive networks | Uses the ICE servers provided by the UU cloud; complex network setups are not thoroughly tested |
|
||||
| Acting as a viewer (controlling other machines from Linux) | Out of scope |
|
||||
|
||||
@@ -191,6 +191,9 @@ connect from 开始协助 (remote assistance) in UU Remote.
|
||||
- **Signed in**: the host is in your device list and remote assistance keeps working (same device ID). A background
|
||||
service keeps the window hidden; open it with `uuremote-server show` or the "UU Remote Linux Host" launcher.
|
||||
Closing the window only hides it.
|
||||
- **Tray icon**: a background host shows a tray icon with Open main window, the allow switch and Quit. GNOME needs
|
||||
the AppIndicator extension (bundled on Ubuntu); Xfce / Cinnamon / KDE work as is. Quit stops `uuremote-native.service`;
|
||||
the launcher starts it again.
|
||||
- **Settings** (as in the official client): allow switch (off by default); verification by temporary code, custom code
|
||||
(8–16 letters and digits) or either; temporary code rotation after each session / hourly / 12 h / 24 h / never;
|
||||
copy buttons for the ID and the code. Stored in the 0600 config.
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
| 远程协助(实验性) | 像官方客户端一样,把**设备 ID + 验证码**发给别人,对方在 UU「开始协助」里输入即可连接;登录前(访客身份)和登录后都能用,见下文 |
|
||||
| 远程桌面 | H.264 视频,NVIDIA 显卡用 NVENC 硬件编码,否则用 libx264;查看端绘制本地鼠标,不会出现双光标 |
|
||||
| 鼠标 / 键盘 | 绝对/相对移动、点击、滚轮、按键;修复了网络延迟导致的按键连发;Wayland 下可用 uinput 虚拟键鼠(不依赖键盘布局,见下文) |
|
||||
| 终端快捷键 | Mac 控制端的 Cmd 和 Ctrl 到被控端都是 Ctrl。焦点在终端窗口时,Ctrl+V / Cmd+V 自动转成 Ctrl+Shift+V 粘贴;Ctrl+C 始终是中断,复制请用 Cmd+Shift+C(X11) |
|
||||
| Mac 快捷键 | **推荐**:在 Mac 远控窗口菜单里关闭「使用 macOS 快捷键」,之后和在 Mac 上一样:Cmd+C/V/A/F/X/Z 是复制、粘贴、全选、查找、剪切、撤销(终端里 Cmd+C/V 自动变成 Ctrl+Shift+C/V),Ctrl+C 在终端里始终是中断。保持开启时,客户端会把 Cmd 和 Ctrl 都当成 Ctrl 发送:终端里 Ctrl+V / Cmd+V 自动转成粘贴,Ctrl+C 是中断,复制用 Cmd+Shift+C(X11) |
|
||||
| 鼠标指针样式 | 远端指针形状实时同步(X11) |
|
||||
| 剪贴板 | 双向文本同步 |
|
||||
| 画质 / 帧率 / 分辨率 | 自动、原画 20M、超清 8M、高清 2M、自定义;30/60/90/144 帧;「其他分辨率」由编码器缩放,不改动主机显示器 |
|
||||
@@ -80,7 +80,7 @@ Wayland 下的限制:只支持单屏、固定分辨率;Hyprland 原生后端
|
||||
| 被控端防窥模式 | 未实现 |
|
||||
| 麦克风(控制端声音传到被控端) | 未实现(需要虚拟声卡) |
|
||||
| 魔兽世界排队提醒等插件 | 不支持,会明确告诉客户端「无插件」 |
|
||||
| 登录前(登录界面 / 无人登录)访问 | 不支持控制登录界面;没有人登录时可以用无头模式或虚拟桌面(见下文) |
|
||||
| Linux 系统登录界面 | 还不支持控制开机后的系统登录界面(还没有人登录 Linux 桌面时);这种情况可以用无头模式或虚拟桌面(见下文)。注意:这里说的是 Linux 系统登录,**不登录 UU 账号**现在可以通过「远程协助」使用 |
|
||||
| 跨运营商 / 受限网络的中继连接 | 已接入官方下发的 ICE 服务器,但复杂网络环境未充分测试 |
|
||||
| 作为控制端(在 Linux 上控制别的电脑) | 不在本项目范围 |
|
||||
|
||||
@@ -171,6 +171,7 @@ X11 默认继续用 XTest,因为它能正确处理网络延迟下按住不放
|
||||
|
||||
- **未登录**:启动后直接显示主窗口,用访客身份提供远程协助,同时显示扫码登录二维码。扫码登录后自动切换到账号模式。
|
||||
- **已登录**:本机出现在你的设备列表里,可以直接连;远程协助也照常可用(同一设备 ID)。服务在后台运行时窗口默认隐藏,用 `uuremote-server show` 或应用菜单里的「UU 远程 Linux 主机」打开。关闭窗口只是隐藏,不会停止服务。
|
||||
- **托盘图标**:后台运行时顶栏/任务栏有托盘图标,菜单里可以「打开主窗口」、切换「允许他人远程协助」、「退出」。GNOME 需要 AppIndicator 扩展(Ubuntu 自带),Xfce / Cinnamon / KDE 直接可用。从托盘退出会停止 `uuremote-native.service`,之后从应用菜单打开会重新启动服务。
|
||||
- **设置**(与官方一致):「允许他人远程协助」开关(默认关闭);验证方式:仅临时验证码 / 仅自定义验证码(8–16 位,需同时包含字母和数字) / 两种都可以;临时验证码自动刷新:每次远控结束 / 每小时 / 每 12 小时 / 每 24 小时 / 不刷新;ID 和验证码旁各有「复制」按钮。设置保存在本机配置文件(0600)。
|
||||
- **只在本机窗口显示**:验证码不会写进日志。没有图形界面时,单独运行 `uuremote-server assist` 会在终端显示(`allow` / `deny` / `reset` / `mode …` / `refresh …` / `off`)。
|
||||
- **安全**:拿到 ID 和验证码的人可以完全控制这台电脑(桌面、文件、终端)。只发给信任的人,用完关掉开关或刷新验证码。
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <stdatomic.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
static const char *CSS =
|
||||
"window { background-color: #f5f6f8; }\n"
|
||||
@@ -27,7 +28,7 @@ static const char *CSS =
|
||||
".status.ok { color: #16a34a; }\n"
|
||||
".status.error { color: #dc2626; }\n";
|
||||
|
||||
enum { CMD_NONE = 0, CMD_ALLOW = 1, CMD_DENY = 2, CMD_RESET = 3, CMD_STOP = 4, CMD_VERIFY = 5, CMD_REFRESH = 6, CMD_CUSTOM = 7, CMD_LOGOUT = 8 };
|
||||
enum { CMD_NONE = 0, CMD_ALLOW = 1, CMD_DENY = 2, CMD_RESET = 3, CMD_STOP = 4, CMD_VERIFY = 5, CMD_REFRESH = 6, CMD_CUSTOM = 7, CMD_LOGOUT = 8, CMD_QUIT = 9 };
|
||||
enum { VERIFY_TEMPORARY = 0, VERIFY_CUSTOM = 1, VERIFY_BOTH = 2 };
|
||||
|
||||
typedef struct { char *id; char *code; int allowed, verify, refresh, has_custom; } State;
|
||||
@@ -47,6 +48,9 @@ static GtkWidget *refresh_items[5], *footer_label;
|
||||
// Account card: QR login before sign-in, user info (+ logout) after.
|
||||
static GtkWidget *assist_card, *account_card, *account_stack, *qr_stack, *qr_image, *login_status, *user_label;
|
||||
static int show_assist = 1, show_account;
|
||||
// Tray (host service only): AppIndicator via dlopen (no build dependency), else GtkStatusIcon.
|
||||
static GtkWidget *tray_menu, *tray_allow;
|
||||
static int suppress_tray;
|
||||
static int cur_verify, cur_refresh, cur_has_custom;
|
||||
static char current_id[64], current_code[64];
|
||||
static int code_visible = 1, suppress_switch, start_hidden, close_hides;
|
||||
@@ -274,6 +278,68 @@ static GtkWidget *build_account_card(void) {
|
||||
return card;
|
||||
}
|
||||
|
||||
static void present_window(void) { if (window) { gtk_widget_show(window); gtk_window_present(GTK_WINDOW(window)); } }
|
||||
static void on_tray_open(GtkMenuItem *i, gpointer d) { (void)i; (void)d; present_window(); }
|
||||
static void on_tray_allow(GtkCheckMenuItem *i, gpointer d) {
|
||||
(void)d;
|
||||
if (!suppress_tray) post(gtk_check_menu_item_get_active(i) ? CMD_ALLOW : CMD_DENY);
|
||||
}
|
||||
static void on_tray_quit(GtkMenuItem *i, gpointer d) {
|
||||
(void)i; (void)d;
|
||||
GtkWidget *dlg = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL,
|
||||
"退出后本机将下线:设备列表和远程协助都无法连接,直到再次启动。确定退出吗?");
|
||||
gtk_window_set_title(GTK_WINDOW(dlg), "UU 远程 Linux 主机");
|
||||
if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK) post(CMD_QUIT);
|
||||
gtk_widget_destroy(dlg);
|
||||
}
|
||||
static void on_status_activate(GtkStatusIcon *i, gpointer d) { (void)i; (void)d; present_window(); }
|
||||
static void on_status_menu(GtkStatusIcon *i, guint button, guint time, gpointer d) {
|
||||
(void)i; (void)button; (void)time; (void)d;
|
||||
gtk_menu_popup_at_pointer(GTK_MENU(tray_menu), NULL);
|
||||
}
|
||||
static void build_tray(void) {
|
||||
tray_menu = gtk_menu_new();
|
||||
GtkWidget *open = gtk_menu_item_new_with_label("打开主窗口");
|
||||
g_signal_connect(open, "activate", G_CALLBACK(on_tray_open), NULL);
|
||||
tray_allow = gtk_check_menu_item_new_with_label("允许他人远程协助");
|
||||
g_signal_connect(tray_allow, "toggled", G_CALLBACK(on_tray_allow), NULL);
|
||||
GtkWidget *quit = gtk_menu_item_new_with_label("退出");
|
||||
g_signal_connect(quit, "activate", G_CALLBACK(on_tray_quit), NULL);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(tray_menu), open);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(tray_menu), tray_allow);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(tray_menu), gtk_separator_menu_item_new());
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(tray_menu), quit);
|
||||
gtk_widget_show_all(tray_menu);
|
||||
const char *icon = gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), "uu-remote-linux") ? "uu-remote-linux" : "computer";
|
||||
|
||||
// StatusNotifierItem (GNOME AppIndicator extension, KDE): libayatana-appindicator3 / libappindicator3.
|
||||
const char *libs[] = { "libayatana-appindicator3.so.1", "libappindicator3.so.1" };
|
||||
for (int i = 0; i < 2; i++) {
|
||||
void *h = dlopen(libs[i], RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!h) continue;
|
||||
void *(*ind_new)(const char *, const char *, int) = (void *(*)(const char *, const char *, int))dlsym(h, "app_indicator_new");
|
||||
void (*set_status)(void *, int) = (void (*)(void *, int))dlsym(h, "app_indicator_set_status");
|
||||
void (*set_menu)(void *, GtkMenu *) = (void (*)(void *, GtkMenu *))dlsym(h, "app_indicator_set_menu");
|
||||
void (*set_title)(void *, const char *) = (void (*)(void *, const char *))dlsym(h, "app_indicator_set_title");
|
||||
if (ind_new && set_status && set_menu) {
|
||||
void *ind = ind_new("uu-remote-linux", icon, 0 /* APPLICATION_STATUS */);
|
||||
if (set_title) set_title(ind, "UU 远程 Linux 主机");
|
||||
set_menu(ind, GTK_MENU(tray_menu));
|
||||
set_status(ind, 1 /* ACTIVE */);
|
||||
return; // keep the library loaded for the indicator's lifetime
|
||||
}
|
||||
dlclose(h);
|
||||
}
|
||||
// XEmbed system tray (Xfce, Cinnamon, MATE...).
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
GtkStatusIcon *status = gtk_status_icon_new_from_icon_name(icon);
|
||||
gtk_status_icon_set_tooltip_text(status, "UU 远程 Linux 主机");
|
||||
gtk_status_icon_set_title(status, "UU 远程 Linux 主机");
|
||||
g_signal_connect(status, "activate", G_CALLBACK(on_status_activate), NULL);
|
||||
g_signal_connect(status, "popup-menu", G_CALLBACK(on_status_menu), NULL);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
static void build_window(void) {
|
||||
GtkCssProvider *css = gtk_css_provider_new();
|
||||
gtk_css_provider_load_from_data(css, CSS, -1, NULL);
|
||||
@@ -398,6 +464,7 @@ static void build_window(void) {
|
||||
gtk_box_pack_end(GTK_BOX(root), footer_label, FALSE, FALSE, 0);
|
||||
if (close_hides) gtk_label_set_text(GTK_LABEL(footer_label), "开源 Linux 被控端 · 非网易官方客户端 · 关闭窗口后远程协助仍在后台运行");
|
||||
render_code();
|
||||
if (close_hides) build_tray();
|
||||
gtk_widget_show_all(gtk_bin_get_child(GTK_BIN(window)));
|
||||
gtk_widget_set_visible(assist_card, show_assist);
|
||||
gtk_widget_set_visible(hint_label, show_assist);
|
||||
@@ -465,6 +532,7 @@ static gboolean apply_state(gpointer data) {
|
||||
suppress_switch = 1;
|
||||
gtk_switch_set_active(GTK_SWITCH(allow_switch), s->allowed);
|
||||
suppress_switch = 0;
|
||||
if (tray_allow) { suppress_tray = 1; gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tray_allow), s->allowed); suppress_tray = 0; }
|
||||
cur_verify = s->verify; cur_refresh = s->refresh; cur_has_custom = s->has_custom;
|
||||
suppress_combo = 1; gtk_combo_box_set_active(GTK_COMBO_BOX(verify_combo), s->verify); suppress_combo = 0;
|
||||
if (s->refresh >= 0 && s->refresh < 5) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
Mac 快捷键和在 Mac 上一样用。/ Mac shortcuts work as on a Mac.
|
||||
|
||||
### 新增 / Added
|
||||
- **Mac 快捷键**:在 Mac 远控窗口菜单里**关闭「使用 macOS 快捷键」**后:
|
||||
- Cmd+C / V / A / F / X / Z 是复制、粘贴、全选、查找、剪切、撤销(Cmd+Shift+Z 等组合同样可用);
|
||||
- 在终端里 Cmd+C / Cmd+V 自动变成终端的复制、粘贴(Ctrl+Shift+C / V),**Ctrl+C 始终是中断**;
|
||||
- 其他 Cmd 组合键和单独按 Cmd 仍然是 Super(Windows 键)。
|
||||
只对 Mac 控制端生效(按连接请求里的控制端平台判断),Windows 和手机控制端不受影响。✅ 已用官方 Mac 客户端在 X11 实机验收。
|
||||
保持该选项开启时行为和以前一样(客户端会把 Cmd 当成 Ctrl 发送)。
|
||||
With 「使用 macOS 快捷键」 off, Cmd shortcuts behave as on a Mac (terminal-aware copy/paste), only for macOS viewers.
|
||||
|
||||
### 下载 / Download
|
||||
`uu-remote-linux-v0.1.12-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/`。
|
||||
|
||||
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||
@@ -0,0 +1,17 @@
|
||||
托盘图标。/ Tray icon.
|
||||
|
||||
### 新增 / Added
|
||||
- **托盘图标**:后台运行时,顶栏/任务栏会显示托盘图标,菜单里有「打开主窗口」、「允许他人远程协助」(与主窗口开关同步)和「退出」。
|
||||
- GNOME 通过 AppIndicator 显示(Ubuntu 自带扩展;运行时加载 libayatana-appindicator,无需额外编译依赖);Xfce / Cinnamon / KDE 等使用系统托盘。
|
||||
- 「退出」会停止 `uuremote-native.service`(不会被自动重启);之后从应用菜单「UU 远程 Linux 主机」打开,会重新启动服务并显示主窗口。
|
||||
✅ Ubuntu 24.04 GNOME(X11)实机验收:图标、菜单、开关同步、退出、从应用菜单重新启动。⚠️ Xfce 等系统托盘路径尚未实机验收。
|
||||
Tray icon with open / allow / quit; Quit stops the user service and the launcher restarts it. Verified on Ubuntu GNOME.
|
||||
|
||||
### 改进 / Improved
|
||||
- `uuremote-server show`:主机没在运行时,优先启动已安装的 `uuremote-native.service`,而不是另起一个不受管理的进程。
|
||||
- 修复启动时的一个时序问题:先注册窗口唤起信号再写入 PID 文件,避免过早的 `show` 意外结束主机进程。
|
||||
|
||||
### 下载 / Download
|
||||
`uu-remote-linux-v0.1.13-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/`。
|
||||
|
||||
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||
@@ -0,0 +1,13 @@
|
||||
修复手机切回终端时黑屏。/ Fixes a black terminal after returning to it on mobile.
|
||||
|
||||
### 修复 / Fixed
|
||||
- **终端历史输出较多时,重连后黑屏**(#14,感谢 @cnetst):手机客户端切到后台再回到同一个终端时,如果之前积累的输出较多,
|
||||
会整屏黑屏,连新建终端也没有输出,只能完全退出 App 重连。原因是重连时把最多 256 KB 的历史输出作为一条消息发送,
|
||||
超过了 WebRTC 数据通道单条消息 64 KB 的上限,发送失败后整个终端连接卡住。现在历史输出按 16 KB 分段发送,顺序不变。
|
||||
✅ 已用官方手机客户端在 3090 实机验收。
|
||||
Terminal scrollback is replayed in 16 KiB chunks instead of one message over the 64 KiB SCTP limit. Verified on mobile.
|
||||
|
||||
### 下载 / Download
|
||||
`uu-remote-linux-v0.1.14-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/`。
|
||||
|
||||
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||
+11
-5
@@ -68,7 +68,7 @@ fn valid_custom(code: &str) -> bool {
|
||||
&& code.bytes().any(|b| b.is_ascii_alphabetic()) && code.bytes().any(|b| b.is_ascii_digit())
|
||||
}
|
||||
|
||||
pub enum Command { Allow, Deny, Reset, Stop, Verify(Verify), Refresh(Refresh), Custom(String), Logout }
|
||||
pub enum Command { Allow, Deny, Reset, Stop, Verify(Verify), Refresh(Refresh), Custom(String), Logout, Quit }
|
||||
|
||||
#[cfg(uu_gtk)]
|
||||
extern "C" {
|
||||
@@ -156,6 +156,7 @@ impl LocalUi {
|
||||
6 => if let Some(r) = Refresh::from_index(index) { return Command::Refresh(r) },
|
||||
7 => return Command::Custom(text),
|
||||
8 => return Command::Logout,
|
||||
9 => return Command::Quit,
|
||||
_ => tokio::time::sleep(std::time::Duration::from_millis(150)).await,
|
||||
}
|
||||
},
|
||||
@@ -477,10 +478,15 @@ mod tests {
|
||||
let ui = LocalUi::Tty(tokio::io::unix::AsyncFd::new(slave).unwrap());
|
||||
let mut master = std::fs::File::from(pair.master);
|
||||
ui.show("fixture-123", "FIXTURE8", false, Verify::Temporary, Refresh::Session, false).unwrap();
|
||||
let mut bytes = [0u8; 1024];
|
||||
let n = master.read(&mut bytes).unwrap();
|
||||
let text = std::str::from_utf8(&bytes[..n]).unwrap();
|
||||
assert!(text.contains("fixture-123") && text.contains("FIXTURE8") && text.contains("false"));
|
||||
// A PTY may deliver the banner in several chunks: read until complete (bounded).
|
||||
let mut text = String::new();
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(3);
|
||||
let complete = |t: &str| t.contains("fixture-123") && t.contains("FIXTURE8") && t.contains("false") && t.contains("off=");
|
||||
while !complete(&text) && std::time::Instant::now() < deadline {
|
||||
let mut bytes = [0u8; 1024];
|
||||
match master.read(&mut bytes) { Ok(n) if n > 0 => text.push_str(&String::from_utf8_lossy(&bytes[..n])), _ => break }
|
||||
}
|
||||
assert!(complete(&text));
|
||||
for (input, expected) in [(b"unknown\nallow\n".as_slice(), 0), (b"reset\n".as_slice(), 1), (b"off\n".as_slice(), 2)] {
|
||||
master.write_all(input).unwrap();
|
||||
let command = tokio::time::timeout(std::time::Duration::from_secs(2), ui.command()).await.unwrap();
|
||||
|
||||
+61
-2
@@ -43,8 +43,12 @@ struct HeldInput { buttons: std::collections::BTreeSet<i32>, keys: std::collecti
|
||||
/// Held modifier VKs (bit 0 Ctrl, 1 Shift, 2 Alt, 3 Win) and keys that got a synthetic Shift.
|
||||
#[derive(Default)]
|
||||
struct Shortcuts { modifiers: u8, shifted: std::collections::BTreeSet<i32> }
|
||||
/// Mac viewer with 「使用 macOS 快捷键」 off sends Cmd as VK_LWIN (verified: Cmd 0x5B, Option 0xA4,
|
||||
/// Ctrl 0xA2). Cmd is held back until we know whether it starts a Mac shortcut.
|
||||
#[derive(Default)]
|
||||
struct CmdState { held: bool, pending: bool, passthrough: bool, combos: std::collections::BTreeMap<i32, bool> }
|
||||
|
||||
pub struct InputInjector { serial:std::sync::Mutex<()>, owner:std::sync::Mutex<DesktopOwner>, shortcuts: std::sync::Mutex<Shortcuts>, uinput: Option<crate::uinput::Devices>, screen: std::sync::Mutex<(u32,u32)>, portal_failures: std::sync::atomic::AtomicUsize, portal_outcomes: [std::sync::atomic::AtomicUsize; 3], portal:std::sync::Mutex<Option<std::sync::Arc<crate::portal::PortalSession>>>, backend: crate::desktop_backend::DesktopBackend, pending: std::sync::Mutex<PendingPointer>, held: std::sync::Mutex<HeldInput> }
|
||||
pub struct InputInjector { mac_controller: std::sync::atomic::AtomicBool, cmd: std::sync::Mutex<CmdState>, serial:std::sync::Mutex<()>, owner:std::sync::Mutex<DesktopOwner>, shortcuts: std::sync::Mutex<Shortcuts>, uinput: Option<crate::uinput::Devices>, screen: std::sync::Mutex<(u32,u32)>, portal_failures: std::sync::atomic::AtomicUsize, portal_outcomes: [std::sync::atomic::AtomicUsize; 3], portal:std::sync::Mutex<Option<std::sync::Arc<crate::portal::PortalSession>>>, backend: crate::desktop_backend::DesktopBackend, pending: std::sync::Mutex<PendingPointer>, held: std::sync::Mutex<HeldInput> }
|
||||
|
||||
impl InputInjector {
|
||||
pub fn new() -> Self {
|
||||
@@ -55,7 +59,7 @@ impl InputInjector {
|
||||
Err(e) => { log::warn!("uinput unavailable ({}); using the desktop input path. See README for the udev rule.", e.kind()); None }
|
||||
}
|
||||
} else { None };
|
||||
Self { serial:std::sync::Mutex::new(()), owner:std::sync::Mutex::new(DesktopOwner::default()), shortcuts: std::sync::Mutex::new(Shortcuts::default()), uinput, screen: std::sync::Mutex::new((0,0)), portal_failures: std::sync::atomic::AtomicUsize::new(0), portal_outcomes: std::array::from_fn(|_| std::sync::atomic::AtomicUsize::new(0)), portal:std::sync::Mutex::new(None), backend:crate::desktop_backend::detect().unwrap_or(crate::desktop_backend::DesktopBackend::X11), pending: std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()) }
|
||||
Self { mac_controller: std::sync::atomic::AtomicBool::new(false), cmd: std::sync::Mutex::new(CmdState::default()), serial:std::sync::Mutex::new(()), owner:std::sync::Mutex::new(DesktopOwner::default()), shortcuts: std::sync::Mutex::new(Shortcuts::default()), uinput, screen: std::sync::Mutex::new((0,0)), portal_failures: std::sync::atomic::AtomicUsize::new(0), portal_outcomes: std::array::from_fn(|_| std::sync::atomic::AtomicUsize::new(0)), portal:std::sync::Mutex::new(None), backend:crate::desktop_backend::detect().unwrap_or(crate::desktop_backend::DesktopBackend::X11), pending: std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()) }
|
||||
}
|
||||
|
||||
pub fn bind_portal(&self,session:Option<std::sync::Arc<crate::portal::PortalSession>>) {
|
||||
@@ -167,8 +171,62 @@ impl InputInjector {
|
||||
shift
|
||||
}
|
||||
|
||||
/// The current desktop controller is the macOS viewer (connect header controller_platform).
|
||||
pub fn set_mac_controller(&self, mac: bool) {
|
||||
self.mac_controller.store(mac, std::sync::atomic::Ordering::Relaxed);
|
||||
*self.cmd.lock().unwrap() = CmdState::default();
|
||||
}
|
||||
|
||||
fn terminal_focused(&self) -> bool {
|
||||
self.backend == crate::desktop_backend::DesktopBackend::X11 && std::env::var_os("DISPLAY").is_some()
|
||||
&& !std::env::var("UU_TERMINAL_SHORTCUTS").is_ok_and(|v| v == "0")
|
||||
&& unsafe { x11_terminal_shortcut_state() } & 1 != 0
|
||||
}
|
||||
|
||||
/// Mac habits for a Mac viewer with 「使用 macOS 快捷键」 off: Cmd+C/V/A/F/X/Z (the keys that option
|
||||
/// lists) become Ctrl+key, and in a focused terminal Cmd+C/V become Ctrl+Shift+C/V (copy/paste)
|
||||
/// while Ctrl+C still interrupts. Other Cmd combos, and Cmd alone, stay Super. Returns true when handled.
|
||||
fn mac_cmd(&self, key: i32, is_press: bool) -> bool {
|
||||
const SUPER_L: u64 = 0xffeb; const CONTROL_L: u64 = 0xffe3; const SHIFT_L: u64 = 0xffe1;
|
||||
let mut st = self.cmd.lock().unwrap();
|
||||
if matches!(key, 0x5b | 0x5c) {
|
||||
if is_press { st.held = true; st.pending = true; st.passthrough = false; }
|
||||
else {
|
||||
if st.passthrough { self.inject_key(SUPER_L, false); }
|
||||
else if st.pending { self.inject_key(SUPER_L, true); self.inject_key(SUPER_L, false); }
|
||||
st.held = false; st.pending = false; st.passthrough = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if !is_press {
|
||||
let Some(shifted) = st.combos.remove(&key) else { return false };
|
||||
self.key_symbol_event(key, false);
|
||||
if shifted { self.inject_key(SHIFT_L, false); }
|
||||
self.inject_key(CONTROL_L, false);
|
||||
return true;
|
||||
}
|
||||
if !st.held { return false; }
|
||||
// Shift/Option/Ctrl pressed with Cmd (e.g. Cmd+Shift+Z) must not decide the combo yet.
|
||||
if matches!(key, 0x10..=0x12 | 0xa0..=0xa5) { return false; }
|
||||
if st.combos.contains_key(&key) { self.key_symbol_event(key, true); return true; } // autorepeat
|
||||
if matches!(key, 0x41 | 0x43 | 0x46 | 0x56 | 0x58 | 0x5a) && !st.passthrough {
|
||||
st.pending = false;
|
||||
let shifted = matches!(key, 0x43 | 0x56) && self.terminal_focused();
|
||||
self.inject_key(CONTROL_L, true);
|
||||
if shifted { self.inject_key(SHIFT_L, true); }
|
||||
self.key_symbol_event(key, true);
|
||||
st.combos.insert(key, shifted);
|
||||
static NOTED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
||||
if NOTED.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 4 { log::info!("Mac shortcut: Cmd combo sent as Ctrl{}", if shifted { "+Shift (terminal)" } else { "" }); }
|
||||
return true;
|
||||
}
|
||||
if st.pending { self.inject_key(SUPER_L, true); st.pending = false; st.passthrough = true; }
|
||||
false
|
||||
}
|
||||
|
||||
pub fn windows_key_event(&self, key: i32, is_press: bool) {
|
||||
let _serial=self.serial.lock().unwrap();
|
||||
if self.mac_controller.load(std::sync::atomic::Ordering::Relaxed) && self.mac_cmd(key, is_press) { return; }
|
||||
if self.terminal_shift(key, is_press) {
|
||||
const SHIFT_L: u64 = 0xffe1;
|
||||
if is_press {
|
||||
@@ -221,6 +279,7 @@ impl InputInjector {
|
||||
}
|
||||
*held=HeldInput::default();
|
||||
*self.shortcuts.lock().unwrap()=Shortcuts::default();
|
||||
*self.cmd.lock().unwrap()=CmdState::default();
|
||||
}
|
||||
// Per-injector budgets cover missing bindings, locked sessions, stale handles
|
||||
// and D-Bus errors. Never include keys, coordinates, text or portal tokens.
|
||||
|
||||
+42
-5
@@ -63,14 +63,19 @@ fn restart_host() -> ! {
|
||||
eprintln!("restart failed: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
/// systemd user unit running this process (from /proc/self/cgroup), e.g. "uuremote-native.service".
|
||||
fn systemd_unit() -> Option<String> {
|
||||
std::env::var_os("INVOCATION_ID")?;
|
||||
let cgroup = std::fs::read_to_string("/proc/self/cgroup").ok()?;
|
||||
cgroup.lines().find_map(|l| l.rsplit('/').next().filter(|u| u.ends_with(".service")).map(str::to_owned))
|
||||
}
|
||||
fn display_present() -> bool { std::env::var_os("DISPLAY").is_some() || std::env::var_os("WAYLAND_DISPLAY").is_some() }
|
||||
/// SIGUSR1 (`uuremote-server show`) opens the host window.
|
||||
fn present_on_usr1(ui: std::sync::Arc<assist::LocalUi>) {
|
||||
// Install the handler before publishing the pid: SIGUSR1's default action terminates the process.
|
||||
let Ok(mut usr1) = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::user_defined1()) else { return };
|
||||
write_host_pid();
|
||||
tokio::spawn(async move {
|
||||
let Ok(mut usr1) = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::user_defined1()) else { return };
|
||||
while usr1.recv().await.is_some() { ui.present(); }
|
||||
});
|
||||
tokio::spawn(async move { while usr1.recv().await.is_some() { ui.present(); } });
|
||||
}
|
||||
|
||||
fn host_pid_path() -> std::path::PathBuf { config::path().with_file_name("host.pid") }
|
||||
@@ -94,6 +99,24 @@ fn show_running_host() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(pid) = running {
|
||||
if unsafe { libc::kill(pid, libc::SIGUSR1) } == 0 { return Ok(()); }
|
||||
}
|
||||
// Stopped from the tray but installed as a user service: start the service (not a second,
|
||||
// unmanaged host), wait for it to publish its pid, then ask it to show the window.
|
||||
let unit = std::env::var("UU_SERVICE_UNIT").unwrap_or_else(|_| "uuremote-native.service".into());
|
||||
let installed = std::process::Command::new("systemctl").args(["--user", "cat", &unit])
|
||||
.stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null()).status().is_ok_and(|s| s.success());
|
||||
if installed && std::process::Command::new("systemctl").args(["--user", "start", &unit]).status().is_ok_and(|s| s.success()) {
|
||||
let before = std::fs::metadata(host_pid_path()).and_then(|m| m.modified()).ok();
|
||||
for _ in 0..60 {
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
let fresh = std::fs::metadata(host_pid_path()).and_then(|m| m.modified()).ok().is_some_and(|t| Some(t) != before);
|
||||
let pid = std::fs::read_to_string(host_pid_path()).ok().and_then(|s| s.trim().parse::<i32>().ok());
|
||||
if let (true, Some(pid)) = (fresh, pid) {
|
||||
std::thread::sleep(std::time::Duration::from_millis(500)); // signal handler installed right after the pid
|
||||
if unsafe { libc::kill(pid, libc::SIGUSR1) } == 0 { return Ok(()); }
|
||||
}
|
||||
}
|
||||
return Err("the UU remote host service started but did not open its window".into());
|
||||
}
|
||||
use std::os::unix::process::CommandExt;
|
||||
Err(Box::new(std::process::Command::new("/proc/self/exe").env("UU_SHOW_WINDOW", "1").exec()))
|
||||
}
|
||||
@@ -426,6 +449,8 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
// One peer per viewer connection (desktop, file transfer, terminal...), keyed by ice_id.
|
||||
let mut next_capture_type: Option<(u64,crate::session_ice::SessionIce)> = None;
|
||||
let mut capture_types: HashMap<String, (u64,crate::session_ice::SessionIce)> = HashMap::new();
|
||||
let mut mac_by_ice: HashMap<String, bool> = HashMap::new();
|
||||
let mut next_mac = false;
|
||||
|
||||
loop {
|
||||
if *shutdown.borrow() {
|
||||
@@ -522,6 +547,14 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
SignalingEvent::AssistCommand(assist::Command::Verify(v)) => { if let Some(s) = assist.as_mut() { s.set_verify(v)?; } }
|
||||
SignalingEvent::AssistCommand(assist::Command::Refresh(r)) => { if let Some(s) = assist.as_mut() { s.set_refresh(r)?; } }
|
||||
SignalingEvent::AssistCommand(assist::Command::Custom(c)) => { if let Some(s) = assist.as_mut() { s.set_custom(c)?; } }
|
||||
SignalingEvent::AssistCommand(assist::Command::Quit) => {
|
||||
// Tray 退出: under systemd (Restart=always) stop the unit itself, else just exit.
|
||||
log::info!("Quit requested from the tray");
|
||||
if let Some(unit) = systemd_unit() {
|
||||
let _ = std::process::Command::new("systemctl").args(["--user", "stop", "--no-block", &unit]).status();
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
SignalingEvent::AssistCommand(assist::Command::Logout) => {
|
||||
if let Some(s) = assist.as_mut().filter(|s| s.is_account()) {
|
||||
s.logout().await;
|
||||
@@ -579,7 +612,9 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
.and_then(|s| s.as_str())
|
||||
);
|
||||
}
|
||||
SignalingEvent::ConnectRequest { capture_type, ice_id, transport } => {
|
||||
SignalingEvent::ConnectRequest { capture_type, ice_id, transport, controller_mac } => {
|
||||
if mac_by_ice.len()>=32 { mac_by_ice.clear(); }
|
||||
match ice_id.clone() { Some(id) => { mac_by_ice.insert(id, controller_mac); } None => next_mac = controller_mac }
|
||||
// Pending cloud credentials live only within this room; cap
|
||||
// requests that never receive an offer rather than retain them.
|
||||
if capture_types.len()>=32 { capture_types.clear(); }
|
||||
@@ -610,6 +645,8 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
let (capture_type,transport) = capture_types.remove(&ice).or_else(|| next_capture_type.take()).unwrap_or((1,crate::session_ice::SessionIce::default()));
|
||||
// CaptureType: 0 unknown, 1 desktop, 2 window; 5 file transfer, 8 terminal, 9 port mapping.
|
||||
let desktop = capture_type <= 2;
|
||||
let controller_mac = mac_by_ice.remove(&ice).unwrap_or(next_mac);
|
||||
if desktop { input.set_mac_controller(controller_mac); }
|
||||
log::info!("Offer for connection: capture_type={} desktop={} active_peers={}", capture_type, desktop, sessions.len());
|
||||
if let Some(old) = sessions.remove(&ice) { let _ = old.pc.close().await; }
|
||||
if desktop {
|
||||
|
||||
+7
-2
@@ -41,7 +41,7 @@ pub enum SignalingEvent {
|
||||
BeControlled(Value),
|
||||
/// be-controlled with its binary app_data (ConnectOptions): capture type and the
|
||||
/// ice_id it announces, when present.
|
||||
ConnectRequest { capture_type: u64, ice_id: Option<String>, transport:crate::session_ice::SessionIce },
|
||||
ConnectRequest { capture_type: u64, ice_id: Option<String>, transport:crate::session_ice::SessionIce, controller_mac: bool },
|
||||
Soac(SoacMessage),
|
||||
Released(Value),
|
||||
Left(Value),
|
||||
@@ -317,7 +317,12 @@ impl SignalingClient {
|
||||
let ice_id = ["ice_id", "iceId"].iter().find_map(|k| header.get(*k).or_else(|| header.get("data").and_then(|d| d.get(*k))))
|
||||
.and_then(|v| v.as_str()).map(str::to_owned);
|
||||
log::info!("be-controlled connect request: capture_type={} header_keys={:?} ice_id_present={}", capture_type, keys, ice_id.is_some());
|
||||
let _ = event_sender.send(SignalingEvent::ConnectRequest { capture_type, ice_id, transport:crate::session_ice::SessionIce::from_header(&header) }).await;
|
||||
// Viewer platform (website enum: 1 windows, 2 android, 3 ios, 4 macos, 5 tv).
|
||||
let platform = header.get("controller_platform").or_else(|| header.get("data").and_then(|d| d.get("controller_platform")));
|
||||
let controller_mac = platform.is_some_and(|v| v.as_i64() == Some(4)
|
||||
|| v.as_str().is_some_and(|s| s == "4" || s.to_ascii_lowercase().contains("mac") || s.to_ascii_lowercase().contains("darwin")));
|
||||
log::info!("Controller platform: {} mac={}", platform.map(|v| v.to_string()).unwrap_or_default().chars().take(24).collect::<String>(), controller_mac);
|
||||
let _ = event_sender.send(SignalingEvent::ConnectRequest { capture_type, ice_id, transport:crate::session_ice::SessionIce::from_header(&header), controller_mac }).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+42
-2
@@ -34,6 +34,7 @@ const MAGIC: &[u8; 4] = b"TERM";
|
||||
const HEADER: usize = 16;
|
||||
const MAX_PAYLOAD: usize = 0x10_0000;
|
||||
const SCROLLBACK: usize = 256 * 1024;
|
||||
const OUTPUT_CHUNK: usize = 16 * 1024;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Frame { pub kind: u8, pub flags: [u8; 2], pub session: u32, pub payload: Vec<u8> }
|
||||
@@ -140,7 +141,7 @@ fn spawn(requested_id: u32, cols: u16, rows: u16, shell: Option<&str>) -> Result
|
||||
let mut reader = std::fs::File::from(session.master.try_clone().map_err(|e| format!("pty dup failed: {e}"))?);
|
||||
let worker = session.clone();
|
||||
std::thread::Builder::new().name(format!("uu-term-{id}")).spawn(move || {
|
||||
let mut buf = vec![0u8; 16 * 1024];
|
||||
let mut buf = vec![0u8; OUTPUT_CHUNK];
|
||||
loop {
|
||||
match reader.read(&mut buf) {
|
||||
Ok(0) | Err(_) => break,
|
||||
@@ -222,7 +223,8 @@ impl TerminalConn {
|
||||
self.send(OPEN_RESP, s.id, &reply(0, "ok"));
|
||||
*sink = Some(self.out.clone());
|
||||
let replay: Vec<u8> = s.scrollback.lock().unwrap().iter().copied().collect();
|
||||
if !replay.is_empty() { self.send(STDOUT, s.id, &replay); }
|
||||
// A full scrollback exceeds SCTP's 64 KiB outbound message limit.
|
||||
for chunk in replay.chunks(OUTPUT_CHUNK) { self.send(STDOUT, s.id, chunk); }
|
||||
}
|
||||
Err(e) => { log::warn!("Terminal open failed: {}", e); self.send(OPEN_RESP, frame.session, &reply(1, &e)); }
|
||||
}
|
||||
@@ -289,6 +291,44 @@ mod tests {
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn reconnect_replays_large_history_in_bounded_frames() {
|
||||
let pty = nix::pty::openpty(None, None).unwrap();
|
||||
let id = u32::MAX - 1;
|
||||
let history: Vec<u8> = (0..SCROLLBACK).map(|n| (n % 251) as u8).collect();
|
||||
let session = Arc::new(Session { id, shell: "/bin/sh".into(), created_ms: now_ms(),
|
||||
master: pty.master, pid: 0, sink: Mutex::new(None),
|
||||
scrollback: Mutex::new(history.iter().copied().collect()) });
|
||||
registry().lock().unwrap().insert(id, session.clone());
|
||||
struct Cleanup(u32);
|
||||
impl Drop for Cleanup { fn drop(&mut self) { registry().lock().unwrap().remove(&self.0); } }
|
||||
let _cleanup = Cleanup(id);
|
||||
|
||||
for _ in 0..2 {
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
let conn = TerminalConn::new(tx);
|
||||
conn.handle(&encode(OPEN, id, br#"{"cols":80,"rows":24}"#));
|
||||
let opened = decode(&rx.try_recv().unwrap()).unwrap();
|
||||
assert_eq!(opened.kind, OPEN_RESP);
|
||||
assert_eq!(opened.session, id);
|
||||
let mut replay = Vec::new();
|
||||
while replay.len() < history.len() {
|
||||
let packet = rx.try_recv().unwrap();
|
||||
// SCTP's default outbound limit includes the TERM header.
|
||||
assert!(packet.len() <= 65536, "terminal replay exceeds the SCTP message limit");
|
||||
let frame = decode(&packet).unwrap();
|
||||
assert_eq!(frame.kind, STDOUT);
|
||||
assert_eq!(frame.session, id);
|
||||
replay.extend(frame.payload);
|
||||
}
|
||||
assert!(replay == history, "terminal replay must preserve every byte in order");
|
||||
assert!(session.emit(STDOUT, b"live output"));
|
||||
assert_eq!(decode(&rx.try_recv().unwrap()).unwrap().payload, b"live output");
|
||||
conn.handle(&encode(LIST_REQ, 7, &[]));
|
||||
assert_eq!(decode(&rx.try_recv().unwrap()).unwrap().kind, LIST_RESP);
|
||||
conn.handle(&encode(DETACH, id, &[]));
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn open_spawns_shell_and_streams_output() {
|
||||
for requested_id in [0, u32::MAX] {
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
|
||||
Reference in new issue
Block a user