improve capture error handling

This commit is contained in:
Ferdinand Schober
2024-07-10 09:00:43 +02:00
parent 6a4dd740c3
commit 110b37e26e
14 changed files with 296 additions and 216 deletions

View File

@@ -109,6 +109,10 @@ pub enum FrontendRequest {
UpdateFixIps(ClientHandle, Vec<IpAddr>),
/// request the state of the given client
GetState(ClientHandle),
/// request reenabling input capture
EnableCapture,
/// request reenabling input emulation
EnableEmulation,
}
#[derive(Debug, Clone, Serialize, Deserialize)]

View File

@@ -215,6 +215,13 @@ impl Window {
}
}
pub fn request_capture(&self) {
self.request(FrontendRequest::EnableCapture);
}
pub fn request_emulation(&self) {
self.request(FrontendRequest::EnableEmulation);
}
pub fn request_client_state(&self, client: &ClientObject) {
let handle = client.handle();
let event = FrontendRequest::GetState(handle);

View File

@@ -30,6 +30,10 @@ pub struct Window {
pub hostname_label: TemplateChild<Label>,
#[template_child]
pub toast_overlay: TemplateChild<ToastOverlay>,
#[template_child]
pub input_emulation_button: TemplateChild<Button>,
#[template_child]
pub input_capture_button: TemplateChild<Button>,
pub clients: RefCell<Option<gio::ListStore>>,
#[cfg(unix)]
pub stream: RefCell<Option<UnixStream>>,
@@ -100,6 +104,17 @@ impl Window {
self.port_edit_cancel.set_visible(false);
}
#[template_callback]
fn handle_emulation(&self) {
self.obj().request_emulation();
}
#[template_callback]
fn handle_capture(&self) {
log::info!("requesting capture");
self.obj().request_capture();
}
pub fn set_port(&self, port: u16) {
self.port.set(port);
if port == DEFAULT_PORT {

View File

@@ -22,6 +22,8 @@ pub enum CaptureEvent {
Destroy(CaptureHandle),
/// termination signal
Terminate,
/// restart input capture
Restart,
}
pub fn new(
@@ -55,6 +57,13 @@ pub fn new(
}
CaptureEvent::Create(h, p) => capture.create(h, p)?,
CaptureEvent::Destroy(h) => capture.destroy(h)?,
CaptureEvent::Restart => {
let clients = server.client_manager.borrow().get_client_states().map(|(h, (c,_))| (h, c.pos)).collect::<Vec<_>>();
capture = input_capture::create(backend).await?;
for (handle, pos) in clients {
capture.create(handle, pos.into())?;
}
}
CaptureEvent::Terminate => break,
},
None => break,

View File

@@ -30,6 +30,8 @@ pub enum EmulationEvent {
ReleaseKeys(ClientHandle),
/// termination signal
Terminate,
/// restart input emulation
Restart,
}
pub fn new(
@@ -90,6 +92,13 @@ async fn emulation_task(
EmulationEvent::Create(h) => emulation.create(h).await,
EmulationEvent::Destroy(h) => emulation.destroy(h).await,
EmulationEvent::ReleaseKeys(c) => release_keys(&server, &mut emulation, c).await?,
EmulationEvent::Restart => {
let clients = server.client_manager.borrow().get_client_states().map(|(h, _)| h).collect::<Vec<_>>();
emulation = input_emulation::create(backend).await?;
for handle in clients {
emulation.create(handle).await;
}
},
EmulationEvent::Terminate => break,
},
None => break,

View File

@@ -106,6 +106,12 @@ async fn handle_frontend_event(
) -> bool {
log::debug!("frontend: {event:?}");
match event {
FrontendRequest::EnableCapture => {
let _ = capture.send(CaptureEvent::Restart).await;
}
FrontendRequest::EnableEmulation => {
let _ = emulate.send(EmulationEvent::Restart).await;
}
FrontendRequest::Create => {
let handle = add_client(server, frontend).await;
resolve_dns(server, resolve_tx, handle).await;