mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-04 16:21:29 +03:00
committed by
GitHub
parent
c50b746816
commit
d042c0aa4a
51
src/main.rs
51
src/main.rs
@@ -3,10 +3,13 @@ use std::{process, error::Error};
|
||||
use env_logger::Env;
|
||||
use lan_mouse::{
|
||||
consumer, producer,
|
||||
config::{Config, Frontend::{Gtk, Cli}}, event::server::Server,
|
||||
frontend::{FrontendAdapter, cli::CliFrontend},
|
||||
config::{Config, Frontend::{Cli, Gtk}}, event::server::Server,
|
||||
frontend::{FrontendAdapter, cli},
|
||||
};
|
||||
|
||||
#[cfg(all(unix, feature = "gtk"))]
|
||||
use lan_mouse::frontend::gtk;
|
||||
|
||||
pub fn main() {
|
||||
|
||||
// init logging
|
||||
@@ -33,30 +36,34 @@ pub fn run() -> Result<(), Box<dyn Error>> {
|
||||
// start sending and receiving events
|
||||
let mut event_server = Server::new(config.port, producer, consumer, frontend_adapter)?;
|
||||
|
||||
// add clients form config
|
||||
config.get_clients().into_iter().for_each(|(c, h, p)| {
|
||||
let host_name = match h {
|
||||
Some(h) => format!(" '{}'", h),
|
||||
None => "".to_owned(),
|
||||
};
|
||||
if c.len() == 0 {
|
||||
log::warn!("ignoring client{} with 0 assigned ips!", host_name);
|
||||
}
|
||||
log::info!("adding client [{}]{} @ {:?}", p, host_name, c);
|
||||
event_server.add_client(c, p);
|
||||
});
|
||||
|
||||
// any threads need to be started after event_server sets up signal handling
|
||||
match config.frontend {
|
||||
Gtk => {
|
||||
#[cfg(all(unix, feature = "gtk"))]
|
||||
frontend::gtk::create();
|
||||
#[cfg(not(feature = "gtk"))]
|
||||
panic!("gtk frontend requested but feature not enabled!");
|
||||
},
|
||||
Cli => Box::new(CliFrontend::new()?),
|
||||
#[cfg(all(unix, feature = "gtk"))]
|
||||
Gtk => { gtk::start()?; }
|
||||
#[cfg(any(not(feature = "gtk"), not(unix)))]
|
||||
Gtk => panic!("gtk frontend requested but feature not enabled!"),
|
||||
Cli => { cli::start()?; }
|
||||
};
|
||||
|
||||
// this currently causes issues, because the clients from
|
||||
// the config arent communicated to gtk yet.
|
||||
if config.frontend == Gtk {
|
||||
log::warn!("clients defined in config currently have no effect with the gtk frontend");
|
||||
} else {
|
||||
// add clients from config
|
||||
config.get_clients().into_iter().for_each(|(c, h, p)| {
|
||||
let host_name = match h {
|
||||
Some(h) => format!(" '{}'", h),
|
||||
None => "".to_owned(),
|
||||
};
|
||||
if c.len() == 0 {
|
||||
log::warn!("ignoring client{} with 0 assigned ips!", host_name);
|
||||
}
|
||||
log::info!("adding client [{}]{} @ {:?}", p, host_name, c);
|
||||
event_server.add_client(c, p);
|
||||
});
|
||||
}
|
||||
|
||||
log::info!("Press Ctrl+Alt+Shift+Super to release the mouse");
|
||||
// run event loop
|
||||
event_server.run()?;
|
||||
|
||||
Reference in New Issue
Block a user