mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 11:59:59 +03:00
move capture/emulation errors into their creates
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1194,7 +1194,6 @@ dependencies = [
|
||||
name = "input-capture"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"ashpd",
|
||||
"async-trait",
|
||||
"core-graphics",
|
||||
|
||||
@@ -7,7 +7,6 @@ license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/ferdinandschober/lan-mouse"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.86"
|
||||
futures = "0.3.28"
|
||||
futures-core = "0.3.30"
|
||||
log = "0.4.22"
|
||||
@@ -15,25 +14,42 @@ input-event = { path = "../input-event", version = "0.1.0" }
|
||||
memmap = "0.7"
|
||||
tempfile = "3.8"
|
||||
thiserror = "1.0.61"
|
||||
tokio = { version = "1.32.0", features = ["io-util", "io-std", "macros", "net", "process", "rt", "sync", "signal"] }
|
||||
tokio = { version = "1.32.0", features = [
|
||||
"io-util",
|
||||
"io-std",
|
||||
"macros",
|
||||
"net",
|
||||
"process",
|
||||
"rt",
|
||||
"sync",
|
||||
"signal",
|
||||
] }
|
||||
once_cell = "1.19.0"
|
||||
async-trait = "0.1.81"
|
||||
tokio-util = "0.7.11"
|
||||
|
||||
|
||||
[target.'cfg(all(unix, not(target_os="macos")))'.dependencies]
|
||||
wayland-client = { version="0.31.1", optional = true }
|
||||
wayland-protocols = { version="0.32.1", features=["client", "staging", "unstable"], optional = true }
|
||||
wayland-protocols-wlr = { version="0.3.1", features=["client"], optional = true }
|
||||
wayland-client = { version = "0.31.1", optional = true }
|
||||
wayland-protocols = { version = "0.32.1", features = [
|
||||
"client",
|
||||
"staging",
|
||||
"unstable",
|
||||
], optional = true }
|
||||
wayland-protocols-wlr = { version = "0.3.1", features = [
|
||||
"client",
|
||||
], optional = true }
|
||||
x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true }
|
||||
ashpd = { version = "0.8", default-features = false, features = ["tokio"], optional = true }
|
||||
reis = { version = "0.2", features = [ "tokio" ], optional = true }
|
||||
ashpd = { version = "0.8", default-features = false, features = [
|
||||
"tokio",
|
||||
], optional = true }
|
||||
reis = { version = "0.2", features = ["tokio"], optional = true }
|
||||
|
||||
[target.'cfg(target_os="macos")'.dependencies]
|
||||
core-graphics = { version = "0.23", features = ["highsierra"] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows = { version = "0.57.0", features = [
|
||||
windows = { version = "0.57.0", features = [
|
||||
"Win32_System_LibraryLoader",
|
||||
"Win32_System_Threading",
|
||||
"Win32_Foundation",
|
||||
@@ -45,6 +61,10 @@ windows = { version = "0.57.0", features = [
|
||||
|
||||
[features]
|
||||
default = ["wayland", "x11", "libei"]
|
||||
wayland = ["dep:wayland-client", "dep:wayland-protocols", "dep:wayland-protocols-wlr" ]
|
||||
wayland = [
|
||||
"dep:wayland-client",
|
||||
"dep:wayland-protocols",
|
||||
"dep:wayland-protocols-wlr",
|
||||
]
|
||||
x11 = ["dep:x11"]
|
||||
libei = ["dep:reis", "dep:ashpd"]
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum InputCaptureError {
|
||||
#[error("error creating input-capture: `{0}`")]
|
||||
Create(#[from] CaptureCreationError),
|
||||
#[error("error while capturing input: `{0}`")]
|
||||
Capture(#[from] CaptureError),
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
use std::io;
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
|
||||
@@ -5,7 +5,7 @@ use futures_core::Stream;
|
||||
|
||||
use input_event::Event;
|
||||
|
||||
pub use error::{CaptureCreationError, CaptureError};
|
||||
pub use error::{CaptureCreationError, CaptureError, InputCaptureError};
|
||||
|
||||
pub mod error;
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
#[derive(Debug, Error)]
|
||||
pub enum InputEmulationError {
|
||||
#[error("error creating input-emulation: `{0}`")]
|
||||
Create(#[from] EmulationCreationError),
|
||||
#[error("error emulating input: `{0}`")]
|
||||
Emulate(#[from] EmulationError),
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
use ashpd::{desktop::ResponseError, Error::Response};
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use async_trait::async_trait;
|
||||
use error::EmulationError;
|
||||
use std::fmt::Display;
|
||||
|
||||
use input_event::Event;
|
||||
|
||||
use self::error::EmulationCreationError;
|
||||
pub use self::error::{EmulationCreationError, EmulationError, InputEmulationError};
|
||||
|
||||
#[cfg(windows)]
|
||||
pub mod windows;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use crate::config::Config;
|
||||
use anyhow::Result;
|
||||
use futures::StreamExt;
|
||||
use input_capture::{self, CaptureError, InputCapture, Position};
|
||||
use input_capture::{self, CaptureError, InputCapture, InputCaptureError, Position};
|
||||
use input_event::{Event, KeyboardEvent};
|
||||
use tokio::task::LocalSet;
|
||||
|
||||
pub fn run() -> Result<()> {
|
||||
pub fn run() -> anyhow::Result<()> {
|
||||
log::info!("running input capture test");
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_io()
|
||||
@@ -14,10 +13,10 @@ pub fn run() -> Result<()> {
|
||||
|
||||
let config = Config::new()?;
|
||||
|
||||
runtime.block_on(LocalSet::new().run_until(input_capture_test(config)))
|
||||
Ok(runtime.block_on(LocalSet::new().run_until(input_capture_test(config)))?)
|
||||
}
|
||||
|
||||
async fn input_capture_test(config: Config) -> Result<()> {
|
||||
async fn input_capture_test(config: Config) -> Result<(), InputCaptureError> {
|
||||
log::info!("creating input capture");
|
||||
let backend = config.capture_backend.map(|b| b.into());
|
||||
loop {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use anyhow::Result;
|
||||
use std::net::IpAddr;
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
|
||||
@@ -12,7 +11,7 @@ pub(crate) struct DnsResolver {
|
||||
}
|
||||
|
||||
impl DnsResolver {
|
||||
pub(crate) fn new(dns_request: Receiver<ClientHandle>) -> Result<Self> {
|
||||
pub(crate) fn new(dns_request: Receiver<ClientHandle>) -> Result<Self, ResolveError> {
|
||||
let resolver = TokioAsyncResolver::tokio_from_system_conf()?;
|
||||
Ok(Self {
|
||||
resolver,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use futures::StreamExt;
|
||||
use std::{collections::HashSet, net::SocketAddr};
|
||||
use thiserror::Error;
|
||||
|
||||
use tokio::{
|
||||
process::Command,
|
||||
@@ -8,9 +7,7 @@ use tokio::{
|
||||
task::JoinHandle,
|
||||
};
|
||||
|
||||
use input_capture::{
|
||||
self, error::CaptureCreationError, CaptureError, CaptureHandle, InputCapture, Position,
|
||||
};
|
||||
use input_capture::{self, CaptureError, CaptureHandle, InputCapture, InputCaptureError, Position};
|
||||
|
||||
use input_event::{scancode, Event, KeyboardEvent};
|
||||
|
||||
@@ -18,14 +15,6 @@ use crate::{client::ClientHandle, frontend::Status, server::State};
|
||||
|
||||
use super::Server;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub(crate) enum LanMouseCaptureError {
|
||||
#[error("error creating input-capture: `{0}`")]
|
||||
Create(#[from] CaptureCreationError),
|
||||
#[error("error while capturing input: `{0}`")]
|
||||
Capture(#[from] CaptureError),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) enum CaptureEvent {
|
||||
/// capture must release the mouse
|
||||
@@ -76,7 +65,7 @@ async fn do_capture(
|
||||
server: &Server,
|
||||
sender_tx: &Sender<(Event, SocketAddr)>,
|
||||
notify_rx: &mut Receiver<CaptureEvent>,
|
||||
) -> Result<(), LanMouseCaptureError> {
|
||||
) -> Result<(), InputCaptureError> {
|
||||
/* allow cancelling capture request */
|
||||
let mut capture = tokio::select! {
|
||||
r = input_capture::create(backend) => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use thiserror::Error;
|
||||
use tokio::{
|
||||
sync::mpsc::{Receiver, Sender},
|
||||
task::JoinHandle,
|
||||
@@ -11,11 +10,7 @@ use crate::{
|
||||
frontend::Status,
|
||||
server::State,
|
||||
};
|
||||
use input_emulation::{
|
||||
self,
|
||||
error::{EmulationCreationError, EmulationError},
|
||||
EmulationHandle, InputEmulation,
|
||||
};
|
||||
use input_emulation::{self, EmulationError, EmulationHandle, InputEmulation, InputEmulationError};
|
||||
use input_event::{Event, KeyboardEvent};
|
||||
|
||||
use super::{network_task::NetworkError, CaptureEvent, Server};
|
||||
@@ -41,14 +36,6 @@ pub(crate) fn new(
|
||||
tokio::task::spawn_local(emulation_task)
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum LanMouseEmulationError {
|
||||
#[error("error creating input-emulation: `{0}`")]
|
||||
Create(#[from] EmulationCreationError),
|
||||
#[error("error emulating input: `{0}`")]
|
||||
Emulate(#[from] EmulationError),
|
||||
}
|
||||
|
||||
async fn emulation_task(
|
||||
server: Server,
|
||||
mut rx: Receiver<EmulationEvent>,
|
||||
@@ -82,7 +69,7 @@ async fn do_emulation(
|
||||
udp_rx: &mut Receiver<Result<(Event, SocketAddr), NetworkError>>,
|
||||
sender_tx: &Sender<(Event, SocketAddr)>,
|
||||
capture_tx: &Sender<CaptureEvent>,
|
||||
) -> Result<(), LanMouseEmulationError> {
|
||||
) -> Result<(), InputEmulationError> {
|
||||
let backend = server.config.emulation_backend.map(|b| b.into());
|
||||
log::info!("creating input emulation...");
|
||||
let mut emulation = tokio::select! {
|
||||
@@ -117,7 +104,7 @@ async fn do_emulation_session(
|
||||
udp_rx: &mut Receiver<Result<(Event, SocketAddr), NetworkError>>,
|
||||
sender_tx: &Sender<(Event, SocketAddr)>,
|
||||
capture_tx: &Sender<CaptureEvent>,
|
||||
) -> Result<(), LanMouseEmulationError> {
|
||||
) -> Result<(), InputEmulationError> {
|
||||
let mut last_ignored = None;
|
||||
|
||||
loop {
|
||||
|
||||
Reference in New Issue
Block a user