mirror of
https://github.com/talwat/lowfi
synced 2025-12-31 11:03:21 +00:00
fix: don't initialize environment if ui is disabled
This commit is contained in:
parent
6b65b7d952
commit
cd002ef9ab
@ -6,4 +6,4 @@ lowfi has some more specific options, usually as a result of minor feature reque
|
||||
If you have some behavior you'd like to change, which is quite specific, then see if one of these options suits you.
|
||||
|
||||
* `LOWFI_FIXED_MPRIS_NAME` - Limits the number of lowfi instances to one, but ensures the player name is always `lowfi`.
|
||||
* `LOWFI_DISABLE_UI` - Disables the UI.
|
||||
* `LOWFI_DISABLE_UI` - Disables the UI. This requires MPRIS, so that you can still actually control lowfi.
|
||||
|
||||
@ -89,6 +89,10 @@ enum Commands {
|
||||
},
|
||||
}
|
||||
|
||||
pub fn env(name: &str) -> bool {
|
||||
std::env::var(name).is_ok_and(|x| x == "1")
|
||||
}
|
||||
|
||||
/// Returns the application data directory used for persistency.
|
||||
///
|
||||
/// The function returns the platform-specific user data directory with
|
||||
@ -121,7 +125,7 @@ async fn main() -> eyre::Result<()> {
|
||||
}
|
||||
|
||||
let stream = audio::stream()?;
|
||||
let environment = ui::Environment::ready(args.alternate)?;
|
||||
let environment = ui::Environment::ready(&args)?;
|
||||
let (mut player, mut tasks) = Player::init(args, stream.mixer())
|
||||
.await
|
||||
.inspect_err(|_| environment.cleanup(false).unwrap())?;
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::player::Current;
|
||||
use tokio::{sync::broadcast, time::Instant};
|
||||
|
||||
pub mod environment;
|
||||
pub mod task;
|
||||
pub mod init;
|
||||
pub use environment::Environment;
|
||||
pub mod input;
|
||||
pub mod interface;
|
||||
|
||||
@ -15,16 +15,29 @@ pub struct Environment {
|
||||
|
||||
/// Whether the terminal is in an alternate screen or not.
|
||||
alternate: bool,
|
||||
|
||||
/// Whether the UI is actually enabled at all.
|
||||
/// This will effectively make the environment just do nothing.
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
impl Environment {
|
||||
/// This prepares the terminal, returning an [Environment] helpful
|
||||
/// for cleaning up afterwards.
|
||||
pub fn ready(alternate: bool) -> super::Result<Self> {
|
||||
pub fn ready(args: &crate::Args) -> super::Result<Self> {
|
||||
let enabled = !crate::env("LOWFI_DISABLE_UI");
|
||||
if !enabled {
|
||||
return Ok(Environment {
|
||||
enhancement: false,
|
||||
alternate: args.alternate,
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
let mut lock = stdout().lock();
|
||||
|
||||
crossterm::execute!(lock, Hide)?;
|
||||
if alternate {
|
||||
if args.alternate {
|
||||
crossterm::execute!(lock, EnterAlternateScreen, MoveTo(0, 0))?;
|
||||
}
|
||||
|
||||
@ -39,8 +52,9 @@ impl Environment {
|
||||
}
|
||||
|
||||
let environment = Self {
|
||||
enabled,
|
||||
enhancement,
|
||||
alternate,
|
||||
alternate: args.alternate,
|
||||
};
|
||||
|
||||
panic::set_hook(Box::new(move |info| {
|
||||
@ -54,6 +68,10 @@ impl Environment {
|
||||
/// Uses the information collected from initialization to safely close down
|
||||
/// the terminal & restore it to it's previous state.
|
||||
pub fn cleanup(&self, elegant: bool) -> super::Result<()> {
|
||||
if !self.enabled {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let mut lock = stdout().lock();
|
||||
|
||||
if self.alternate {
|
||||
|
||||
@ -2,7 +2,7 @@ use crate::{
|
||||
ui::{self, State},
|
||||
Args,
|
||||
};
|
||||
use std::{env, io::stdout, time::Duration};
|
||||
use std::{io::stdout, time::Duration};
|
||||
|
||||
pub mod clock;
|
||||
pub mod components;
|
||||
@ -59,7 +59,7 @@ impl TryFrom<&Args> for Params {
|
||||
let delta = 1.0 / f32::from(args.fps);
|
||||
let delta = Duration::from_secs_f32(delta);
|
||||
|
||||
let disabled = env::var("LOWFI_DISABLE_UI").is_ok_and(|x| x == "1");
|
||||
let disabled = crate::env("LOWFI_DISABLE_UI");
|
||||
if disabled && !cfg!(feature = "mpris") {
|
||||
return Err(ui::Error::RejectedDisable);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user