mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
feat(viewer): remove a device from the account (unbind)
POST /api/v1/device/{id}/unbind, the path the official Windows host and Mac
viewer use for 「删除设备」. Verified live on a disposable test device; the
shared-device path (/api/v1/device/share/{id}/unbind) comes from strings only.
CLI: uuremote-viewer unbind DEVICE [--shared]; launcher: 更多工具 → 删除设备
with a confirmation dialog.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
664c96941c
commit
2815a01569
7 files changed
+61
-12
No files matched your search
@@ -146,7 +146,7 @@ every 60 s.
|
||||
| `c_engine/x11_engine.c`, `c_engine/clipboard.c` | X11 capture/input/selection |
|
||||
| `c_engine/wayland_engine.c`, `c_engine/portal_engine.c` | Wayland and portal engines |
|
||||
| `src/assist.rs`, `c_engine/assist_window.c` | remote assistance (guest + account) and the unified GTK main window (assist + account/QR card) |
|
||||
| `src/viewer_main.rs`, `src/viewer/` | experimental viewer (`--features native-viewer,viewer-sdl`): cloud join, WebRTC offer side, SDL desktop window (ffmpeg CLI decode), files/terminal/portmap/power/assist tools, GTK launcher |
|
||||
| `src/viewer_main.rs`, `src/viewer/` | experimental viewer (`--features native-viewer,viewer-sdl`): cloud join, WebRTC offer side, SDL desktop window (ffmpeg CLI decode), files/terminal/portmap/power/assist tools, device removal (`POST /api/v1/device/{id}/unbind`, verified live; shared devices use `/api/v1/device/share/{id}/unbind`, strings only), GTK launcher |
|
||||
| `c_engine/viewer_window.c`, `c_engine/viewer_tools.c` | viewer GTK launcher and tool windows (files, port mapping, terminal list) |
|
||||
|
||||
Diagnostic subcommands: `login [--no-gui]`, `unlock-check` (password on stdin, prints only accepted/rejected),
|
||||
|
||||
+1
-1
@@ -427,7 +427,7 @@ GNOME-to-official-Mac bidirectional clipboard synchronization is still unverifie
|
||||
machine with the same identity**; other devices are fine.
|
||||
- `uuremote-viewer ui`: launcher listing your devices: desktop, view-only, files, terminal, port mapping, reboot/shutdown, assistance.
|
||||
- CLI: `connect DEVICE false - echo legacy [--view-only]` (desktop), `files DEVICE ls|get|put …`, `terminal DEVICE [SESSION]`,
|
||||
`terminal-ui DEVICE NAME`, `portmap DEVICE LOCAL_PORT HOST PORT` (listens on 127.0.0.1 only), `power DEVICE reboot|shutdown`,
|
||||
`terminal-ui DEVICE NAME`, `portmap DEVICE LOCAL_PORT HOST PORT` (listens on 127.0.0.1 only), `power DEVICE reboot|shutdown`, `unbind DEVICE` (remove a device from the account; also under "More tools" in the launcher),
|
||||
`assist CONNECT_ID` (the code is read from one stdin line, never an argument). See `uuremote-viewer --help`.
|
||||
- Ctrl+Alt+F in the desktop window opens the files window on the same connection. `UU_VIEWER_AUDIO=0` disables sound,
|
||||
`UU_VIEWER_CLIPBOARD=0` the clipboard, `UU_VIEWER_VIEW_ONLY=1` input; `UU_VIEWER_FFMPEG` selects the ffmpeg binary.
|
||||
|
||||
@@ -390,7 +390,7 @@ GNOME 与官方 Mac 被控端的双向剪贴板尚未验证通过;此修改不
|
||||
`~/.config/uuremote/config.json`(可用 `UU_CONFIG` 另指定),因此**不能用同一身份连接本机上的主机**;控制其他设备不受影响。
|
||||
- `uuremote-viewer ui`:启动窗口,列出账号下的设备,可进入桌面、只看模式、文件传输、终端、端口映射、重启/关机、远程协助。
|
||||
- 命令行:`connect DEVICE false - echo legacy [--view-only]`(桌面)、`files DEVICE ls|get|put …`、`terminal DEVICE [SESSION]`、
|
||||
`terminal-ui DEVICE NAME`、`portmap DEVICE LOCAL_PORT HOST PORT`(只监听 127.0.0.1)、`power DEVICE reboot|shutdown`、
|
||||
`terminal-ui DEVICE NAME`、`portmap DEVICE LOCAL_PORT HOST PORT`(只监听 127.0.0.1)、`power DEVICE reboot|shutdown`、`unbind DEVICE`(从账号删除设备,启动窗口「更多工具」里也有)、
|
||||
`assist CONNECT_ID`(验证码从 stdin 读取一行,不能作为参数传入)。`uuremote-viewer --help` 查看全部参数。
|
||||
- 桌面窗口中按 Ctrl+Alt+F 打开文件窗口(复用同一连接)。`UU_VIEWER_AUDIO=0` 关闭声音,`UU_VIEWER_CLIPBOARD=0` 关闭剪贴板,
|
||||
`UU_VIEWER_VIEW_ONLY=1` 只看不控,`UU_VIEWER_FFMPEG` 指定 ffmpeg 路径。
|
||||
|
||||
@@ -117,6 +117,15 @@ static void more_item(GtkButton *b, gpointer kind) {
|
||||
if (ok) { connect_kind(k); show_toast("正在发送电源指令…"); }
|
||||
return;
|
||||
}
|
||||
if (!strcmp(k, "unbind")) {
|
||||
GtkWidget *d = gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
|
||||
"确定要从账号中删除该设备吗?");
|
||||
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(d), "删除后需要在该设备上重新登录才能再次远控。");
|
||||
gtk_dialog_add_buttons(GTK_DIALOG(d), "取消", GTK_RESPONSE_CANCEL, "删除", GTK_RESPONSE_OK, NULL);
|
||||
int ok = gtk_dialog_run(GTK_DIALOG(d)) == GTK_RESPONSE_OK; gtk_widget_destroy(d);
|
||||
if (ok) { gtk_widget_destroy(dialog); connect_kind(k); show_toast("正在删除设备…"); }
|
||||
return;
|
||||
}
|
||||
gtk_widget_destroy(dialog);
|
||||
on_tool(NULL, kind);
|
||||
}
|
||||
@@ -126,9 +135,9 @@ static void open_more(void) {
|
||||
GtkWidget *area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)), *box = vbox(10);
|
||||
gtk_container_set_border_width(GTK_CONTAINER(box), 22);
|
||||
gtk_box_pack_start(GTK_BOX(box), label("更多工具", "h2"), FALSE, FALSE, 6);
|
||||
const char *names[] = {"🗂 文件传输", "▶ 观看模式", "⌨ 终端", "⇄ 端口映射", "⏻ 远程开机", "↻ 重启", "⏻ 关机"};
|
||||
const char *kinds[] = {"file", "watch", "terminal", "portmap", "wol", "reboot", "shutdown"};
|
||||
for (int i = 0; i < 7; i++) {
|
||||
const char *names[] = {"🗂 文件传输", "▶ 观看模式", "⌨ 终端", "⇄ 端口映射", "⏻ 远程开机", "↻ 重启", "⏻ 关机", "🗑 删除设备"};
|
||||
const char *kinds[] = {"file", "watch", "terminal", "portmap", "wol", "reboot", "shutdown", "unbind"};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
GtkWidget *b = gtk_button_new(), *line = hbox(10); add_class(b, "cardbtn");
|
||||
gtk_box_pack_start(GTK_BOX(line), label(names[i], "devname"), TRUE, TRUE, 0);
|
||||
gtk_box_pack_end(GTK_BOX(line), label("›", "hint"), FALSE, FALSE, 0);
|
||||
|
||||
+31
-4
@@ -42,6 +42,18 @@ impl std::fmt::Display for Error {
|
||||
}
|
||||
|
||||
// Mirrors Windows 0x140b77cd0 / 0x140b7a6d0, not host RoomData.
|
||||
/// Treat the caller's device string as one opaque path segment, never a URL/query.
|
||||
fn path_segment(device: &str) -> Result<String, Error> {
|
||||
if device.is_empty() || device=="." || device==".." { return Err(Error::InvalidDevice); }
|
||||
Ok(device.bytes().map(|b|if b.is_ascii_alphanumeric() || b"-._~".contains(&b) {(b as char).to_string()}else{format!("%{b:02X}")}).collect())
|
||||
}
|
||||
fn parse_ack(status: u16, body: Value) -> Result<(), Error> {
|
||||
let code = body.get("code").and_then(Value::as_i64).unwrap_or(-1);
|
||||
if code == 1120 { return Err(Error::AuthenticationExpired); }
|
||||
if status == 200 && code == 0 { return Ok(()); }
|
||||
let msg = body.get("msg").and_then(Value::as_str).unwrap_or("").chars().take(120).collect();
|
||||
Err(Error::Api(i32::try_from(code).unwrap_or(-1), msg))
|
||||
}
|
||||
pub fn parse_join(status: u16, value: Value) -> Result<JoinData, Error> {
|
||||
let code = value.get("code").and_then(Value::as_i64).and_then(|v| i32::try_from(v).ok()).ok_or(Error::InvalidResponse)?;
|
||||
let msg = value.get("msg").and_then(Value::as_str).ok_or(Error::InvalidResponse)?.chars().take(120).collect::<String>();
|
||||
@@ -110,10 +122,7 @@ impl Api {
|
||||
Ok((status, response.json().await.map_err(|_| Error::InvalidResponse)?))
|
||||
}
|
||||
pub async fn join(&self, device: &str, force_join: bool, retry: bool) -> Result<JoinData, Error> {
|
||||
// Treat the caller's device string as one opaque path segment, never a URL/query.
|
||||
if device.is_empty() || device=="." || device==".." { return Err(Error::InvalidDevice); }
|
||||
let encoded=device.bytes().map(|b|if b.is_ascii_alphanumeric() || b"-._~".contains(&b) {(b as char).to_string()}else{format!("%{b:02X}")}).collect::<String>();
|
||||
let path = format!("/api/v1/room/join/by_device/{encoded}");
|
||||
let path = format!("/api/v1/room/join/by_device/{}", path_segment(device)?);
|
||||
let mut retries = 0;
|
||||
loop {
|
||||
let result = match self.request(reqwest::Method::POST, &path, Some(json!({"force_join":force_join}))).await {
|
||||
@@ -143,6 +152,15 @@ impl Api {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Remove a device from the account (official 「删除设备」). Paths from the Windows host strings
|
||||
/// `/api/v1/device/%s/unbind` and `/api/v1/device/share/%s/unbind` (own vs. shared-with-me device).
|
||||
/// POST verified live against an own device; the shared-device path is from strings only.
|
||||
pub async fn unbind(&self, device: &str, shared: bool) -> Result<(), Error> {
|
||||
let segment = path_segment(device)?;
|
||||
let path = if shared { format!("/api/v1/device/share/{segment}/unbind") } else { format!("/api/v1/device/{segment}/unbind") };
|
||||
let (status, body) = self.request(reqwest::Method::POST, &path, None).await?;
|
||||
parse_ack(status, body)
|
||||
}
|
||||
/// Structure-only probe of the device list (status, JSON keys/types/lengths, never values).
|
||||
pub async fn devices_shape(&self, method: reqwest::Method) -> Result<String, Error> {
|
||||
let path = "/api/v1/device/list";
|
||||
@@ -188,6 +206,15 @@ impl Api {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test] fn unbind_ack_and_device_segment(){
|
||||
use super::*;
|
||||
assert_eq!(parse_ack(200,json!({"code":0,"msg":"ok"})),Ok(()));
|
||||
assert_eq!(parse_ack(422,json!({"code":1120})),Err(Error::AuthenticationExpired));
|
||||
assert_eq!(parse_ack(200,json!({"code":5003,"msg":"no such device"})),Err(Error::Api(5003,"no such device".into())));
|
||||
assert_eq!(parse_ack(404,json!({})),Err(Error::Api(-1,String::new())));
|
||||
assert_eq!(path_segment("a/b?c").unwrap(),"a%2Fb%3Fc");
|
||||
for bad in ["",".",".."]{assert_eq!(path_segment(bad),Err(Error::InvalidDevice));}
|
||||
}
|
||||
use super::*;
|
||||
#[test]
|
||||
fn target_platform_matches_only_the_selected_device(){
|
||||
|
||||
@@ -195,6 +195,15 @@ pub async fn run(credentials: impl Fn() -> Result<crate::auth::Credentials, Stri
|
||||
Err(_) => toast("电源指令失败:无法启动会话进程"),
|
||||
}
|
||||
}
|
||||
["connect", id, "unbind"] => {
|
||||
if let Some(s)=sessions.remove(*id){s.stop().await;}
|
||||
let result=match credentials(){
|
||||
Ok(creds)=>super::api::Api::new(crate::auth::UUAuthClient::new(creds),crate::auth::BASE_URL).unbind(id,false).await.map_err(|e|e.to_string()),
|
||||
Err(e)=>Err(e),
|
||||
};
|
||||
match result {Ok(())=>toast("设备已从账号删除"),Err(e)=>toast(&format!("删除设备失败:{e}"))}
|
||||
next_refresh=Instant::now();
|
||||
}
|
||||
["connect", _, kind] => log::info!("Viewer UI: {kind} is not supported yet"),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
+6
-2
@@ -13,7 +13,7 @@ use viewer::clipboard;
|
||||
#[cfg(test)] #[path="initialization.rs"] mod initialization;
|
||||
use viewer::{api::Api,rtc::ReadyPolicy,session::{Options,Session},wire::Shape};
|
||||
use std::time::Duration;
|
||||
const HELP:&str="Experimental native viewer.\n uuremote-viewer ui (GTK window: sign-in, devices, sessions) Desktop UI requires viewer-sdl (decodes with the ffmpeg CLI, or FFmpeg 6.x libraries with viewer-ffmpeg).\n uuremote-viewer power DEVICE reboot|shutdown\n uuremote-viewer terminal DEVICE [SESSION]\n uuremote-viewer files DEVICE ls PATH | get REMOTE LOCAL | put LOCAL REMOTE\n uuremote-viewer portmap DEVICE LOCAL_PORT HOST PORT\n uuremote-viewer files-ui|portmap-ui|terminal-ui DEVICE NAME (GTK tool windows)\n uuremote-viewer login [--no-gui]\n uuremote-viewer devices METHOD ARRAY_POINTER ID_POINTER NAME_POINTER\n uuremote-viewer assist CONNECT_ID (验证码从 stdin 读取一行)\n uuremote-viewer connect DEVICE true|false SHAPE_JSON echo|manual raw|legacy [--view-only]\nVideo: UU_VIEWER_CODEC=h264 forces H.264; UU_VIEWER_CHROMA=444 requests true color (default 4:2:0).\nAudio: UU_VIEWER_AUDIO=0 disables playback. UU_VIEWER_VIEW_ONLY=1 disables desktop input.\nDevice-list method/JSON pointers and compatibility shape require verified operator configuration.\nQR login reuses the sibling uuremote-server login command. Never run login in a captured log.\nEcho readiness is transport observation only; no sendVideoTrack RPC is emitted.";
|
||||
const HELP:&str="Experimental native viewer.\n uuremote-viewer ui (GTK window: sign-in, devices, sessions) Desktop UI requires viewer-sdl (decodes with the ffmpeg CLI, or FFmpeg 6.x libraries with viewer-ffmpeg).\n uuremote-viewer power DEVICE reboot|shutdown\n uuremote-viewer unbind DEVICE [--shared] (从账号删除设备 / remove a device from the account)\n uuremote-viewer terminal DEVICE [SESSION]\n uuremote-viewer files DEVICE ls PATH | get REMOTE LOCAL | put LOCAL REMOTE\n uuremote-viewer portmap DEVICE LOCAL_PORT HOST PORT\n uuremote-viewer files-ui|portmap-ui|terminal-ui DEVICE NAME (GTK tool windows)\n uuremote-viewer login [--no-gui]\n uuremote-viewer devices METHOD ARRAY_POINTER ID_POINTER NAME_POINTER\n uuremote-viewer assist CONNECT_ID (验证码从 stdin 读取一行)\n uuremote-viewer connect DEVICE true|false SHAPE_JSON echo|manual raw|legacy [--view-only]\nVideo: UU_VIEWER_CODEC=h264 forces H.264; UU_VIEWER_CHROMA=444 requests true color (default 4:2:0).\nAudio: UU_VIEWER_AUDIO=0 disables playback. UU_VIEWER_VIEW_ONLY=1 disables desktop input.\nDevice-list method/JSON pointers and compatibility shape require verified operator configuration.\nQR login reuses the sibling uuremote-server login command. Never run login in a captured log.\nEcho readiness is transport observation only; no sendVideoTrack RPC is emitted.";
|
||||
const DEFAULT_SHAPE:&str=r#"{"capture_type":1,"platform":3,"client_version":"4.42.0","width":1920,"height":1080,"fps":60,"chroma":1,
|
||||
"decoders":[{"fps":60,"codec":1,"width":3840,"height":2160,"chroma":1}],"display_modes":[[1920,1080,60]],
|
||||
"displays":[{"id":1,"fps":60,"type":0,"hdr":0}],
|
||||
@@ -55,6 +55,10 @@ async fn run(args:&[String])->Result<(),String> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Some("unbind") if (args.len()==2 || (args.len()==3 && args[2]=="--shared")) && !args[1].is_empty() => {
|
||||
api()?.unbind(&args[1],args.len()==3).await.map_err(|e|format!("删除设备失败:{e}"))?;
|
||||
println!("已从账号删除设备");Ok(())
|
||||
}
|
||||
Some("power")=>power_command(args).await,
|
||||
Some("terminal-local") if args.len()==2 || args.len()==3=>{
|
||||
let session=if args.len()==3{Some(args[2].parse::<u32>().ok().filter(|n|*n!=0).ok_or("Invalid terminal session id")?)}else{None};
|
||||
@@ -124,7 +128,7 @@ mod cli_tests {
|
||||
use super::*;
|
||||
#[tokio::test]
|
||||
async fn invalid_commands_never_fall_through_to_login_or_host_service() {
|
||||
for args in [vec!["invalid"],vec!["power"],vec!["power","device","logout"],vec!["power","device","reboot","extra"],vec!["login","--invalid"],vec!["connect"],vec!["assist"],vec!["assist","id","forbidden-code-argument"],vec!["terminal"],vec!["terminal","device","extra"],vec!["terminal","device","0"],vec!["terminal","device","4294967296"],vec!["terminal-ui","device"],vec!["files","device","bad","path"],vec!["portmap","device","bad","host","80"],vec!["portmap","device","8000","host","0"],vec!["devices","DELETE","/data","/id","/name"]] {
|
||||
for args in [vec!["invalid"],vec!["power"],vec!["power","device","logout"],vec!["power","device","reboot","extra"],vec!["login","--invalid"],vec!["connect"],vec!["assist"],vec!["assist","id","forbidden-code-argument"],vec!["terminal"],vec!["terminal","device","extra"],vec!["terminal","device","0"],vec!["terminal","device","4294967296"],vec!["terminal-ui","device"],vec!["files","device","bad","path"],vec!["portmap","device","bad","host","80"],vec!["portmap","device","8000","host","0"],vec!["devices","DELETE","/data","/id","/name"],vec!["unbind"],vec!["unbind",""],vec!["unbind","device","--other"],vec!["unbind","device","--shared","extra"]] {
|
||||
assert!(run(&args.into_iter().map(str::to_owned).collect::<Vec<_>>()).await.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user