subtails/src/main.rs

47 lines
1.1 KiB
Rust
Raw Normal View History

2024-11-25 14:57:49 +05:00
use std::process::exit;
2024-11-25 16:16:43 +05:00
use std::sync::mpsc::{channel, Receiver};
2024-11-25 14:57:49 +05:00
mod audio;
mod config;
mod player;
mod ssonic;
mod utils;
2024-11-25 16:16:43 +05:00
fn init() -> Result<Receiver<utils::Error>, utils::Error> {
2024-11-25 14:57:49 +05:00
let settings = config::init()?;
let (error_in, error_out) = channel();
let (player_events_in, player_events_out) = channel();
let audio_event_chan =
audio::init(settings.clone(), error_in.clone(), player_events_in.clone())?;
let api_event_chan =
ssonic::init(settings.clone(), error_in.clone(), player_events_in.clone())?;
2024-11-27 16:01:29 +05:00
player::init(
2024-11-25 14:57:49 +05:00
settings.clone(),
audio_event_chan,
api_event_chan,
error_in.clone(),
player_events_out,
2024-11-25 14:57:49 +05:00
)?;
2024-11-25 16:16:43 +05:00
Ok(error_out)
2024-11-25 14:57:49 +05:00
}
fn main() {
2024-11-27 14:42:29 +05:00
let err_chan = match init() {
2024-11-25 16:16:43 +05:00
Err(x) => {
2024-11-27 16:01:29 +05:00
utils::restore();
2024-11-25 16:16:43 +05:00
eprintln!("{}", x);
exit(1)
}
2024-11-27 14:42:29 +05:00
Ok(err_chan) => err_chan,
2024-11-25 14:57:49 +05:00
};
2024-11-27 14:42:29 +05:00
match err_chan.recv() {
Err(_) => exit(0),
Ok(err) => {
2024-11-27 16:01:29 +05:00
utils::restore();
2024-11-27 14:42:29 +05:00
eprintln!("{}", err);
exit(1)
}
}
2024-11-25 14:57:49 +05:00
}