mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-17 01:00:41 +01:00
fix(portal): establish desktop CONTROL while GNOME is locked and auto unlock cold connections (#30)
* fix(portal): establish locked desktop control before capture * test(portal): preserve v4 pixel inventory after deferred capture settings * fix(control): refresh lock state after viewer Echo handshake * fix(portal): announce desktop target before locked capture wait * ci: run the desktop_power native test under ASan/UBSan Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * input: skip the Portal release sweep while no session is bound The first locked connection creates its peer before any Portal exists; the sweep then logged two failed injections and a 'reset incomplete' warning for nothing. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs: describe locked cold connections, auto unlock limits and iPhone status Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * fix(portal): treat a cached screen with a closed Portal session as not ready begin() now marks the state as waiting when the cached session is dead, and permission/video/clipboard consumers honor it instead of reporting Allow and starting the stale video path before maintain() has rebuilt capture. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * fix(portal): gate input on a ready desktop and share recovery backoff Input dispatch kept only the cached screen and dropped State.waiting, so a closed Portal passed the gate once the screen unlocked. The supervisor's recover() and the encoder's stream-loss recovery now share failure backoff and a terminal-denial flag, so a denied consent is not re-prompted by the other path. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * fix(control): keep unknown lock state unlocked, stop waits on Closing, never drop capture settings - QuerySystemState with no logind lock state (Xvfb/linger) reports unlocked as before. - The Portal wait loop also exits while the channel is Closing. - Capture-setting requests back-pressure instead of try_send dropping the latest setting. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]> Co-authored-by: VallierDev <[email protected]>
This commit is contained in:
23 files changed
+2292
-207
No files matched your search
@@ -265,6 +265,8 @@ impl InputInjector {
|
||||
unsafe {x11_release_all();}
|
||||
} else if self.backend==crate::desktop_backend::DesktopBackend::Wayland && self.portal.lock().unwrap().is_none() {
|
||||
crate::wayland::release_all();
|
||||
} else if self.backend==crate::desktop_backend::DesktopBackend::Portal && self.portal.lock().unwrap().is_none() {
|
||||
// Nothing is bound yet (e.g. the first locked connection): no input can be held.
|
||||
} else {
|
||||
// Portal/Wayland cannot query global state. Sweep every key/button
|
||||
// that this host can emit through the currently bound session.
|
||||
@@ -445,6 +447,15 @@ impl InputInjector {
|
||||
}
|
||||
}
|
||||
impl DesktopInputSession {
|
||||
pub fn is_current(&self) -> bool {
|
||||
let owner = self.input.owner.lock().unwrap();
|
||||
owner.owns(self.id)
|
||||
}
|
||||
/// Call only inside with_current or with_input, so a superseded peer cannot change bindings.
|
||||
pub fn bind_portal(&self, portal: Option<std::sync::Arc<crate::portal::PortalSession>>) {
|
||||
self.input.bind_portal(portal);
|
||||
}
|
||||
pub fn release_input(&self) { self.input.release_held(); }
|
||||
pub fn connected(&self) {
|
||||
let mut owner=self.input.owner.lock().unwrap();
|
||||
if owner.owns(self.id) && !owner.active {self.input.release_held();owner.active=true;}
|
||||
@@ -453,6 +464,11 @@ impl DesktopInputSession {
|
||||
let mut owner=self.input.owner.lock().unwrap();
|
||||
if owner.owns(self.id) && owner.active {owner.active=false;self.input.release_held();}
|
||||
}
|
||||
/// Lifecycle updates survive a transient disconnect, but serialize with replacement and shutdown.
|
||||
pub fn with_current(&self, action:impl FnOnce()) {
|
||||
let owner=self.input.owner.lock().unwrap();
|
||||
if owner.owns(self.id) {action();}
|
||||
}
|
||||
pub fn with_input(&self, action:impl FnOnce()) {
|
||||
let owner=self.input.owner.lock().unwrap();
|
||||
if owner.owns(self.id) && owner.active {action();}
|
||||
@@ -460,11 +476,62 @@ impl DesktopInputSession {
|
||||
}
|
||||
impl Drop for DesktopInputSession {fn drop(&mut self) {self.disconnected();}}
|
||||
|
||||
#[cfg(test)]
|
||||
impl InputInjector {
|
||||
pub fn without_desktop() -> Self {
|
||||
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:None, 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::DesktopBackend::Portal,
|
||||
pending:std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod lifecycle_tests {
|
||||
use super::*;
|
||||
use std::sync::{Arc,atomic::{AtomicUsize,Ordering}};
|
||||
#[test]
|
||||
fn current_owner_can_publish_while_disconnected_but_cannot_inject() {
|
||||
let input=Arc::new(InputInjector::without_desktop());
|
||||
let session=input.desktop_session();
|
||||
session.connected();session.disconnected();
|
||||
let publications=AtomicUsize::new(0);
|
||||
session.with_current(||{publications.fetch_add(1,Ordering::Relaxed);});
|
||||
session.with_input(||panic!("disconnected owner must not inject"));
|
||||
assert_eq!(publications.load(Ordering::Relaxed),1);
|
||||
session.connected();
|
||||
session.with_input(||{publications.fetch_add(1,Ordering::Relaxed);});
|
||||
let next=input.desktop_session();
|
||||
session.with_current(||panic!("replaced owner must not publish"));
|
||||
next.with_current(||{publications.fetch_add(1,Ordering::Relaxed);});
|
||||
input.shutdown();
|
||||
next.with_current(||panic!("shutdown must reject lifecycle updates"));
|
||||
assert_eq!(publications.load(Ordering::Relaxed),3);
|
||||
}
|
||||
#[test]
|
||||
fn current_owner_gate_holds_ownership_through_publication() {
|
||||
let input=Arc::new(InputInjector::without_desktop());
|
||||
let session=input.desktop_session();
|
||||
let (started,ready)=std::sync::mpsc::channel();
|
||||
let (finish,resume)=std::sync::mpsc::channel();
|
||||
let worker=session.clone();
|
||||
let publication=std::thread::spawn(move ||worker.with_current(|| {
|
||||
started.send(()).unwrap();resume.recv().unwrap();
|
||||
}));
|
||||
ready.recv_timeout(std::time::Duration::from_secs(2)).unwrap();
|
||||
assert!(input.owner.try_lock().is_err());
|
||||
let replacing=input.clone();
|
||||
let replacement=std::thread::spawn(move ||replacing.desktop_session());
|
||||
finish.send(()).unwrap();
|
||||
publication.join().unwrap();
|
||||
let next=replacement.join().unwrap();
|
||||
assert!(next.is_current());
|
||||
session.with_current(||panic!("late publication after replacement"));
|
||||
}
|
||||
#[test]
|
||||
fn cleanup_discards_motion_shortcuts_and_untracked_input_ledger() {
|
||||
let input=Arc::new(InputInjector::new());
|
||||
input.held.lock().unwrap().keys.insert(0xffe1);
|
||||
|
||||
Reference in new issue
Block a user