mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 11:59:59 +03:00
solve clippy except tomanyargs
This commit is contained in:
@@ -26,7 +26,7 @@ impl Default for DummyInputCapture {
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> InputCapture for DummyInputCapture {
|
||||
impl InputCapture for DummyInputCapture {
|
||||
async fn create(&mut self, _handle: CaptureHandle, _pos: Position) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -312,9 +312,7 @@ async fn do_capture<'a>(
|
||||
}
|
||||
|
||||
// propagate error from capture session
|
||||
if capture_result.is_err() {
|
||||
return capture_result;
|
||||
}
|
||||
capture_result?;
|
||||
} else {
|
||||
handle_session_update_request.await;
|
||||
}
|
||||
@@ -352,7 +350,7 @@ async fn do_capture_session(
|
||||
|
||||
// set barriers
|
||||
let client_for_barrier_id =
|
||||
update_barriers(input_capture, session, &active_clients, next_barrier_id).await?;
|
||||
update_barriers(input_capture, session, active_clients, next_barrier_id).await?;
|
||||
|
||||
log::debug!("enabling session");
|
||||
input_capture.enable(session).await?;
|
||||
@@ -410,7 +408,7 @@ async fn do_capture_session(
|
||||
_ = cancel_session.cancelled() => break, /* kill session notify */
|
||||
}
|
||||
|
||||
release_capture(input_capture, session, activated, client, &active_clients).await?;
|
||||
release_capture(input_capture, session, activated, client, active_clients).await?;
|
||||
|
||||
}
|
||||
_ = capture_session_event.recv() => {}, /* capture release -> we are not capturing anyway, so ignore */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::config::Config;
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::Result;
|
||||
use futures::StreamExt;
|
||||
use input_capture::{self, Position};
|
||||
use input_capture::{self, CaptureError, InputCapture, Position};
|
||||
use input_event::{Event, KeyboardEvent};
|
||||
use tokio::task::LocalSet;
|
||||
|
||||
@@ -20,49 +20,36 @@ pub fn run() -> Result<()> {
|
||||
async fn input_capture_test(config: Config) -> Result<()> {
|
||||
log::info!("creating input capture");
|
||||
let backend = config.capture_backend.map(|b| b.into());
|
||||
for _ in 0..2 {
|
||||
let mut input_capture = Some(input_capture::create(backend).await?);
|
||||
loop {
|
||||
let mut input_capture = input_capture::create(backend).await?;
|
||||
log::info!("creating clients");
|
||||
input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.create(0, Position::Left)
|
||||
.await?;
|
||||
input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.create(1, Position::Right)
|
||||
.await?;
|
||||
input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.create(2, Position::Top)
|
||||
.await?;
|
||||
input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.create(3, Position::Bottom)
|
||||
.await?;
|
||||
loop {
|
||||
let (client, event) = input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.next()
|
||||
.await
|
||||
.ok_or(anyhow!("capture stream closed"))??;
|
||||
let pos = match client {
|
||||
0 => Position::Left,
|
||||
1 => Position::Right,
|
||||
2 => Position::Top,
|
||||
_ => Position::Bottom,
|
||||
};
|
||||
log::info!("position: {pos}, event: {event}");
|
||||
if let Event::Keyboard(KeyboardEvent::Key { key: 1, .. }) = event {
|
||||
input_capture.as_mut().unwrap().release().await?;
|
||||
// break;
|
||||
}
|
||||
input_capture.create(0, Position::Left).await?;
|
||||
input_capture.create(1, Position::Right).await?;
|
||||
input_capture.create(2, Position::Top).await?;
|
||||
input_capture.create(3, Position::Bottom).await?;
|
||||
if let Err(e) = do_capture(&mut input_capture).await {
|
||||
log::warn!("{e} - recreating capture");
|
||||
let _ = input_capture.terminate().await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn do_capture(input_capture: &mut Box<dyn InputCapture>) -> Result<(), CaptureError> {
|
||||
loop {
|
||||
let (client, event) = input_capture
|
||||
.next()
|
||||
.await
|
||||
.ok_or(CaptureError::EndOfStream)??;
|
||||
let pos = match client {
|
||||
0 => Position::Left,
|
||||
1 => Position::Right,
|
||||
2 => Position::Top,
|
||||
_ => Position::Bottom,
|
||||
};
|
||||
log::info!("position: {pos}, event: {event}");
|
||||
if let Event::Keyboard(KeyboardEvent::Key { key: 1, .. }) = event {
|
||||
input_capture.release().await?;
|
||||
break Ok(());
|
||||
}
|
||||
// input_capture.take().unwrap().terminate().await.unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -117,42 +117,47 @@ async fn handle_capture_event(
|
||||
}
|
||||
}
|
||||
|
||||
let (addr, enter, start_timer) = {
|
||||
let info = {
|
||||
let mut enter = false;
|
||||
let mut start_timer = false;
|
||||
|
||||
// get client state for handle
|
||||
let mut client_manager = server.client_manager.borrow_mut();
|
||||
let client_state = match client_manager.get_mut(handle) {
|
||||
Some((_, s)) => s,
|
||||
None => {
|
||||
// should not happen
|
||||
log::warn!("unknown client!");
|
||||
capture.release().await?;
|
||||
server.state.replace(State::Receiving);
|
||||
log::trace!("STATE ===> Receiving");
|
||||
return Ok(());
|
||||
let client_state = client_manager.get_mut(handle).map(|(_, s)| s);
|
||||
if let Some(client_state) = client_state {
|
||||
// if we just entered the client we want to send additional enter events until
|
||||
// we get a leave event
|
||||
if let Event::Enter() = e {
|
||||
server.state.replace(State::AwaitingLeave);
|
||||
server.active_client.replace(Some(handle));
|
||||
log::trace!("Active client => {}", handle);
|
||||
start_timer = true;
|
||||
log::trace!("STATE ===> AwaitingLeave");
|
||||
enter = true;
|
||||
} else {
|
||||
// ignore any potential events in receiving mode
|
||||
if server.state.get() == State::Receiving && e != Event::Disconnect() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// if we just entered the client we want to send additional enter events until
|
||||
// we get a leave event
|
||||
if let Event::Enter() = e {
|
||||
server.state.replace(State::AwaitingLeave);
|
||||
server.active_client.replace(Some(handle));
|
||||
log::trace!("Active client => {}", handle);
|
||||
start_timer = true;
|
||||
log::trace!("STATE ===> AwaitingLeave");
|
||||
enter = true;
|
||||
Some((client_state.active_addr, enter, start_timer))
|
||||
} else {
|
||||
// ignore any potential events in receiving mode
|
||||
if server.state.get() == State::Receiving && e != Event::Disconnect() {
|
||||
return Ok(());
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
(client_state.active_addr, enter, start_timer)
|
||||
};
|
||||
|
||||
let (addr, enter, start_timer) = match info {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
// should not happen
|
||||
log::warn!("unknown client!");
|
||||
capture.release().await?;
|
||||
server.state.replace(State::Receiving);
|
||||
log::trace!("STATE ===> Receiving");
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
if start_timer {
|
||||
timer_notify.notify_waiters();
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ fn handle_frontend_stream(
|
||||
let tx = frontend_tx.clone();
|
||||
tokio::task::spawn_local(async move {
|
||||
tokio::select! {
|
||||
_ = listen_frontend(tx, stream) => return,
|
||||
_ = cancellation_token.cancelled() => return,
|
||||
_ = listen_frontend(tx, stream) => {},
|
||||
_ = cancellation_token.cancelled() => {},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user