Files
uu-remote-linux/src/login_ui.rs
T
VallierDevandClaude Opus 5.5 94039c092a Remote assistance (experimental) and unified host window
Like the official client: share a device ID + verification code; the other
person connects from 开始协助. Guest identity before sign-in, account identity
after (same share ID). One GTK window: 本设备 (allow switch, ID/code with copy,
verification modes incl. custom code, rotation schedule, copy & share) and
账号 (QR before sign-in, masked account + sign out after). Logged-in hosts keep
the window hidden; `uuremote-server show` / the desktop launcher opens it.
App icon and .desktop entry in contrib/desktop.

Protocol from the official Windows lite host; guest flow, wrong-code rejection,
rotation, switching off, sign-in/sign-out verified with the official Mac
viewer. Signed-in assistance from another account is not yet verified.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 22:17:25 +08:00

89 lines
3.5 KiB
Rust

//! Optional GTK3 window for `uuremote-server login` (c_engine/login_window.c). Built only when
//! gtk+-3.0 is available (cfg uu_gtk); otherwise, and with `--no-gui` or no display, every call
//! is a no-op and the terminal QR remains the only UI.
#[cfg(uu_gtk)]
extern "C" {
fn uu_login_ui_start(name: *const libc::c_char, os: *const libc::c_char, cpu: *const libc::c_char, gpu: *const libc::c_char) -> libc::c_int;
fn uu_login_ui_set_qr(rgba: *const u8, edge: libc::c_int);
fn uu_login_ui_set_status(text: *const libc::c_char, kind: libc::c_int);
fn uu_login_ui_set_done(text: *const libc::c_char);
fn uu_login_ui_closed() -> libc::c_int;
fn uu_login_ui_close();
}
#[derive(Clone, Copy)]
pub enum Tone { Info = 0, Ok = 1, Error = 2 }
pub struct LoginUi { shown: bool, attached: bool }
#[cfg(uu_gtk)]
fn cstr(s: &str) -> std::ffi::CString { std::ffi::CString::new(s.replace('\0', "")).unwrap_or_default() }
impl LoginUi {
pub fn none() -> Self { LoginUi { shown: false, attached: false } }
/// Opens the window when built with GTK and a display is present; falls back silently otherwise.
#[allow(unused_variables)]
pub fn open(name: &str, os: &str, cpu: &str, gpu: &str) -> Self {
#[cfg(uu_gtk)]
if std::env::var_os("DISPLAY").is_some() || std::env::var_os("WAYLAND_DISPLAY").is_some() {
let (n, o, c, g) = (cstr(name), cstr(os), cstr(cpu), cstr(gpu));
if unsafe { uu_login_ui_start(n.as_ptr(), o.as_ptr(), c.as_ptr(), g.as_ptr()) } == 0 {
return LoginUi { shown: true, attached: false };
}
eprintln!("Login window unavailable; using the terminal QR code");
}
LoginUi::none()
}
/// Account card of the host's own main window (already open): the QR stays in the window only
/// (a service's stdout is the journal and the QR URL is a login ticket), and dropping this
/// handle never closes the shared window.
pub fn attached() -> Self {
#[cfg(uu_gtk)]
{ unsafe { uu_login_ui_start(std::ptr::null(), std::ptr::null(), std::ptr::null(), std::ptr::null()) }; LoginUi { shown: true, attached: true } }
#[cfg(not(uu_gtk))]
LoginUi { shown: false, attached: true }
}
pub fn quiet(&self) -> bool { self.attached }
pub fn shown(&self) -> bool { self.shown }
#[allow(unused_variables)]
pub fn qr(&self, rgba: &[u8], edge: usize) {
#[cfg(uu_gtk)]
if self.shown && rgba.len() == edge * edge * 4 { unsafe { uu_login_ui_set_qr(rgba.as_ptr(), edge as libc::c_int) } }
}
#[allow(unused_variables)]
pub fn status(&self, text: &str, tone: Tone) {
#[cfg(uu_gtk)]
if self.shown { let t = cstr(text); unsafe { uu_login_ui_set_status(t.as_ptr(), tone as libc::c_int) } }
}
#[allow(unused_variables)]
pub fn done(&self, text: &str) {
#[cfg(uu_gtk)]
if self.shown { let t = cstr(text); unsafe { uu_login_ui_set_done(t.as_ptr()) } }
}
pub fn closed(&self) -> bool {
#[cfg(uu_gtk)]
if self.shown { return unsafe { uu_login_ui_closed() } != 0; }
false
}
/// Resolves when the user closes the window; never resolves without a window.
pub async fn wait_closed(&self) {
if !self.shown { return std::future::pending().await; }
while !self.closed() { tokio::time::sleep(std::time::Duration::from_millis(200)).await; }
}
}
impl Drop for LoginUi {
fn drop(&mut self) {
#[cfg(uu_gtk)]
if self.shown && !self.attached { unsafe { uu_login_ui_close() } }
}
}