mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-11 07:10:54 +03:00
improve capture error handling
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user