Some simplifications; release v0.0.8

timeout_old
Tassilo Horn 4 years ago
parent b8c0799ffc
commit 26aeddd34e
  1. 2
      Cargo.toml
  2. 15
      src/bin/swayrd.rs
  3. 20
      src/demon.rs

@ -1,6 +1,6 @@
[package] [package]
name = "swayr" name = "swayr"
version = "0.0.7" version = "0.0.8"
description = "A wofi-based LRU window-switcher for sway written in Rust" description = "A wofi-based LRU window-switcher for sway written in Rust"
homepage = "https://git.sr.ht/~tsdh/swayr" homepage = "https://git.sr.ht/~tsdh/swayr"
repository = "https://git.sr.ht/~tsdh/swayr" repository = "https://git.sr.ht/~tsdh/swayr"

@ -13,18 +13,9 @@ fn main() {
Arc::new(RwLock::new(HashMap::new())); Arc::new(RwLock::new(HashMap::new()));
let con_props_for_ev_handler = con_props.clone(); let con_props_for_ev_handler = con_props.clone();
let subscriber_handle = thread::spawn(move || { thread::spawn(move || {
demon::monitor_con_events(con_props_for_ev_handler) demon::monitor_con_events(con_props_for_ev_handler);
}); });
match demon::serve_client_requests(con_props) { demon::serve_client_requests(con_props);
Ok(()) => {
let subscriber_result = subscriber_handle.join();
match subscriber_result {
Ok(()) => println!("Subscriber thread shut down cleanly."),
Err(err) => panic!(err),
}
}
Err(err) => panic!(err),
}
} }

@ -7,7 +7,6 @@ use std::os::unix::net::{UnixListener, UnixStream};
use std::process as proc; use std::process as proc;
use std::sync::Arc; use std::sync::Arc;
use std::sync::RwLock; use std::sync::RwLock;
use std::thread;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
pub fn monitor_con_events( pub fn monitor_con_events(
@ -122,23 +121,30 @@ fn get_epoch_time_as_millis() -> u128 {
pub fn serve_client_requests( pub fn serve_client_requests(
con_props: Arc<RwLock<HashMap<ipc::Id, ipc::ConProps>>>, con_props: Arc<RwLock<HashMap<ipc::Id, ipc::ConProps>>>,
) -> std::io::Result<()> { ) {
match std::fs::remove_file(util::get_swayr_socket_path()) { match std::fs::remove_file(util::get_swayr_socket_path()) {
Ok(()) => println!("Deleted stale socket from previous run."), Ok(()) => println!("Deleted stale socket from previous run."),
Err(e) => eprintln!("Could not delete socket:\n{:?}", e), Err(e) => eprintln!("Could not delete socket:\n{:?}", e),
} }
let listener = UnixListener::bind(util::get_swayr_socket_path())?; match UnixListener::bind(util::get_swayr_socket_path()) {
Ok(listener) => {
for stream in listener.incoming() { for stream in listener.incoming() {
match stream { match stream {
Ok(stream) => { Ok(stream) => {
let wp_clone = con_props.clone(); handle_client_request(stream, con_props.clone());
thread::spawn(move || handle_client_request(stream, wp_clone)); }
Err(err) => {
eprintln!("Error handling client request: {}", err);
break;
}
}
}
} }
Err(err) => return Err(err), Err(err) => {
eprintln!("Could not bind socket: {}", err)
} }
} }
Ok(())
} }
fn handle_client_request( fn handle_client_request(

Loading…
Cancel
Save