add config option for fps and ups

This commit is contained in:
figsoda 2020-10-30 12:42:31 -04:00
parent f3534a03fe
commit eebd80626a
2 changed files with 17 additions and 3 deletions

View file

@ -11,9 +11,21 @@ use std::{
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Config { pub struct Config {
#[serde(default = "fps_default")]
pub fps: f64,
#[serde(default = "ups_default")]
pub ups: f64,
pub layout: Widget, pub layout: Widget,
} }
fn fps_default() -> f64 {
30.0
}
fn ups_default() -> f64 {
4.0
}
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub enum Widget { pub enum Widget {
Rows(Vec<Constrained<Widget>>), Rows(Vec<Constrained<Widget>>),

View file

@ -62,6 +62,9 @@ async fn run() -> Result<()> {
let status = Arc::new(Mutex::new(mpd::status(&mut status_cl).await?)); let status = Arc::new(Mutex::new(mpd::status(&mut status_cl).await?));
let status1 = Arc::clone(&status); let status1 = Arc::clone(&status);
let frame_interval = Duration::from_secs_f64(1.0 / cfg.fps);
let update_interval = Duration::from_secs_f64(1.0 / cfg.ups);
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
mpd::idle_playlist(&mut idle_cl) mpd::idle_playlist(&mut idle_cl)
@ -77,7 +80,7 @@ async fn run() -> Result<()> {
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
let deadline = Instant::now() + Duration::from_millis(250); let deadline = Instant::now() + update_interval;
*status1.lock().await = mpd::status(&mut status_cl) *status1.lock().await = mpd::status(&mut status_cl)
.await .await
.context("Failed to query status") .context("Failed to query status")
@ -94,8 +97,7 @@ async fn run() -> Result<()> {
Terminal::new(CrosstermBackend::new(stdout)).context("Failed to initialize terminal")?; Terminal::new(CrosstermBackend::new(stdout)).context("Failed to initialize terminal")?;
loop { loop {
let deadline = Instant::now() + Duration::from_secs_f32(1.0 / 30.0); let deadline = Instant::now() + frame_interval;
let queue = &*queue.lock().await; let queue = &*queue.lock().await;
let status = &*status.lock().await; let status = &*status.lock().await;