Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
feschber committed Nov 9, 2024
1 parent ae58714 commit 682a7b6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 14 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
}
}
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -357,6 +369,7 @@ impl Config {
let test_emulation = args.test_emulation;

Ok(Config {
path: config_path,
authorized_fingerprints,
capture_backend,
emulation_backend,
Expand Down
19 changes: 11 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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(())
}
Expand Down
6 changes: 0 additions & 6 deletions src/plugin.rs

This file was deleted.

0 comments on commit 682a7b6

Please sign in to comment.