big overhaul
This commit is contained in:
30
src/main.rs
30
src/main.rs
@@ -8,20 +8,26 @@ use structs::{config::Config, data::Data};
|
||||
use crate::update_players::update_players;
|
||||
use crate::update_message::update_message;
|
||||
use crate::print_text::print_text;
|
||||
use crate::print_players::print_players;
|
||||
|
||||
mod update_players;
|
||||
mod update_message;
|
||||
mod print_text;
|
||||
mod structs;
|
||||
mod print_players;
|
||||
|
||||
fn handle_signal(data: &Data, pf: &PlayerFinder) {
|
||||
if data.current_player.is_some() {
|
||||
if let Ok(p) = pf.find_by_name(data.current_player.as_ref().unwrap()) {
|
||||
let _ = p.checked_play_pause();
|
||||
}
|
||||
fn handle_signal(data: &Data) {
|
||||
if let Some(p) = &data.current_player {
|
||||
let _ = p.checked_play_pause();
|
||||
}
|
||||
}
|
||||
|
||||
fn default_loop(pf: &PlayerFinder, cfg: &Config, data: &mut Data) {
|
||||
update_players(pf, cfg, data);
|
||||
update_message(cfg, data);
|
||||
print_text(cfg, data);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
//dotenvy::dotenv().expect("Failed to read .env file");
|
||||
std::env::set_var("RUST_LOG", "error");
|
||||
@@ -37,18 +43,20 @@ fn main() {
|
||||
|
||||
let pf: PlayerFinder = PlayerFinder::new()
|
||||
.expect("Failed to connect to Dbus!");
|
||||
|
||||
|
||||
if let Err(e) = signal_hook::flag::register(signal_hook::consts::SIGUSR1, Arc::clone(&term)) {
|
||||
panic!("{}", e);
|
||||
}
|
||||
|
||||
loop {
|
||||
thread::sleep(cfg.update_delay);
|
||||
update_players(&pf, &cfg, &mut data);
|
||||
update_message(&pf, &cfg, &mut data);
|
||||
print_text(&cfg, &mut data);
|
||||
if term.load(Ordering::Relaxed) {
|
||||
handle_signal(&data, &pf);
|
||||
match cli.debug {
|
||||
true => print_players(&pf),
|
||||
false => default_loop(&pf, &cfg, &mut data),
|
||||
}
|
||||
|
||||
if term.load(Ordering::Relaxed) {
|
||||
handle_signal(&data);
|
||||
term.swap(false, Ordering::Relaxed);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user