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

@@ -6,6 +6,8 @@ use futures_core::Stream;
use input_event::Event;
use crate::CaptureError;
use super::{CaptureHandle, InputCapture, Position};
pub struct DummyInputCapture {}
@@ -37,7 +39,7 @@ impl InputCapture for DummyInputCapture {
}
impl Stream for DummyInputCapture {
type Item = io::Result<(CaptureHandle, Event)>;
type Item = Result<(CaptureHandle, Event), CaptureError>;
fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Pending

View File

@@ -92,7 +92,9 @@ impl Display for Backend {
}
}
pub trait InputCapture: Stream<Item = io::Result<(CaptureHandle, Event)>> + Unpin {
pub trait InputCapture:
Stream<Item = Result<(CaptureHandle, Event), CaptureError>> + Unpin
{
/// create a new client with the given id
fn create(&mut self, id: CaptureHandle, pos: Position) -> io::Result<()>;
@@ -105,8 +107,10 @@ pub trait InputCapture: Stream<Item = io::Result<(CaptureHandle, Event)>> + Unpi
pub async fn create_backend(
backend: Backend,
) -> Result<Box<dyn InputCapture<Item = io::Result<(CaptureHandle, Event)>>>, CaptureCreationError>
{
) -> Result<
Box<dyn InputCapture<Item = Result<(CaptureHandle, Event), CaptureError>>>,
CaptureCreationError,
> {
match backend {
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
Backend::InputCapturePortal => Ok(Box::new(libei::LibeiInputCapture::new().await?)),
@@ -124,8 +128,10 @@ pub async fn create_backend(
pub async fn create(
backend: Option<Backend>,
) -> Result<Box<dyn InputCapture<Item = io::Result<(CaptureHandle, Event)>>>, CaptureCreationError>
{
) -> Result<
Box<dyn InputCapture<Item = Result<(CaptureHandle, Event), CaptureError>>>,
CaptureCreationError,
> {
if let Some(backend) = backend {
let b = create_backend(backend).await;
if b.is_ok() {

View File

@@ -5,7 +5,7 @@ use ashpd::{
},
enumflags2::BitFlags,
};
use futures::StreamExt;
use futures::{FutureExt, StreamExt};
use reis::{
ei::{self, keyboard::KeyState},
eis::button::ButtonState,
@@ -17,9 +17,9 @@ use std::{
collections::HashMap,
io,
os::unix::net::UnixStream,
pin::Pin,
pin::{pin, Pin},
rc::Rc,
task::{ready, Context, Poll},
task::{Context, Poll},
};
use tokio::{
sync::mpsc::{Receiver, Sender},
@@ -192,7 +192,7 @@ async fn libei_event_handler(
.map_err(ReisConvertEventStreamError::from)?;
log::trace!("from ei: {ei_event:?}");
let client = current_client.get();
handle_ei_event(ei_event, client, &context, &event_tx).await;
handle_ei_event(ei_event, client, &context, &event_tx).await?;
}
}
@@ -252,10 +252,9 @@ async fn do_capture<'a>(
if active_clients.is_empty() {
wait_for_active_client(&mut notify_rx, &mut active_clients).await;
if notify_rx.is_closed() {
break Ok(());
} else {
continue;
break;
}
continue;
}
let current_client = Rc::new(Cell::new(None));
@@ -270,13 +269,12 @@ async fn do_capture<'a>(
let (context, ei_event_stream) = connect_to_eis(input_capture, &session).await?;
// async event task
let mut ei_task: JoinHandle<Result<(), CaptureError>> =
tokio::task::spawn_local(libei_event_handler(
ei_event_stream,
context,
event_tx.clone(),
current_client.clone(),
));
let mut ei_task = pin!(libei_event_handler(
ei_event_stream,
context,
event_tx.clone(),
current_client.clone(),
));
let mut activated = input_capture.receive_activated().await?;
let mut zones_changed = input_capture.receive_zones_changed().await?;
@@ -320,10 +318,8 @@ async fn do_capture<'a>(
break;
}
res = &mut ei_task => {
if let Err(e) = res.expect("ei task paniced") {
log::warn!("libei task exited: {e}");
}
break;
/* propagate errors to toplevel task */
res?;
}
}
release_capture(
@@ -342,19 +338,16 @@ async fn do_capture<'a>(
}
},
res = &mut ei_task => {
if let Err(e) = res.expect("ei task paniced") {
log::warn!("libei task exited: {e}");
}
break;
res?;
}
}
}
ei_task.abort();
input_capture.disable(&session).await?;
if event_tx.is_closed() {
break Ok(());
break;
}
}
Ok(())
}
async fn release_capture(
@@ -410,7 +403,7 @@ async fn handle_ei_event(
current_client: Option<CaptureHandle>,
context: &ei::Context,
event_tx: &Sender<(CaptureHandle, Event)>,
) {
) -> Result<(), CaptureError> {
match ei_event {
EiEvent::SeatAdded(s) => {
s.seat.bind_capabilities(&[
@@ -421,7 +414,7 @@ async fn handle_ei_event(
DeviceCapability::Scroll,
DeviceCapability::Button,
]);
context.flush().unwrap();
context.flush().map_err(|e| io::Error::new(e.kind(), e))?;
}
EiEvent::SeatRemoved(_) => {}
EiEvent::DeviceAdded(_) => {}
@@ -439,7 +432,7 @@ async fn handle_ei_event(
event_tx
.send((current_client, Event::Keyboard(modifier_event)))
.await
.unwrap();
.map_err(|_| CaptureError::EndOfStream)?;
}
}
EiEvent::Frame(_) => {}
@@ -459,7 +452,7 @@ async fn handle_ei_event(
event_tx
.send((current_client, Event::Pointer(motion_event)))
.await
.unwrap();
.map_err(|_| CaptureError::EndOfStream)?;
}
}
EiEvent::PointerMotionAbsolute(_) => {}
@@ -476,7 +469,7 @@ async fn handle_ei_event(
event_tx
.send((current_client, Event::Pointer(button_event)))
.await
.unwrap();
.map_err(|_| CaptureError::EndOfStream)?;
}
}
EiEvent::ScrollDelta(delta) => {
@@ -500,7 +493,7 @@ async fn handle_ei_event(
event_tx
.send((handle, Event::Pointer(event)))
.await
.unwrap();
.map_err(|_| CaptureError::EndOfStream)?;
}
}
}
@@ -516,7 +509,7 @@ async fn handle_ei_event(
event_tx
.send((current_client, Event::Pointer(event)))
.await
.unwrap();
.map_err(|_| CaptureError::EndOfStream)?;
}
}
if scroll.discrete_dx != 0 {
@@ -528,7 +521,7 @@ async fn handle_ei_event(
event_tx
.send((current_client, Event::Pointer(event)))
.await
.unwrap();
.map_err(|_| CaptureError::EndOfStream)?;
}
};
}
@@ -545,7 +538,7 @@ async fn handle_ei_event(
event_tx
.send((current_client, Event::Keyboard(key_event)))
.await
.unwrap();
.map_err(|_| CaptureError::EndOfStream)?;
}
}
EiEvent::TouchDown(_) => {}
@@ -555,6 +548,7 @@ async fn handle_ei_event(
log::error!("disconnect: {d:?}");
}
}
Ok(())
}
impl<'a> LanMouseInputCapture for LibeiInputCapture<'a> {
@@ -584,12 +578,15 @@ impl<'a> LanMouseInputCapture for LibeiInputCapture<'a> {
}
impl<'a> Stream for LibeiInputCapture<'a> {
type Item = io::Result<(CaptureHandle, Event)>;
type Item = Result<(CaptureHandle, Event), CaptureError>;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match ready!(self.event_rx.poll_recv(cx)) {
None => Poll::Ready(None),
Some(e) => Poll::Ready(Some(Ok(e))),
match self.libei_task.poll_unpin(cx) {
Poll::Ready(r) => match r.expect("failed to join") {
Ok(()) => Poll::Ready(None),
Err(e) => Poll::Ready(Some(Err(e))),
},
Poll::Pending => self.event_rx.poll_recv(cx).map(|e| e.map(Result::Ok)),
}
}
}

View File

@@ -1,4 +1,6 @@
use crate::{error::MacOSInputCaptureCreationError, CaptureHandle, InputCapture, Position};
use crate::{
error::MacOSInputCaptureCreationError, CaptureError, CaptureHandle, InputCapture, Position,
};
use futures_core::Stream;
use input_event::Event;
use std::task::{Context, Poll};
@@ -13,7 +15,7 @@ impl MacOSInputCapture {
}
impl Stream for MacOSInputCapture {
type Item = io::Result<(CaptureHandle, Event)>;
type Item = Result<(CaptureHandle, Event), CaptureError>;
fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Pending

View File

@@ -62,6 +62,8 @@ use tempfile;
use input_event::{Event, KeyboardEvent, PointerEvent};
use crate::CaptureError;
use super::{
error::{LayerShellCaptureCreationError, WaylandBindError},
CaptureHandle, InputCapture, Position,
@@ -582,7 +584,7 @@ impl InputCapture for WaylandInputCapture {
}
impl Stream for WaylandInputCapture {
type Item = io::Result<(CaptureHandle, Event)>;
type Item = Result<(CaptureHandle, Event), CaptureError>;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
if let Some(event) = self.0.get_mut().state.pending_events.pop_front() {
@@ -600,7 +602,7 @@ impl Stream for WaylandInputCapture {
// prepare next read
match inner.prepare_read() {
Ok(_) => {}
Err(e) => return Poll::Ready(Some(Err(e))),
Err(e) => return Poll::Ready(Some(Err(e.into()))),
}
}
@@ -610,14 +612,14 @@ impl Stream for WaylandInputCapture {
// flush outgoing events
if let Err(e) = inner.flush_events() {
if e.kind() != ErrorKind::WouldBlock {
return Poll::Ready(Some(Err(e)));
return Poll::Ready(Some(Err(e.into())));
}
}
// prepare for the next read
match inner.prepare_read() {
Ok(_) => {}
Err(e) => return Poll::Ready(Some(Err(e))),
Err(e) => return Poll::Ready(Some(Err(e.into()))),
}
}

View File

@@ -36,7 +36,7 @@ use input_event::{
Event, KeyboardEvent, PointerEvent, BTN_BACK, BTN_FORWARD, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT,
};
use super::{CaptureHandle, InputCapture, Position};
use super::{CaptureError, CaptureHandle, InputCapture, Position};
enum Request {
Create(CaptureHandle, Position),
@@ -609,7 +609,7 @@ impl WindowsInputCapture {
}
impl Stream for WindowsInputCapture {
type Item = io::Result<(CaptureHandle, Event)>;
type Item = Result<(CaptureHandle, Event), CaptureError>;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match ready!(self.event_rx.poll_recv(cx)) {
None => Poll::Ready(None),

View File

@@ -3,6 +3,8 @@ use std::task::Poll;
use futures_core::Stream;
use crate::CaptureError;
use super::InputCapture;
use input_event::Event;
@@ -32,7 +34,7 @@ impl InputCapture for X11InputCapture {
}
impl Stream for X11InputCapture {
type Item = io::Result<(CaptureHandle, Event)>;
type Item = Result<(CaptureHandle, Event), CaptureError>;
fn poll_next(
self: std::pin::Pin<&mut Self>,

View File

@@ -1,167 +1,186 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="libadwaita" version="1.0"/>
<menu id="main-menu">
<item>
<attribute name="label" translatable="yes">_Close window</attribute>
<attribute name="action">window.close</attribute>
</item>
</menu>
<template class="LanMouseWindow" parent="AdwApplicationWindow">
<property name="width-request">600</property>
<property name="height-request">700</property>
<property name="title" translatable="yes">Lan Mouse</property>
<property name="show-menubar">True</property>
<property name="content">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child type="top">
<object class="AdwHeaderBar">
<child type ="end">
<object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property>
<property name="menu-model">main-menu</property>
</object>
</child>
<style>
<class name="flat"/>
</style>
</object>
</child>
<child>
<object class="AdwToastOverlay" id="toast_overlay">
<child>
<object class="AdwStatusPage">
<property name="title" translatable="yes">Lan Mouse</property>
<property name="description" translatable="yes">easily use your mouse and keyboard on multiple computers</property>
<property name="icon-name">de.feschber.LanMouse</property>
<property name="child">
<object class="AdwClamp">
<property name="maximum-size">600</property>
<property name="tightening-threshold">0</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">General</property>
<!--
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">enable</property>
<child type="suffix">
<object class="GtkSwitch">
<property name="valign">center</property>
<property name="tooltip-text" translatable="yes">enable</property>
</object>
</child>
</object>
</child>
-->
<child>
<object class="AdwActionRow">
<property name="title">port</property>
<child>
<object class="GtkEntry" id="port_entry">
<signal name="activate" handler="handle_port_edit_apply" swapped="true"/>
<signal name="changed" handler="handle_port_changed" swapped="true"/>
<!-- <signal name="delete-text" handler="handle_port_changed" swapped="true"/> -->
<!-- <property name="title" translatable="yes">port</property> -->
<property name="placeholder-text">4242</property>
<property name="width-chars">5</property>
<property name="xalign">0.5</property>
<property name="valign">center</property>
<!-- <property name="show-apply-button">True</property> -->
<property name="input-purpose">GTK_INPUT_PURPOSE_DIGITS</property>
</object>
</child>
<child>
<object class="GtkButton" id="port_edit_apply">
<signal name="clicked" handler="handle_port_edit_apply" swapped="true"/>
<property name="icon-name">object-select-symbolic</property>
<property name="valign">center</property>
<property name="visible">false</property>
<property name="name">port-edit-apply</property>
<style><class name="success"/></style>
</object>
</child>
<child>
<object class="GtkButton" id="port_edit_cancel">
<signal name="clicked" handler="handle_port_edit_cancel" swapped="true"/>
<property name="icon-name">process-stop-symbolic</property>
<property name="valign">center</property>
<property name="visible">false</property>
<property name="name">port-edit-cancel</property>
<style><class name="error"/></style>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title">hostname</property>
<child>
<object class="GtkLabel" id="hostname_label">
<property name="label">&lt;span font_style=&quot;italic&quot; font_weight=&quot;light&quot; foreground=&quot;darkgrey&quot;&gt;could not determine hostname&lt;/span&gt;</property>
<property name="use-markup">true</property>
<property name="valign">center</property>
</object>
</child>
<child>
<object class="GtkButton" id="copy-hostname-button">
<property name="icon-name">edit-copy-symbolic</property>
<property name="valign">center</property>
<signal name="clicked" handler="handle_copy_hostname" swapped="true"/>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Connections</property>
<property name="header-suffix">
<object class="GtkButton">
<signal name="clicked" handler="handle_add_client_pressed" swapped="true"/>
<property name="child">
<object class="AdwButtonContent">
<property name="icon-name">list-add-symbolic</property>
<property name="label" translatable="yes">Add</property>
</object>
</property>
<style>
<class name="flat"/>
</style>
</object>
</property>
<child>
<object class="GtkListBox" id="client_list">
<property name="selection-mode">none</property>
<child type="placeholder">
<object class="AdwActionRow" id="client_placeholder">
<property name="title">No connections!</property>
<property name="subtitle">add a new client via the + button</property>
</object>
</child>
<style>
<class name="boxed-list" />
</style>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</property>
</template>
<requires lib="gtk" version="4.0"/>
<requires lib="libadwaita" version="1.0"/>
<menu id="main-menu">
<item>
<attribute name="label" translatable="yes">_Close window</attribute>
<attribute name="action">window.close</attribute>
</item>
</menu>
<template class="LanMouseWindow" parent="AdwApplicationWindow">
<property name="width-request">600</property>
<property name="height-request">700</property>
<property name="title" translatable="yes">Lan Mouse</property>
<property name="show-menubar">True</property>
<property name="content">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child type="top">
<object class="AdwHeaderBar">
<child type ="end">
<object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property>
<property name="menu-model">main-menu</property>
</object>
</child>
<style>
<class name="flat"/>
</style>
</object>
</child>
<child>
<object class="AdwToastOverlay" id="toast_overlay">
<child>
<object class="AdwStatusPage">
<property name="title" translatable="yes">Lan Mouse</property>
<property name="description" translatable="yes">easily use your mouse and keyboard on multiple computers</property>
<property name="icon-name">de.feschber.LanMouse</property>
<property name="child">
<object class="AdwClamp">
<property name="maximum-size">600</property>
<property name="tightening-threshold">0</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">General</property>
<!--
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">enable</property>
<child type="suffix">
<object class="GtkSwitch">
<property name="valign">center</property>
<property name="tooltip-text" translatable="yes">enable</property>
</object>
</child>
</object>
</child>
-->
<child>
<object class="AdwActionRow">
<property name="title">port</property>
<child>
<object class="GtkEntry" id="port_entry">
<signal name="activate" handler="handle_port_edit_apply" swapped="true"/>
<signal name="changed" handler="handle_port_changed" swapped="true"/>
<!-- <signal name="delete-text" handler="handle_port_changed" swapped="true"/> -->
<!-- <property name="title" translatable="yes">port</property> -->
<property name="placeholder-text">4242</property>
<property name="width-chars">5</property>
<property name="xalign">0.5</property>
<property name="valign">center</property>
<!-- <property name="show-apply-button">True</property> -->
<property name="input-purpose">GTK_INPUT_PURPOSE_DIGITS</property>
</object>
</child>
<child>
<object class="GtkButton" id="port_edit_apply">
<signal name="clicked" handler="handle_port_edit_apply" swapped="true"/>
<property name="icon-name">object-select-symbolic</property>
<property name="valign">center</property>
<property name="visible">false</property>
<property name="name">port-edit-apply</property>
<style><class name="success"/></style>
</object>
</child>
<child>
<object class="GtkButton" id="port_edit_cancel">
<signal name="clicked" handler="handle_port_edit_cancel" swapped="true"/>
<property name="icon-name">process-stop-symbolic</property>
<property name="valign">center</property>
<property name="visible">false</property>
<property name="name">port-edit-cancel</property>
<style><class name="error"/></style>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title">hostname</property>
<child>
<object class="GtkLabel" id="hostname_label">
<property name="label">&lt;span font_style=&quot;italic&quot; font_weight=&quot;light&quot; foreground=&quot;darkgrey&quot;&gt;could not determine hostname&lt;/span&gt;</property>
<property name="use-markup">true</property>
<property name="valign">center</property>
</object>
</child>
<child>
<object class="GtkButton" id="copy-hostname-button">
<property name="icon-name">edit-copy-symbolic</property>
<property name="valign">center</property>
<signal name="clicked" handler="handle_copy_hostname" swapped="true"/>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title">capture / emulation status</property>
<child>
<object class="GtkButton" id="input_emulation_button">
<property name="icon-name">input-mouse-symbolic</property>
<property name="valign">center</property>
<signal name="clicked" handler="handle_emulation" swapped="true"/>
</object>
</child>
<child>
<object class="GtkButton" id="input_capture_button">
<property name="icon-name">input-mouse-symbolic</property>
<property name="valign">center</property>
<signal name="clicked" handler="handle_capture" swapped="true"/>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Connections</property>
<property name="header-suffix">
<object class="GtkButton">
<signal name="clicked" handler="handle_add_client_pressed" swapped="true"/>
<property name="child">
<object class="AdwButtonContent">
<property name="icon-name">list-add-symbolic</property>
<property name="label" translatable="yes">Add</property>
</object>
</property>
<style>
<class name="flat"/>
</style>
</object>
</property>
<child>
<object class="GtkListBox" id="client_list">
<property name="selection-mode">none</property>
<child type="placeholder">
<object class="AdwActionRow" id="client_placeholder">
<property name="title">No connections!</property>
<property name="subtitle">add a new client via the + button</property>
</object>
</child>
<style>
<class name="boxed-list" />
</style>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</property>
</template>
</interface>

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;