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)]
pub struct Config {
#[serde(default = "fps_default")]
pub fps: f64,
#[serde(default = "ups_default")]
pub ups: f64,
pub layout: Widget,
}
fn fps_default() -> f64 {
30.0
}
fn ups_default() -> f64 {
4.0
}
#[derive(Debug, Deserialize)]
pub enum 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 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 {
loop {
mpd::idle_playlist(&mut idle_cl)
@ -77,7 +80,7 @@ async fn run() -> Result<()> {
tokio::spawn(async move {
loop {
let deadline = Instant::now() + Duration::from_millis(250);
let deadline = Instant::now() + update_interval;
*status1.lock().await = mpd::status(&mut status_cl)
.await
.context("Failed to query status")
@ -94,8 +97,7 @@ async fn run() -> Result<()> {
Terminal::new(CrosstermBackend::new(stdout)).context("Failed to initialize terminal")?;
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 status = &*status.lock().await;