mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-19 03:00:55 +03:00
Compare commits
1 Commits
cleanup
...
extract-fr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
377997c6d2 |
@@ -2,9 +2,22 @@ use crate::config::Config;
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use input_capture::{self, CaptureError, CaptureEvent, InputCapture, InputCaptureError, Position};
|
use input_capture::{self, CaptureError, CaptureEvent, InputCapture, InputCaptureError, Position};
|
||||||
use input_event::{Event, KeyboardEvent};
|
use input_event::{Event, KeyboardEvent};
|
||||||
|
use tokio::task::LocalSet;
|
||||||
|
|
||||||
pub async fn run(config: Config) -> Result<(), InputCaptureError> {
|
pub fn run() -> Result<(), InputCaptureError> {
|
||||||
log::info!("running input capture test");
|
log::info!("running input capture test");
|
||||||
|
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||||
|
.enable_io()
|
||||||
|
.enable_time()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let config = Config::new().unwrap();
|
||||||
|
|
||||||
|
runtime.block_on(LocalSet::new().run_until(input_capture_test(config)))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn input_capture_test(config: Config) -> Result<(), InputCaptureError> {
|
||||||
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());
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
@@ -3,17 +3,28 @@ use input_emulation::{InputEmulation, InputEmulationError};
|
|||||||
use input_event::{Event, PointerEvent};
|
use input_event::{Event, PointerEvent};
|
||||||
use std::f64::consts::PI;
|
use std::f64::consts::PI;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
use tokio::task::LocalSet;
|
||||||
|
|
||||||
|
pub fn run() -> Result<(), InputEmulationError> {
|
||||||
|
log::info!("running input emulation test");
|
||||||
|
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||||
|
.enable_io()
|
||||||
|
.enable_time()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let config = Config::new().unwrap();
|
||||||
|
|
||||||
|
runtime.block_on(LocalSet::new().run_until(input_emulation_test(config)))
|
||||||
|
}
|
||||||
|
|
||||||
const FREQUENCY_HZ: f64 = 1.0;
|
const FREQUENCY_HZ: f64 = 1.0;
|
||||||
const RADIUS: f64 = 100.0;
|
const RADIUS: f64 = 100.0;
|
||||||
|
|
||||||
pub async fn run(config: Config) -> Result<(), InputEmulationError> {
|
async fn input_emulation_test(config: Config) -> Result<(), InputEmulationError> {
|
||||||
log::info!("running input emulation test");
|
|
||||||
|
|
||||||
let backend = config.emulation_backend.map(|b| b.into());
|
let backend = config.emulation_backend.map(|b| b.into());
|
||||||
let mut emulation = InputEmulation::new(backend).await?;
|
let mut emulation = InputEmulation::new(backend).await?;
|
||||||
emulation.create(0).await;
|
emulation.create(0).await;
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut offset = (0, 0);
|
let mut offset = (0, 0);
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
72
src/main.rs
72
src/main.rs
@@ -1,6 +1,4 @@
|
|||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
use input_capture::InputCaptureError;
|
|
||||||
use input_emulation::InputEmulationError;
|
|
||||||
use lan_mouse::{
|
use lan_mouse::{
|
||||||
capture_test,
|
capture_test,
|
||||||
config::{Config, ConfigError, Frontend},
|
config::{Config, ConfigError, Frontend},
|
||||||
@@ -9,29 +7,12 @@ use lan_mouse::{
|
|||||||
};
|
};
|
||||||
use lan_mouse_ipc::IpcError;
|
use lan_mouse_ipc::IpcError;
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
|
||||||
io,
|
io,
|
||||||
process::{self, Child, Command},
|
process::{self, Child, Command},
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio::task::LocalSet;
|
use tokio::task::LocalSet;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
enum LanMouseError {
|
|
||||||
#[error(transparent)]
|
|
||||||
Service(#[from] ServiceError),
|
|
||||||
#[error(transparent)]
|
|
||||||
IpcError(#[from] IpcError),
|
|
||||||
#[error(transparent)]
|
|
||||||
Config(#[from] ConfigError),
|
|
||||||
#[error(transparent)]
|
|
||||||
Io(#[from] io::Error),
|
|
||||||
#[error(transparent)]
|
|
||||||
Capture(#[from] InputCaptureError),
|
|
||||||
#[error(transparent)]
|
|
||||||
Emulation(#[from] InputEmulationError),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
// init logging
|
// init logging
|
||||||
let env = Env::default().filter_or("LAN_MOUSE_LOG_LEVEL", "info");
|
let env = Env::default().filter_or("LAN_MOUSE_LOG_LEVEL", "info");
|
||||||
@@ -43,6 +24,26 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn start_service() -> Result<Child, io::Error> {
|
||||||
|
let child = Command::new(std::env::current_exe()?)
|
||||||
|
.args(std::env::args().skip(1))
|
||||||
|
.arg("--daemon")
|
||||||
|
.spawn()?;
|
||||||
|
Ok(child)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
enum LanMouseError {
|
||||||
|
#[error(transparent)]
|
||||||
|
Service(#[from] ServiceError),
|
||||||
|
#[error(transparent)]
|
||||||
|
IpcError(#[from] IpcError),
|
||||||
|
#[error(transparent)]
|
||||||
|
Config(#[from] ConfigError),
|
||||||
|
#[error(transparent)]
|
||||||
|
Io(#[from] io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
fn run() -> Result<(), LanMouseError> {
|
fn run() -> Result<(), LanMouseError> {
|
||||||
// parse config file + cli args
|
// parse config file + cli args
|
||||||
let config = Config::new()?;
|
let config = Config::new()?;
|
||||||
@@ -50,12 +51,12 @@ fn run() -> Result<(), LanMouseError> {
|
|||||||
log::info!("release bind: {:?}", config.release_bind);
|
log::info!("release bind: {:?}", config.release_bind);
|
||||||
|
|
||||||
if config.test_capture {
|
if config.test_capture {
|
||||||
run_async(capture_test::run(config))?;
|
capture_test::run().unwrap();
|
||||||
} else if config.test_emulation {
|
} else if config.test_emulation {
|
||||||
run_async(emulation_test::run(config))?;
|
emulation_test::run().unwrap();
|
||||||
} else if config.daemon {
|
} else if config.daemon {
|
||||||
// if daemon is specified we run the service
|
// if daemon is specified we run the service
|
||||||
run_async(run_service(config))?;
|
run_service(config)?;
|
||||||
} else {
|
} else {
|
||||||
// otherwise start the service as a child process and
|
// otherwise start the service as a child process and
|
||||||
// run a frontend
|
// run a frontend
|
||||||
@@ -76,11 +77,7 @@ fn run() -> Result<(), LanMouseError> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_async<F, E>(f: F) -> Result<(), LanMouseError>
|
fn run_service(config: Config) -> Result<(), ServiceError> {
|
||||||
where
|
|
||||||
F: Future<Output = Result<(), E>>,
|
|
||||||
LanMouseError: From<E>,
|
|
||||||
{
|
|
||||||
// create single threaded tokio runtime
|
// create single threaded tokio runtime
|
||||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||||
.enable_io()
|
.enable_io()
|
||||||
@@ -88,21 +85,16 @@ where
|
|||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
// run async event loop
|
// run async event loop
|
||||||
Ok(runtime.block_on(LocalSet::new().run_until(f))?)
|
runtime.block_on(LocalSet::new().run_until(async {
|
||||||
}
|
// run main loop
|
||||||
|
log::info!("Press {:?} to release the mouse", config.release_bind);
|
||||||
|
|
||||||
fn start_service() -> Result<Child, io::Error> {
|
let mut server = Server::new(config);
|
||||||
let child = Command::new(std::env::current_exe()?)
|
server.run().await?;
|
||||||
.args(std::env::args().skip(1))
|
|
||||||
.arg("--daemon")
|
|
||||||
.spawn()?;
|
|
||||||
Ok(child)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_service(config: Config) -> Result<(), ServiceError> {
|
log::debug!("service exiting");
|
||||||
log::info!("Press {:?} to release the mouse", config.release_bind);
|
Result::<(), ServiceError>::Ok(())
|
||||||
Server::new(config).run().await?;
|
}))?;
|
||||||
log::info!("service exited!");
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user