[refactor] Remove redundant Result<(), Box<dyn Error>>

main
Shinyzenith 2 years ago
parent 257e642d52
commit eab71d680d
No known key found for this signature in database
GPG Key ID: A3DFCDC66E9E2950

@ -2,9 +2,9 @@ use clap::{arg, App};
use evdev::{Device, Key};
use interprocess::local_socket::LocalSocketStream;
use nix::unistd;
use std::{env, error::Error, io::prelude::*, path::Path, process::exit};
use std::{env, io::prelude::*, path::Path, process::exit};
pub fn main() -> Result<(), Box<dyn Error>> {
pub fn main() {
let args = set_flags().get_matches();
env::set_var("RUST_LOG", "swhkd=warn");
@ -49,9 +49,23 @@ pub fn main() -> Result<(), Box<dyn Error>> {
//TODO: IMPLEMENT KEYBOARD EVENT GRAB
let mut conn = LocalSocketStream::connect("/tmp/swhkd.sock")?;
conn.write_all(args.value_of("shell").unwrap().as_bytes())?;
Ok(())
let mut conn = match LocalSocketStream::connect("/tmp/swhkd.sock"){
Ok(conn) => {conn},
Err(e) => {
log::error!("Unable to connect to hotkey server, is swhks running??");
log::error!("Error: {}", e);
exit(1);
}
};
match conn.write_all(args.value_of("shell").unwrap().as_bytes()){
Ok(_) => {},
Err(e) => {
log::error!("Unable to send command to hotkey server, is swhks running??");
log::error!("Error: {}", e);
exit(1);
}
};
}
pub fn permission_check() -> bool {
@ -81,7 +95,7 @@ pub fn check_keyboard(device: &Device) -> bool {
log::debug!(
"{} ({}) is a keyboard.",
device.name().unwrap(),
device.physical_path().unwrap()
device.physical_path().unwrap(),
);
return true;
} else {

@ -1,7 +1,6 @@
use interprocess::local_socket::{LocalSocketListener, LocalSocketStream};
use std::{
env,
error::Error,
fs,
io::{self, prelude::*, BufReader},
path::Path,
@ -9,7 +8,7 @@ use std::{
};
use sysinfo::{ProcessExt, System, SystemExt};
fn main() -> Result<(), Box<dyn Error>> {
fn main() {
env::set_var("RUST_LOG", "swhks=trace");
env_logger::init();
@ -46,7 +45,7 @@ fn main() -> Result<(), Box<dyn Error>> {
log::debug!("Removed old socket file");
}
Err(e) => {
log::error!("Error removeing the socket file!: {}", e);
log::error!("Error removing the socket file!: {}", e);
exit(1);
}
};
@ -81,13 +80,26 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}
let listener = LocalSocketListener::bind(sockfile)?;
let listener = match LocalSocketListener::bind(sockfile.clone()){
Ok(listener) => {listener},
Err(e) => {
log::error!("Failed to connect to {}", sockfile);
log::error!("Error: {}",e);
exit(1);
}
};
for conn in listener.incoming().filter_map(handle_error) {
let mut conn = BufReader::new(conn);
let mut buffer = String::new();
conn.read_line(&mut buffer)?;
match conn.read_line(&mut buffer){
Ok(_) => {},
Err(e) => {
log::error!("Failed to read incoming command from client.");
log::error!("Error: {}", e);
exit(1);
}
};
log::debug!("Recieved command : {}", buffer);
run_system_command(&buffer);
}
Ok(())
}

Loading…
Cancel
Save