mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-10 14:50:55 +03:00
Compare commits
1 Commits
rework-cli
...
cleanup
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cba4cc6150 |
@@ -2,22 +2,9 @@ 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 fn run() -> Result<(), InputCaptureError> {
|
pub async fn run(config: Config) -> 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,28 +3,17 @@ 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;
|
||||||
|
|
||||||
async fn input_emulation_test(config: Config) -> Result<(), InputEmulationError> {
|
pub async fn run(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,4 +1,6 @@
|
|||||||
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},
|
||||||
@@ -7,12 +9,29 @@ 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");
|
||||||
@@ -24,26 +43,6 @@ 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()?;
|
||||||
@@ -51,12 +50,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 {
|
||||||
capture_test::run().unwrap();
|
run_async(capture_test::run(config))?;
|
||||||
} else if config.test_emulation {
|
} else if config.test_emulation {
|
||||||
emulation_test::run().unwrap();
|
run_async(emulation_test::run(config))?;
|
||||||
} 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_service(config)?;
|
run_async(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
|
||||||
@@ -77,7 +76,11 @@ fn run() -> Result<(), LanMouseError> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_service(config: Config) -> Result<(), ServiceError> {
|
fn run_async<F, E>(f: F) -> Result<(), LanMouseError>
|
||||||
|
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()
|
||||||
@@ -85,16 +88,21 @@ fn run_service(config: Config) -> Result<(), ServiceError> {
|
|||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
// run async event loop
|
// run async event loop
|
||||||
runtime.block_on(LocalSet::new().run_until(async {
|
Ok(runtime.block_on(LocalSet::new().run_until(f))?)
|
||||||
// run main loop
|
}
|
||||||
log::info!("Press {:?} to release the mouse", config.release_bind);
|
|
||||||
|
|
||||||
let mut server = Server::new(config);
|
fn start_service() -> Result<Child, io::Error> {
|
||||||
server.run().await?;
|
let child = Command::new(std::env::current_exe()?)
|
||||||
|
.args(std::env::args().skip(1))
|
||||||
|
.arg("--daemon")
|
||||||
|
.spawn()?;
|
||||||
|
Ok(child)
|
||||||
|
}
|
||||||
|
|
||||||
log::debug!("service exiting");
|
async fn run_service(config: Config) -> Result<(), ServiceError> {
|
||||||
Result::<(), ServiceError>::Ok(())
|
log::info!("Press {:?} to release the mouse", config.release_bind);
|
||||||
}))?;
|
Server::new(config).run().await?;
|
||||||
|
log::info!("service exited!");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user