beatbaer/src/player/mod.rs
PlexSheep 6a5cbcdbea
All checks were successful
cargo devel CI / cargo CI (push) Successful in 3m14s
fix(store): store is now actually saved and loaded
2024-08-23 12:07:14 +02:00

100 lines
2.5 KiB
Rust

use clap::Parser;
use eframe::CreationContext;
use egui::Stroke;
use libpt::cli::args::VerbosityLevel;
use libpt::log::{debug, info};
use crate::error::Error;
use crate::store::Store;
use self::ui::entry::{Entry, Kind};
pub mod ui;
pub const TITLE: &str = "Beatbär";
#[derive(Parser)]
pub struct Player {
#[command(flatten)]
verbosity: VerbosityLevel,
#[clap(skip)]
pub gui_options: eframe::NativeOptions,
#[clap(skip)]
show_info_window: bool,
#[clap(skip)]
kind: Kind,
#[clap(skip)]
store: Option<Store>,
}
impl Player {
#[inline]
pub fn store(&self) -> &Store {
&self.store.as_ref().unwrap()
}
pub fn build() -> Result<Self, Error> {
let mut app = Player::parse();
let filter = tracing_subscriber::EnvFilter::builder()
.with_default_directive(app.verbosity.level().into())
.from_env()
.expect("could not init logger")
.add_directive(
format!("{}={}", env!("CARGO_PKG_NAME"), app.verbosity.level())
.parse()
.expect("could not init logger"),
);
tracing_subscriber::fmt::Subscriber::builder()
.with_env_filter(filter)
.with_max_level(app.verbosity.level())
.init();
debug!("logging initialized!");
debug!("level: {}", app.verbosity.level());
app.gui_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([900.0, 700.0])
.with_min_inner_size([500.0, 320.0])
.with_icon(Player::load_icon()),
..Default::default()
};
info!("Player ready to start UI");
Ok(app)
}
pub fn init(&mut self, _cc: &CreationContext) {
self.store = Some(Store::load().expect("could not load store"));
}
fn set_category(&mut self, kind: Kind) {
self.kind = kind;
}
fn category(&self) -> Kind {
self.kind
}
fn open(&mut self, entry: &Entry) {
todo!()
}
fn entries(&self) -> Vec<Entry> {
match self.category() {
Kind::Album => self.store().albums(),
Kind::Song => self.store().songs(),
Kind::Playlist => self.store().playlists(),
Kind::Artist => self.store().artists(),
Kind::Genre => self.store().genres(),
}
}
pub fn end(&mut self) -> Result<(), Error> {
self.store().save()
}
}