This commit is contained in:
Ferdinand Schober
2024-11-09 12:03:10 +01:00
parent ae58714681
commit 682a7b65bd
5 changed files with 25 additions and 26 deletions

10
Cargo.lock generated
View File

@@ -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"

View File

@@ -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]

View File

@@ -46,7 +46,6 @@ pub struct TomlClient {
impl ConfigToml {
pub fn new(path: &Path) -> Result<ConfigToml, ConfigError> {
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<String, String>,
/// optional input-capture backend override
pub capture_backend: Option<CaptureBackend>,
/// optional input-emulation backend override
pub emulation_backend: Option<EmulationBackend>,
/// 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<scancode::Linux>,
/// 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,

View File

@@ -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<Child, io::Error> {
}
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(())
}

View File

@@ -1,6 +0,0 @@
use input_capture::CaptureEvent;
struct PluginManager {
capture_hook: Vec<Box<dyn Fn(CaptureEvent)>>,
capture_transform: Vec<Box<dyn Fn(CaptureEvent) -> CaptureEvent>>,
}