diff --git a/Cargo.lock b/Cargo.lock index ea01734..fd82081 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1852,7 +1852,6 @@ dependencies = [ "log", "rcgen", "rustls", - "rustls-pemfile", "serde", "serde_json", "sha2", @@ -2651,15 +2650,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls-pemfile" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "rustls-pki-types" version = "1.10.0" diff --git a/Cargo.toml b/Cargo.toml index f89e63d..8d3bb05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,6 @@ rustls = { version = "0.23.12", default-features = false, features = [ "ring", ] } rcgen = "0.13.1" -rustls-pemfile = "2.1.3" sha2 = "0.10.8" [target.'cfg(unix)'.dependencies] diff --git a/src/config.rs b/src/config.rs index 74dba56..493b813 100644 --- a/src/config.rs +++ b/src/config.rs @@ -46,7 +46,6 @@ pub struct TomlClient { impl ConfigToml { pub fn new(path: &Path) -> Result { let config = fs::read_to_string(path)?; - log::info!("using config: \"{path:?}\""); Ok(toml::from_str::<_>(&config)?) } } @@ -232,16 +231,29 @@ impl Default for Frontend { #[derive(Debug)] pub struct Config { + /// the path to the configuration file used + pub path: PathBuf, + /// public key fingerprints authorized for connection pub authorized_fingerprints: HashMap, + /// optional input-capture backend override pub capture_backend: Option, + /// optional input-emulation backend override pub emulation_backend: Option, + /// the frontend to use pub frontend: Frontend, + /// the port to use (initially) pub port: u16, + /// list of clients pub clients: Vec<(TomlClient, Position)>, + /// whether or not to run as a daemon pub daemon: bool, + /// configured release bind pub release_bind: Vec, + /// test capture instead of running the app pub test_capture: bool, + /// test emulation instead of running the app pub test_emulation: bool, + /// path to the tls certificate to use pub cert_path: PathBuf, } @@ -357,6 +369,7 @@ impl Config { let test_emulation = args.test_emulation; Ok(Config { + path: config_path, authorized_fingerprints, capture_backend, emulation_backend, diff --git a/src/main.rs b/src/main.rs index 37c7a92..85b9470 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use lan_mouse::{ emulation_test, service::{Service, ServiceError}, }; -use lan_mouse_ipc::IpcError; +use lan_mouse_ipc::{IpcError, IpcListenerCreationError}; use std::{ future::Future, io, @@ -32,7 +32,7 @@ enum LanMouseError { Emulation(#[from] InputEmulationError), } -pub fn main() { +fn main() { // init logging let env = Env::default().filter_or("LAN_MOUSE_LOG_LEVEL", "info"); env_logger::init_from_env(env); @@ -46,16 +46,18 @@ pub fn main() { fn run() -> Result<(), LanMouseError> { // parse config file + cli args let config = Config::new()?; - log::debug!("{config:?}"); - log::info!("release bind: {:?}", config.release_bind); - if config.test_capture { run_async(capture_test::run(config))?; } else if config.test_emulation { run_async(emulation_test::run(config))?; } else if config.daemon { // if daemon is specified we run the service - run_async(run_service(config))?; + match run_async(run_service(config)) { + Err(LanMouseError::Service(ServiceError::IpcListen( + IpcListenerCreationError::AlreadyRunning, + ))) => log::info!("service already running!"), + r => r?, + } } else { // otherwise start the service as a child process and // run a frontend @@ -100,9 +102,10 @@ fn start_service() -> Result { } async fn run_service(config: Config) -> Result<(), ServiceError> { + log::info!("using config: {:?}", config.path); log::info!("Press {:?} to release the mouse", config.release_bind); - let mut server = Service::new(config).await?; - server.run().await?; + let mut service = Service::new(config).await?; + service.run().await?; log::info!("service exited!"); Ok(()) } diff --git a/src/plugin.rs b/src/plugin.rs deleted file mode 100644 index df581f9..0000000 --- a/src/plugin.rs +++ /dev/null @@ -1,6 +0,0 @@ -use input_capture::CaptureEvent; - -struct PluginManager { - capture_hook: Vec>, - capture_transform: Vec CaptureEvent>>, -}