fix: place LOWFI_DISABLE_UI flag in the interface params instantiation

This commit is contained in:
Tal 2025-12-06 17:37:12 +01:00
parent e44a8b85c4
commit 3ce4e0b8fc
3 changed files with 22 additions and 12 deletions

View File

@ -96,6 +96,8 @@ pub fn data_dir() -> crate::Result<PathBuf> {
Ok(dir)
}
/// Simply creates and runs the player, so that the [`Result`] of both operations
/// can be easily handled by the [`main`] function.
async fn player(args: Args, environment: ui::Environment) -> crate::Result<()> {
let stream = audio::stream()?;
let mut player = Player::init(args, environment, stream.mixer()).await?;

View File

@ -1,4 +1,4 @@
use std::{env, sync::Arc};
use std::sync::Arc;
use crate::{
player::Current,
@ -119,6 +119,7 @@ struct Tasks {
}
impl Tasks {
/// Actually takes care of spawning the tasks for the [`ui`].
pub fn spawn(
tx: Sender<crate::Message>,
updater: broadcast::Receiver<ui::Update>,
@ -196,17 +197,15 @@ impl Handle {
state: State,
args: &Args,
) -> Result<Self> {
let disabled = env::var("LOWFI_DISABLE_UI").is_ok_and(|x| x == "1");
if disabled && !cfg!(feature = "mpris") {
return Err(Error::RejectedDisable);
}
let params = interface::Params::try_from(args)?;
Ok(Self {
#[cfg(feature = "mpris")]
mpris: mpris::Server::new(state.clone(), tx.clone(), updater.resubscribe()).await?,
environment,
_tasks: (!disabled)
.then(|| Tasks::spawn(tx, updater, state, interface::Params::from(args))),
_tasks: params
.enabled
.then(|| Tasks::spawn(tx, updater, state, params)),
})
}
}

View File

@ -1,4 +1,4 @@
use std::time::Duration;
use std::{env, time::Duration};
use crate::{
ui::{self, components, window::Window},
@ -9,19 +9,28 @@ use crate::{
pub struct Params {
pub borderless: bool,
pub minimalist: bool,
pub enabled: bool,
pub delta: Duration,
}
impl From<&Args> for Params {
fn from(args: &Args) -> Self {
impl TryFrom<&Args> for Params {
type Error = ui::Error;
fn try_from(args: &Args) -> ui::Result<Self> {
let delta = 1.0 / f32::from(args.fps);
let delta = Duration::from_secs_f32(delta);
Self {
let disabled = env::var("LOWFI_DISABLE_UI").is_ok_and(|x| x == "1");
if disabled && !cfg!(feature = "mpris") {
return Err(ui::Error::RejectedDisable);
}
Ok(Self {
delta,
enabled: !disabled,
minimalist: args.minimalist,
borderless: args.borderless,
}
})
}
}