solve clippy except tomanyargs

This commit is contained in:
Ferdinand Schober
2024-07-11 01:14:35 +02:00
parent 3f7dae65a2
commit 252547dfdb
5 changed files with 69 additions and 79 deletions

View File

@@ -26,7 +26,7 @@ impl Default for DummyInputCapture {
} }
#[async_trait] #[async_trait]
impl<'a> InputCapture for DummyInputCapture { impl InputCapture for DummyInputCapture {
async fn create(&mut self, _handle: CaptureHandle, _pos: Position) -> io::Result<()> { async fn create(&mut self, _handle: CaptureHandle, _pos: Position) -> io::Result<()> {
Ok(()) Ok(())
} }

View File

@@ -312,9 +312,7 @@ async fn do_capture<'a>(
} }
// propagate error from capture session // propagate error from capture session
if capture_result.is_err() { capture_result?;
return capture_result;
}
} else { } else {
handle_session_update_request.await; handle_session_update_request.await;
} }
@@ -352,7 +350,7 @@ async fn do_capture_session(
// set barriers // set barriers
let client_for_barrier_id = 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"); log::debug!("enabling session");
input_capture.enable(session).await?; input_capture.enable(session).await?;
@@ -410,7 +408,7 @@ async fn do_capture_session(
_ = cancel_session.cancelled() => break, /* kill session notify */ _ = 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 */ _ = capture_session_event.recv() => {}, /* capture release -> we are not capturing anyway, so ignore */

View File

@@ -1,7 +1,7 @@
use crate::config::Config; use crate::config::Config;
use anyhow::{anyhow, Result}; use anyhow::Result;
use futures::StreamExt; use futures::StreamExt;
use input_capture::{self, Position}; use input_capture::{self, CaptureError, InputCapture, Position};
use input_event::{Event, KeyboardEvent}; use input_event::{Event, KeyboardEvent};
use tokio::task::LocalSet; use tokio::task::LocalSet;
@@ -20,36 +20,26 @@ pub fn run() -> Result<()> {
async fn input_capture_test(config: Config) -> Result<()> { async fn input_capture_test(config: Config) -> Result<()> {
log::info!("creating input capture"); log::info!("creating input capture");
let backend = config.capture_backend.map(|b| b.into()); let backend = config.capture_backend.map(|b| b.into());
for _ in 0..2 { loop {
let mut input_capture = Some(input_capture::create(backend).await?); let mut input_capture = input_capture::create(backend).await?;
log::info!("creating clients"); log::info!("creating clients");
input_capture input_capture.create(0, Position::Left).await?;
.as_mut() input_capture.create(1, Position::Right).await?;
.unwrap() input_capture.create(2, Position::Top).await?;
.create(0, Position::Left) input_capture.create(3, Position::Bottom).await?;
.await?; if let Err(e) = do_capture(&mut input_capture).await {
input_capture log::warn!("{e} - recreating capture");
.as_mut() let _ = input_capture.terminate().await;
.unwrap() }
.create(1, Position::Right) }
.await?; }
input_capture
.as_mut() async fn do_capture(input_capture: &mut Box<dyn InputCapture>) -> Result<(), CaptureError> {
.unwrap()
.create(2, Position::Top)
.await?;
input_capture
.as_mut()
.unwrap()
.create(3, Position::Bottom)
.await?;
loop { loop {
let (client, event) = input_capture let (client, event) = input_capture
.as_mut()
.unwrap()
.next() .next()
.await .await
.ok_or(anyhow!("capture stream closed"))??; .ok_or(CaptureError::EndOfStream)??;
let pos = match client { let pos = match client {
0 => Position::Left, 0 => Position::Left,
1 => Position::Right, 1 => Position::Right,
@@ -58,11 +48,8 @@ async fn input_capture_test(config: Config) -> Result<()> {
}; };
log::info!("position: {pos}, event: {event}"); log::info!("position: {pos}, event: {event}");
if let Event::Keyboard(KeyboardEvent::Key { key: 1, .. }) = event { if let Event::Keyboard(KeyboardEvent::Key { key: 1, .. }) = event {
input_capture.as_mut().unwrap().release().await?; input_capture.release().await?;
// break; break Ok(());
} }
} }
// input_capture.take().unwrap().terminate().await.unwrap();
}
Ok(())
} }

View File

@@ -117,24 +117,14 @@ async fn handle_capture_event(
} }
} }
let (addr, enter, start_timer) = { let info = {
let mut enter = false; let mut enter = false;
let mut start_timer = false; let mut start_timer = false;
// get client state for handle // get client state for handle
let mut client_manager = server.client_manager.borrow_mut(); let mut client_manager = server.client_manager.borrow_mut();
let client_state = match client_manager.get_mut(handle) { let client_state = client_manager.get_mut(handle).map(|(_, s)| s);
Some((_, s)) => s, if let Some(client_state) = client_state {
None => {
// should not happen
log::warn!("unknown client!");
capture.release().await?;
server.state.replace(State::Receiving);
log::trace!("STATE ===> Receiving");
return Ok(());
}
};
// if we just entered the client we want to send additional enter events until // if we just entered the client we want to send additional enter events until
// we get a leave event // we get a leave event
if let Event::Enter() = e { if let Event::Enter() = e {
@@ -150,9 +140,24 @@ async fn handle_capture_event(
return Ok(()); return Ok(());
} }
} }
Some((client_state.active_addr, enter, start_timer))
(client_state.active_addr, enter, start_timer) } else {
None
}
}; };
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 { if start_timer {
timer_notify.notify_waiters(); timer_notify.notify_waiters();
} }

View File

@@ -82,8 +82,8 @@ fn handle_frontend_stream(
let tx = frontend_tx.clone(); let tx = frontend_tx.clone();
tokio::task::spawn_local(async move { tokio::task::spawn_local(async move {
tokio::select! { tokio::select! {
_ = listen_frontend(tx, stream) => return, _ = listen_frontend(tx, stream) => {},
_ = cancellation_token.cancelled() => return, _ = cancellation_token.cancelled() => {},
} }
}) })
} }