feat(qbzd): make MPRIS a persisted, TUI-toggleable setting (default on)
MPRIS enablement moves from env-only to a persisted daemon pref, exposed as the
canonical `playback.mpris` setting key so it round-trips through `qbzd settings
show|set`, the settings bundle, AND a toggle in the setup-TUI:
- daemon_prefs gains `mpris_enabled: bool` (default true; unknown-field guard
updated).
- `playback.mpris` added to the settings KEY_TABLE (ApplyClass::None), with the
read (`settings show`) and write (`settings set`) arms; the per-canonical-key
round-trip test now covers it.
- setup-TUI Playback screen: a new "MEDIA CONTROLS" group with a System media
controls toggle, carrying a description line ("MPRIS: KDE/GNOME media widget +
media keys · restart to apply") since it applies at next daemon start.
- `mpris::enabled(roots)`: QBZD_MPRIS env still wins when set (deploy override);
otherwise the persisted toggle decides. Default stays ON.
280 tests green.
cc
This commit is contained in:
6 files changed
+58
-14
No files matched your search
@@ -87,6 +87,7 @@ const KEY_TABLE: &[(&str, ApplyClass)] = &[
|
||||
("playback.persist_session", ApplyClass::None),
|
||||
("playback.resume_playback_position", ApplyClass::None),
|
||||
("playback.show_context_icon", ApplyClass::None),
|
||||
("playback.mpris", ApplyClass::None),
|
||||
// --- qconnect (daemon-root qconnect_settings.db KV, T9) ----------------
|
||||
("qconnect.device_name", ApplyClass::None),
|
||||
("qconnect.startup_mode", ApplyClass::None),
|
||||
@@ -325,6 +326,7 @@ fn read_all(roots: &ProfileRoots) -> Result<Vec<(&'static str, String)>, String>
|
||||
"playback.persist_session" => render_bool(playback.persist_session),
|
||||
"playback.resume_playback_position" => render_bool(playback.resume_playback_position),
|
||||
"playback.show_context_icon" => render_bool(playback.show_context_icon),
|
||||
"playback.mpris" => render_bool(prefs.mpris_enabled),
|
||||
"qconnect.device_name" => render_opt_string(&qconnect_kv::load_device_name_at(&db)),
|
||||
"qconnect.startup_mode" => qconnect_kv::load_startup_mode_at(&db).as_str().to_string(),
|
||||
"qconnect.volume_mode" => {
|
||||
@@ -505,6 +507,12 @@ pub(crate) fn write_one(roots: &ProfileRoots, key: &str, raw: &str) -> Result<Ap
|
||||
prefs.streaming_quality = v;
|
||||
daemon_prefs::save_at(&prefs, &roots.data).map_err(SetError::Io)?;
|
||||
}
|
||||
"playback.mpris" => {
|
||||
let v = parse_bool(raw).map_err(SetError::Usage)?;
|
||||
let mut prefs = daemon_prefs::load_at(&roots.data);
|
||||
prefs.mpris_enabled = v;
|
||||
daemon_prefs::save_at(&prefs, &roots.data).map_err(SetError::Io)?;
|
||||
}
|
||||
"playback.autoplay" => {
|
||||
let v = parse_autoplay(raw).map_err(SetError::Usage)?;
|
||||
open_playback(roots).map_err(SetError::Io)?.set_autoplay_mode(v).map_err(SetError::Io)?
|
||||
|
||||
@@ -53,12 +53,15 @@ impl MprisHandle {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether MPRIS should be published (see the module header).
|
||||
fn enabled() -> bool {
|
||||
match std::env::var("QBZD_MPRIS") {
|
||||
Ok(v) => !matches!(v.trim().to_ascii_lowercase().as_str(), "0" | "false" | "off" | "no"),
|
||||
Err(_) => true,
|
||||
/// Whether MPRIS should be published. The `QBZD_MPRIS` env var wins when set
|
||||
/// (deploy/override knob); otherwise the persisted `daemon_prefs.mpris_enabled`
|
||||
/// toggle decides (default ON), which is what the setup-TUI Playback screen and
|
||||
/// `qbzd settings set playback.mpris` write.
|
||||
fn enabled(roots: &ProfileRoots) -> bool {
|
||||
if let Ok(v) = std::env::var("QBZD_MPRIS") {
|
||||
return !matches!(v.trim().to_ascii_lowercase().as_str(), "0" | "false" | "off" | "no");
|
||||
}
|
||||
qbz_app::settings::daemon_prefs::load_at(&roots.data).mpris_enabled
|
||||
}
|
||||
|
||||
/// Spawn the MPRIS integration. Returns None when disabled, on a non-Linux
|
||||
@@ -69,8 +72,8 @@ pub fn spawn(
|
||||
mut bus: broadcast::Receiver<CoreEvent>,
|
||||
handle: Handle,
|
||||
) -> Option<MprisHandle> {
|
||||
if !enabled() {
|
||||
log::info!("[mpris] disabled via QBZD_MPRIS");
|
||||
if !enabled(&roots) {
|
||||
log::info!("[mpris] disabled (playback.mpris / QBZD_MPRIS)");
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
@@ -446,8 +446,8 @@ impl App {
|
||||
let playback = PlaybackPreferencesStore::new_at(&self.roots.data)
|
||||
.and_then(|s| s.get_preferences())
|
||||
.unwrap_or_default();
|
||||
let quality = daemon_prefs::load_at(&self.roots.data).streaming_quality;
|
||||
Active::Playback(PlaybackState::new(&quality, &audio, &playback))
|
||||
let dp = daemon_prefs::load_at(&self.roots.data);
|
||||
Active::Playback(PlaybackState::new(&dp.streaming_quality, dp.mpris_enabled, &audio, &playback))
|
||||
}
|
||||
Screen::QConnect => {
|
||||
let db = self.roots.data.join("qconnect_settings.db");
|
||||
@@ -1780,6 +1780,7 @@ mod tests {
|
||||
Screen::Audio => Active::Audio(AudioState::new(&AudioSettings::default())),
|
||||
Screen::Playback => Active::Playback(PlaybackState::new(
|
||||
"hires_plus",
|
||||
true,
|
||||
&AudioSettings::default(),
|
||||
&qbz_app::settings::playback::PlaybackPreferences::default(),
|
||||
)),
|
||||
|
||||
@@ -42,6 +42,7 @@ pub struct StagedPlayback {
|
||||
pub gapless: bool, // audio.gapless_enabled
|
||||
pub restore_session: bool, // playback.persist_session
|
||||
pub resume_position: bool, // playback.resume_playback_position
|
||||
pub mpris: bool, // playback.mpris (applies on restart)
|
||||
/// Read-only, from the audio store — drives the Gapless disabled reason.
|
||||
pub streaming_only: bool,
|
||||
}
|
||||
@@ -57,6 +58,7 @@ pub enum PField {
|
||||
Gapless,
|
||||
Restore,
|
||||
Resume,
|
||||
Mpris,
|
||||
}
|
||||
|
||||
/// `(shown, enabled, reason)` per §3.3.
|
||||
@@ -84,7 +86,7 @@ pub fn row_state(field: PField, p: &StagedPlayback) -> (bool, bool, Option<&'sta
|
||||
|
||||
pub fn visible_fields(p: &StagedPlayback) -> Vec<PField> {
|
||||
use PField::*;
|
||||
[Quality, Limit, MaxRate, AllowFallback, RetryFail, Continue, Gapless, Restore, Resume]
|
||||
[Quality, Limit, MaxRate, AllowFallback, RetryFail, Continue, Gapless, Restore, Resume, Mpris]
|
||||
.into_iter()
|
||||
.filter(|f| row_state(*f, p).0)
|
||||
.collect()
|
||||
@@ -104,7 +106,7 @@ pub struct PlaybackState {
|
||||
}
|
||||
|
||||
impl PlaybackState {
|
||||
pub fn new(quality: &str, audio: &AudioSettings, prefs: &PlaybackPreferences) -> Self {
|
||||
pub fn new(quality: &str, mpris: bool, audio: &AudioSettings, prefs: &PlaybackPreferences) -> Self {
|
||||
let staged = StagedPlayback {
|
||||
quality: quality.to_string(),
|
||||
limit_to_device: audio.limit_quality_to_device,
|
||||
@@ -115,6 +117,7 @@ impl PlaybackState {
|
||||
gapless: audio.gapless_enabled,
|
||||
restore_session: prefs.persist_session,
|
||||
resume_position: prefs.resume_playback_position,
|
||||
mpris,
|
||||
streaming_only: audio.streaming_only,
|
||||
};
|
||||
Self {
|
||||
@@ -184,6 +187,9 @@ impl PlaybackState {
|
||||
if a.resume_position != b.resume_position {
|
||||
out.push(("playback.resume_playback_position".to_string(), a.resume_position.to_string()));
|
||||
}
|
||||
if a.mpris != b.mpris {
|
||||
out.push(("playback.mpris".to_string(), a.mpris.to_string()));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -272,6 +278,7 @@ impl PlaybackState {
|
||||
PField::Gapless => self.staged.gapless ^= true,
|
||||
PField::Restore => self.staged.restore_session ^= true,
|
||||
PField::Resume => self.staged.resume_position ^= true,
|
||||
PField::Mpris => self.staged.mpris ^= true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,6 +361,12 @@ impl PlaybackState {
|
||||
widgets::push_section(&mut secs, &mut anchor, s::PLAYBACK_GROUP_SESSION, active(session), sess_lines, sess_a);
|
||||
}
|
||||
|
||||
let controls: &[PField] = &[Mpris];
|
||||
let (ctl_lines, ctl_a) = self.group_block(&fields, controls, focused_field, ctrl_col, width);
|
||||
if !ctl_lines.is_empty() {
|
||||
widgets::push_section(&mut secs, &mut anchor, s::PLAYBACK_GROUP_CONTROLS, active(controls), ctl_lines, ctl_a);
|
||||
}
|
||||
|
||||
widgets::sections_scroll(f, area, &secs, anchor);
|
||||
|
||||
match &self.editor {
|
||||
@@ -401,7 +414,7 @@ impl PlaybackState {
|
||||
focused,
|
||||
enabled,
|
||||
reason,
|
||||
description: None,
|
||||
description: field_description(field),
|
||||
};
|
||||
widgets::field_block(&f, ctrl_col, width)
|
||||
}
|
||||
@@ -419,10 +432,20 @@ impl PlaybackState {
|
||||
PField::Gapless => (s::P_GAPLESS, on_off(a.gapless), "[toggle]"),
|
||||
PField::Restore => (s::P_RESTORE, on_off(a.restore_session), "[toggle]"),
|
||||
PField::Resume => (s::P_RESUME_POS, on_off(a.resume_position), "[toggle]"),
|
||||
PField::Mpris => (s::P_MPRIS, on_off(a.mpris), "[toggle]"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Static one-line help wrapped under a field's label. Only Mpris carries one
|
||||
/// (it needs a restart to apply, unlike the live-ish other toggles).
|
||||
fn field_description(field: PField) -> Option<&'static str> {
|
||||
match field {
|
||||
PField::Mpris => Some(s::P_MPRIS_DESC),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
// ============================ mappers ============================
|
||||
|
||||
fn quality_label(q: &str) -> &'static str {
|
||||
@@ -473,6 +496,7 @@ mod tests {
|
||||
fn base() -> StagedPlayback {
|
||||
PlaybackState::new(
|
||||
"hires_plus",
|
||||
true,
|
||||
&AudioSettings::default(),
|
||||
&PlaybackPreferences::default(),
|
||||
)
|
||||
@@ -481,7 +505,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn ask_renders_note_and_is_never_written() {
|
||||
let mut st = PlaybackState::new("hires_plus", &AudioSettings::default(), &PlaybackPreferences::default());
|
||||
let mut st = PlaybackState::new("hires_plus", true, &AudioSettings::default(), &PlaybackPreferences::default());
|
||||
// AudioSettings::default() seeds fallback_behavior = "ask".
|
||||
assert_eq!(st.staged.fallback_behavior, "ask");
|
||||
assert_eq!(retry_label("ask"), s::RETRY_ASK);
|
||||
|
||||
@@ -203,6 +203,7 @@ pub const PLAYBACK_TITLE: &str = "Playback";
|
||||
pub const PLAYBACK_GROUP_QUALITY: &str = "QUALITY";
|
||||
pub const PLAYBACK_GROUP_BEHAVIOR: &str = "BEHAVIOR";
|
||||
pub const PLAYBACK_GROUP_SESSION: &str = "SESSION";
|
||||
pub const PLAYBACK_GROUP_CONTROLS: &str = "MEDIA CONTROLS";
|
||||
|
||||
pub const P_QUALITY: &str = "Streaming quality";
|
||||
pub const P_LIMIT_DEVICE: &str = "Limit quality to device";
|
||||
@@ -213,6 +214,8 @@ pub const P_CONTINUE: &str = "Continue after track";
|
||||
pub const P_GAPLESS: &str = "Gapless playback";
|
||||
pub const P_RESTORE: &str = "Restore session";
|
||||
pub const P_RESUME_POS: &str = "Resume position";
|
||||
pub const P_MPRIS: &str = "System media controls";
|
||||
pub const P_MPRIS_DESC: &str = "MPRIS: KDE/GNOME media widget + media keys · restart to apply";
|
||||
|
||||
pub const R_LIMIT_OFF: &str = "Limit quality to device off";
|
||||
pub const R_STREAMING_ONLY_ON: &str = "off while Audio > Streaming only on";
|
||||
|
||||
Reference in new issue
Block a user