subtails/src/main.rs
Muaz Ahmad 10e88b511d - Playstate and next handling
- Handle chunk queueing better (directly from api response)
- Fetch more songs if playlist is empty
2024-12-09 16:44:36 +05:00

65 lines
1.5 KiB
Rust

use std::process::exit;
use std::sync::mpsc::{channel, Receiver};
use player::errors::PlayerError;
mod audio;
mod config;
mod player;
mod ssonic;
mod utils;
fn init() -> Result<Receiver<utils::Error>, utils::Error> {
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(),
audio_event_chan.clone(),
)?;
player::init(
settings.clone(),
audio_event_chan,
api_event_chan,
error_in.clone(),
player_events_out,
player_events_in,
)?;
Ok(error_out)
}
fn main() {
let err_chan = match init() {
Err(x) => {
utils::restore();
eprintln!("{}", x);
exit(1)
}
Ok(err_chan) => err_chan,
};
match err_chan.recv() {
Err(_) => {
utils::restore();
exit(0)
}
Ok(err) => {
if let Some(e) = err.downcast_ref::<PlayerError>() {
match e {
PlayerError::UserQuit => {
utils::restore();
exit(0)
}
_ => (),
}
}
utils::restore();
eprintln!("{}", err);
exit(1)
}
}
}