mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-15 11:01:29 +03:00
solve clippy except tomanyargs
This commit is contained in:
@@ -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(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 */
|
||||||
|
|||||||
@@ -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,49 +20,36 @@ 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()
|
loop {
|
||||||
.create(2, Position::Top)
|
let (client, event) = input_capture
|
||||||
.await?;
|
.next()
|
||||||
input_capture
|
.await
|
||||||
.as_mut()
|
.ok_or(CaptureError::EndOfStream)??;
|
||||||
.unwrap()
|
let pos = match client {
|
||||||
.create(3, Position::Bottom)
|
0 => Position::Left,
|
||||||
.await?;
|
1 => Position::Right,
|
||||||
loop {
|
2 => Position::Top,
|
||||||
let (client, event) = input_capture
|
_ => Position::Bottom,
|
||||||
.as_mut()
|
};
|
||||||
.unwrap()
|
log::info!("position: {pos}, event: {event}");
|
||||||
.next()
|
if let Event::Keyboard(KeyboardEvent::Key { key: 1, .. }) = event {
|
||||||
.await
|
input_capture.release().await?;
|
||||||
.ok_or(anyhow!("capture stream closed"))??;
|
break Ok(());
|
||||||
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.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 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 => {
|
// if we just entered the client we want to send additional enter events until
|
||||||
// should not happen
|
// we get a leave event
|
||||||
log::warn!("unknown client!");
|
if let Event::Enter() = e {
|
||||||
capture.release().await?;
|
server.state.replace(State::AwaitingLeave);
|
||||||
server.state.replace(State::Receiving);
|
server.active_client.replace(Some(handle));
|
||||||
log::trace!("STATE ===> Receiving");
|
log::trace!("Active client => {}", handle);
|
||||||
return Ok(());
|
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(());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
Some((client_state.active_addr, enter, start_timer))
|
||||||
|
|
||||||
// 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 {
|
} else {
|
||||||
// ignore any potential events in receiving mode
|
None
|
||||||
if server.state.get() == State::Receiving && e != Event::Disconnect() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(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 {
|
if start_timer {
|
||||||
timer_notify.notify_waiters();
|
timer_notify.notify_waiters();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() => {},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user