mirror of
https://github.com/talwat/lowfi
synced 2025-12-09 16:34:12 +00:00
fix: place LOWFI_DISABLE_UI flag in the interface params instantiation
This commit is contained in:
parent
e44a8b85c4
commit
3ce4e0b8fc
@ -96,6 +96,8 @@ pub fn data_dir() -> crate::Result<PathBuf> {
|
|||||||
Ok(dir)
|
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<()> {
|
async fn player(args: Args, environment: ui::Environment) -> crate::Result<()> {
|
||||||
let stream = audio::stream()?;
|
let stream = audio::stream()?;
|
||||||
let mut player = Player::init(args, environment, stream.mixer()).await?;
|
let mut player = Player::init(args, environment, stream.mixer()).await?;
|
||||||
|
|||||||
13
src/ui.rs
13
src/ui.rs
@ -1,4 +1,4 @@
|
|||||||
use std::{env, sync::Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
player::Current,
|
player::Current,
|
||||||
@ -119,6 +119,7 @@ struct Tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Tasks {
|
impl Tasks {
|
||||||
|
/// Actually takes care of spawning the tasks for the [`ui`].
|
||||||
pub fn spawn(
|
pub fn spawn(
|
||||||
tx: Sender<crate::Message>,
|
tx: Sender<crate::Message>,
|
||||||
updater: broadcast::Receiver<ui::Update>,
|
updater: broadcast::Receiver<ui::Update>,
|
||||||
@ -196,17 +197,15 @@ impl Handle {
|
|||||||
state: State,
|
state: State,
|
||||||
args: &Args,
|
args: &Args,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let disabled = env::var("LOWFI_DISABLE_UI").is_ok_and(|x| x == "1");
|
let params = interface::Params::try_from(args)?;
|
||||||
if disabled && !cfg!(feature = "mpris") {
|
|
||||||
return Err(Error::RejectedDisable);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
#[cfg(feature = "mpris")]
|
#[cfg(feature = "mpris")]
|
||||||
mpris: mpris::Server::new(state.clone(), tx.clone(), updater.resubscribe()).await?,
|
mpris: mpris::Server::new(state.clone(), tx.clone(), updater.resubscribe()).await?,
|
||||||
environment,
|
environment,
|
||||||
_tasks: (!disabled)
|
_tasks: params
|
||||||
.then(|| Tasks::spawn(tx, updater, state, interface::Params::from(args))),
|
.enabled
|
||||||
|
.then(|| Tasks::spawn(tx, updater, state, params)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use std::time::Duration;
|
use std::{env, time::Duration};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ui::{self, components, window::Window},
|
ui::{self, components, window::Window},
|
||||||
@ -9,19 +9,28 @@ use crate::{
|
|||||||
pub struct Params {
|
pub struct Params {
|
||||||
pub borderless: bool,
|
pub borderless: bool,
|
||||||
pub minimalist: bool,
|
pub minimalist: bool,
|
||||||
|
pub enabled: bool,
|
||||||
pub delta: Duration,
|
pub delta: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Args> for Params {
|
impl TryFrom<&Args> for Params {
|
||||||
fn from(args: &Args) -> Self {
|
type Error = ui::Error;
|
||||||
|
|
||||||
|
fn try_from(args: &Args) -> ui::Result<Self> {
|
||||||
let delta = 1.0 / f32::from(args.fps);
|
let delta = 1.0 / f32::from(args.fps);
|
||||||
let delta = Duration::from_secs_f32(delta);
|
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,
|
delta,
|
||||||
|
enabled: !disabled,
|
||||||
minimalist: args.minimalist,
|
minimalist: args.minimalist,
|
||||||
borderless: args.borderless,
|
borderless: args.borderless,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user