Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bcba21f1a | ||
|
|
ab42814302 |
@@ -2,6 +2,18 @@
|
||||
|
||||
One section per version, newest first.
|
||||
|
||||
## v0.7.0 (2026-11-04)
|
||||
|
||||
### Features
|
||||
|
||||
- Remus is an MPRIS player, so media keys, headphone buttons and the desktop's media controls can play, pause and skip, and the desktop shows the track that is playing. Headphone buttons work wherever the system passes them to MPRIS, as KDE does in Desktop Mode.
|
||||
|
||||
## v0.6.8 (2026-11-04)
|
||||
|
||||
### Features
|
||||
|
||||
- Settings has a Show controls bar toggle. Turned off, the bar with the button hints and the version is hidden on the browse and now-playing screens, and Settings lists the version instead. The login screen always shows it.
|
||||
|
||||
## v0.6.7 (2026-11-04)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Generated
+1
-1
@@ -4385,7 +4385,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "remus"
|
||||
version = "0.6.7"
|
||||
version = "0.7.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"directories",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "remus"
|
||||
version = "0.6.7"
|
||||
version = "0.7.0"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
</supports>
|
||||
<content_rating type="oars-1.1"/>
|
||||
<releases>
|
||||
<release version="0.7.0" date="2026-11-04"/>
|
||||
<release version="0.6.8" date="2026-11-04"/>
|
||||
<release version="0.6.7" date="2026-11-04"/>
|
||||
<release version="0.6.6" date="2026-11-04"/>
|
||||
<release version="0.6.5" date="2026-11-04"/>
|
||||
|
||||
@@ -18,6 +18,9 @@ finish-args:
|
||||
# Keeps the screensaver off while music plays, the way Chromium and
|
||||
# Electron apps do. The XDG portal route needs no permission.
|
||||
- --talk-name=org.freedesktop.ScreenSaver
|
||||
# MPRIS, through which the desktop's media keys and headphone buttons
|
||||
# reach the player.
|
||||
- --own-name=org.mpris.MediaPlayer2.remus
|
||||
|
||||
build-options:
|
||||
append-path: /usr/lib/sdk/rust-stable/bin
|
||||
|
||||
+109
-4
@@ -18,6 +18,7 @@ use tokio::sync::Semaphore;
|
||||
|
||||
use crate::config::{self, Config, Settings};
|
||||
use crate::inhibit::Inhibitor;
|
||||
use crate::mpris::{self, Mpris};
|
||||
use crate::palette::{Lab, Palette, Role, Tone};
|
||||
use crate::player::{Player, PlayerEvent};
|
||||
use crate::prompts::{self, Control, Family, Prompts};
|
||||
@@ -117,7 +118,7 @@ impl Section {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum Target {
|
||||
Album(String),
|
||||
Artist(String),
|
||||
@@ -131,6 +132,9 @@ enum Target {
|
||||
enum Setting {
|
||||
AlbumArtColours,
|
||||
CoverBackdrop,
|
||||
ShowHintBar,
|
||||
/// The version, listed while the hint bar that normally shows it is off.
|
||||
Version,
|
||||
}
|
||||
|
||||
/// How long the UI takes to change from one palette to the next.
|
||||
@@ -224,6 +228,8 @@ pub struct App {
|
||||
player: Option<Player>,
|
||||
/// Keeps the screensaver off while music plays. Taken at shutdown.
|
||||
inhibitor: Option<Inhibitor>,
|
||||
/// Media keys, headphone buttons and the desktop's media controls.
|
||||
mpris: Mpris,
|
||||
screen: Screen,
|
||||
area: Area,
|
||||
section: usize,
|
||||
@@ -294,12 +300,16 @@ impl App {
|
||||
log::warn!("cover cache disabled, cannot create {}: {e}", d.display());
|
||||
}
|
||||
let inhibitor = Inhibitor::spawn(&rt);
|
||||
let mpris = Mpris::spawn(&rt, |c| {
|
||||
let _ = slint::invoke_from_event_loop(move || with_app(move |app| app.mpris_command(c)));
|
||||
});
|
||||
App {
|
||||
ui,
|
||||
rt,
|
||||
client: None,
|
||||
player: None,
|
||||
inhibitor: Some(inhibitor),
|
||||
mpris,
|
||||
screen: Screen::Login,
|
||||
area: Area::Content,
|
||||
section: 0,
|
||||
@@ -352,6 +362,7 @@ impl App {
|
||||
|
||||
fn start(&mut self) {
|
||||
self.render_backdrop();
|
||||
self.ui.set_show_hint_bar(self.settings.show_hint_bar);
|
||||
let labels: Vec<SharedString> = SECTIONS.iter().map(|s| s.label().into()).collect();
|
||||
self.ui.set_sections(ModelRc::new(VecModel::from(labels)));
|
||||
|
||||
@@ -913,8 +924,9 @@ impl App {
|
||||
fn toggle_setting(&mut self, setting: Setting) {
|
||||
match setting {
|
||||
Setting::AlbumArtColours => self.settings.album_art_colours = !self.settings.album_art_colours,
|
||||
Setting::ShowHintBar => self.settings.show_hint_bar = !self.settings.show_hint_bar,
|
||||
// A range: left and right change it, confirm does nothing.
|
||||
Setting::CoverBackdrop => return,
|
||||
Setting::CoverBackdrop | Setting::Version => return,
|
||||
}
|
||||
self.settings_changed();
|
||||
}
|
||||
@@ -929,7 +941,7 @@ impl App {
|
||||
}
|
||||
self.settings.cover_backdrop = v;
|
||||
}
|
||||
Setting::AlbumArtColours => return,
|
||||
Setting::AlbumArtColours | Setting::ShowHintBar | Setting::Version => return,
|
||||
}
|
||||
self.settings_changed();
|
||||
}
|
||||
@@ -948,6 +960,7 @@ impl App {
|
||||
}
|
||||
}
|
||||
self.render_backdrop();
|
||||
self.ui.set_show_hint_bar(self.settings.show_hint_bar);
|
||||
self.update_theme();
|
||||
}
|
||||
|
||||
@@ -995,6 +1008,7 @@ impl App {
|
||||
}
|
||||
self.ui.set_volume(self.settings.volume as i32);
|
||||
self.ui.set_muted(self.settings.muted);
|
||||
self.sync_mpris();
|
||||
}
|
||||
|
||||
fn show_volume(&mut self) {
|
||||
@@ -1476,6 +1490,7 @@ impl App {
|
||||
match target {
|
||||
Some(Target::Song(_)) => h(Control::Activate, "Play"),
|
||||
Some(Target::Setting(Setting::CoverBackdrop)) => h(Control::Seek, "Adjust"),
|
||||
Some(Target::Setting(Setting::Version)) => {}
|
||||
Some(Target::Setting(_)) => h(Control::Activate, "Change"),
|
||||
Some(_) => h(Control::Activate, "Open"),
|
||||
None if self.current_page().is_some_and(|p| p.error.is_some()) => {
|
||||
@@ -1814,6 +1829,54 @@ impl App {
|
||||
}
|
||||
}
|
||||
self.sync_inhibit();
|
||||
self.sync_mpris();
|
||||
}
|
||||
|
||||
/// Tells MPRIS clients what is playing.
|
||||
fn sync_mpris(&self) {
|
||||
let track = self.current.and_then(|i| self.queue.get(i).map(|s| (i, s)));
|
||||
let status = match track {
|
||||
None => mpris::Status::Stopped,
|
||||
Some(_) if self.paused || self.held => mpris::Status::Paused,
|
||||
Some(_) => mpris::Status::Playing,
|
||||
};
|
||||
let volume = if self.settings.muted {
|
||||
0.0
|
||||
} else {
|
||||
self.settings.volume as f64 / 100.0
|
||||
};
|
||||
self.mpris.update(mpris::NowPlaying {
|
||||
status,
|
||||
track: track.map(|(index, s)| mpris::Track {
|
||||
index,
|
||||
title: s.title.clone(),
|
||||
artist: s.artist.clone(),
|
||||
album: s.album.clone(),
|
||||
seconds: s.duration,
|
||||
}),
|
||||
volume,
|
||||
});
|
||||
}
|
||||
|
||||
/// A media key, headphone button or desktop control, through MPRIS.
|
||||
fn mpris_command(&mut self, c: mpris::Command) {
|
||||
let playing = self.current.is_some() && !self.paused && !self.held;
|
||||
let action = match c {
|
||||
mpris::Command::PlayPause => Action::PlayPause,
|
||||
mpris::Command::Play if !playing => Action::PlayPause,
|
||||
mpris::Command::Pause | mpris::Command::Stop if playing => Action::PlayPause,
|
||||
mpris::Command::Next => Action::Next,
|
||||
mpris::Command::Previous => Action::Prev,
|
||||
mpris::Command::Quit => Action::Quit,
|
||||
_ => return,
|
||||
};
|
||||
log::debug!("MPRIS {c:?}");
|
||||
// Not on the login screen: nothing is loaded there.
|
||||
if action == Action::Quit {
|
||||
self.action(action);
|
||||
} else if self.screen != Screen::Login {
|
||||
self.global_action(action);
|
||||
}
|
||||
}
|
||||
|
||||
/// Inhibits only while sound is coming out: a restored queue is loaded
|
||||
@@ -1920,6 +1983,7 @@ impl App {
|
||||
self.ui.set_np_progress(progress as f32);
|
||||
self.ui.set_np_position(fmt_time(self.position).into());
|
||||
self.ui.set_np_duration(fmt_time(self.duration).into());
|
||||
self.mpris.set_position(self.position);
|
||||
}
|
||||
|
||||
fn render_player(&mut self) {
|
||||
@@ -1947,6 +2011,7 @@ impl App {
|
||||
}
|
||||
}
|
||||
self.render_progress();
|
||||
self.sync_mpris();
|
||||
self.update_theme();
|
||||
}
|
||||
|
||||
@@ -2222,7 +2287,7 @@ fn song_entry(s: &Song, index: usize) -> Entry {
|
||||
|
||||
fn settings_data(s: &Settings) -> PageData {
|
||||
let on_off = |on: bool| if on { "On" } else { "Off" }.to_string();
|
||||
PageData {
|
||||
let mut data = PageData {
|
||||
entries: vec![
|
||||
Entry {
|
||||
title: "Colours from album art".to_string(),
|
||||
@@ -2248,9 +2313,33 @@ fn settings_data(s: &Settings) -> PageData {
|
||||
show_art: false,
|
||||
target: Target::Setting(Setting::CoverBackdrop),
|
||||
},
|
||||
Entry {
|
||||
title: "Show controls bar".to_string(),
|
||||
subtitle: "The buttons for each screen and the version, at the bottom".to_string(),
|
||||
detail: on_off(s.show_hint_bar),
|
||||
number: String::new(),
|
||||
cover: None,
|
||||
round: false,
|
||||
show_art: false,
|
||||
target: Target::Setting(Setting::ShowHintBar),
|
||||
},
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
// The bar is where the version normally shows.
|
||||
if !s.show_hint_bar {
|
||||
data.entries.push(Entry {
|
||||
title: "Version".to_string(),
|
||||
subtitle: String::new(),
|
||||
detail: concat!("remus ", env!("CARGO_PKG_VERSION")).to_string(),
|
||||
number: String::new(),
|
||||
cover: None,
|
||||
round: false,
|
||||
show_art: false,
|
||||
target: Target::Setting(Setting::Version),
|
||||
});
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
/// One step of the volume, kept within 0 to 100.
|
||||
@@ -2474,6 +2563,22 @@ mod tests {
|
||||
assert_ne!(a, c);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_is_listed_in_settings_only_while_the_bar_is_hidden() {
|
||||
let has_version = |show_hint_bar: bool| {
|
||||
let s = Settings {
|
||||
show_hint_bar,
|
||||
..Settings::default()
|
||||
};
|
||||
settings_data(&s)
|
||||
.entries
|
||||
.iter()
|
||||
.any(|e| e.target == Target::Setting(Setting::Version))
|
||||
};
|
||||
assert!(!has_version(true));
|
||||
assert!(has_version(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn volume_steps_stay_in_range() {
|
||||
assert_eq!(step_volume(50, true), 55);
|
||||
|
||||
@@ -99,6 +99,9 @@ pub struct Settings {
|
||||
pub volume: u8,
|
||||
/// Muted, keeping `volume` for when it is unmuted.
|
||||
pub muted: bool,
|
||||
/// The bar with the button hints and the version. The login screen shows
|
||||
/// it regardless.
|
||||
pub show_hint_bar: bool,
|
||||
}
|
||||
|
||||
/// The cover backdrop strength that looks like it did before it was a setting.
|
||||
@@ -111,6 +114,7 @@ impl Default for Settings {
|
||||
cover_backdrop: COVER_BACKDROP_DEFAULT,
|
||||
volume: 100,
|
||||
muted: false,
|
||||
show_hint_bar: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,6 +220,7 @@ mod tests {
|
||||
assert_eq!(s.cover_backdrop, COVER_BACKDROP_DEFAULT);
|
||||
assert_eq!(s.volume, 100);
|
||||
assert!(!s.muted);
|
||||
assert!(s.show_hint_bar);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -223,6 +228,7 @@ mod tests {
|
||||
let s: Settings = toml::from_str("album_art_colours = true\n").unwrap();
|
||||
assert!(s.album_art_colours);
|
||||
assert_eq!(s.cover_backdrop, COVER_BACKDROP_DEFAULT);
|
||||
assert!(s.show_hint_bar);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -232,6 +238,7 @@ mod tests {
|
||||
cover_backdrop: 70,
|
||||
volume: 35,
|
||||
muted: true,
|
||||
show_hint_bar: false,
|
||||
};
|
||||
let back: Settings = toml::from_str(&toml::to_string(&s).unwrap()).unwrap();
|
||||
assert_eq!(back, s);
|
||||
|
||||
@@ -5,6 +5,7 @@ mod config;
|
||||
mod devscript;
|
||||
mod inhibit;
|
||||
mod input;
|
||||
mod mpris;
|
||||
mod palette;
|
||||
mod player;
|
||||
mod prompts;
|
||||
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
//! MPRIS on the session bus, so the desktop's media controls and media keys
|
||||
//! can drive playback. Headphone buttons arrive this way too: the desktop
|
||||
//! turns the key events of a headset or a Bluetooth AVRCP device into calls
|
||||
//! on the active MPRIS player. Reading those devices directly is not an
|
||||
//! option, since keyboard-like input devices are root:input and only
|
||||
//! gamepads are opened up to the logged-in user.
|
||||
//!
|
||||
//! A bus that cannot be reached, or a name already taken by another remus,
|
||||
//! is logged once and otherwise ignored.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicI64, Ordering};
|
||||
|
||||
use anyhow::Result;
|
||||
use tokio::runtime::Handle;
|
||||
use tokio::sync::watch;
|
||||
use zbus::interface;
|
||||
use zbus::zvariant::{ObjectPath, OwnedValue, Value};
|
||||
|
||||
const BUS_NAME: &str = "org.mpris.MediaPlayer2.remus";
|
||||
const PATH: &str = "/org/mpris/MediaPlayer2";
|
||||
const DESKTOP_ENTRY: &str = "me.anshorei.Fettleshed.Remus";
|
||||
|
||||
/// What a client asked for.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Command {
|
||||
PlayPause,
|
||||
Play,
|
||||
Pause,
|
||||
Stop,
|
||||
Next,
|
||||
Previous,
|
||||
Quit,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum Status {
|
||||
#[default]
|
||||
Stopped,
|
||||
Paused,
|
||||
Playing,
|
||||
}
|
||||
|
||||
impl Status {
|
||||
fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Status::Stopped => "Stopped",
|
||||
Status::Paused => "Paused",
|
||||
Status::Playing => "Playing",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct Track {
|
||||
/// Position in the queue, which makes the track id.
|
||||
pub index: usize,
|
||||
pub title: String,
|
||||
pub artist: Option<String>,
|
||||
pub album: Option<String>,
|
||||
pub seconds: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct NowPlaying {
|
||||
pub status: Status,
|
||||
pub track: Option<Track>,
|
||||
/// 0 to 1, already muted to 0.
|
||||
pub volume: f64,
|
||||
}
|
||||
|
||||
pub struct Mpris {
|
||||
state: watch::Sender<NowPlaying>,
|
||||
position: Arc<AtomicI64>,
|
||||
}
|
||||
|
||||
impl Mpris {
|
||||
pub fn spawn(rt: &Handle, on_command: impl Fn(Command) + Send + Sync + 'static) -> Mpris {
|
||||
let (state, rx) = watch::channel(NowPlaying::default());
|
||||
let position = Arc::new(AtomicI64::new(0));
|
||||
let pos = position.clone();
|
||||
let on_command: Arc<dyn Fn(Command) + Send + Sync> = Arc::new(on_command);
|
||||
rt.spawn(async move {
|
||||
if let Err(e) = run(rx, pos, on_command).await {
|
||||
log::warn!("MPRIS unavailable, media keys will not reach remus: {e:#}");
|
||||
}
|
||||
});
|
||||
Mpris { state, position }
|
||||
}
|
||||
|
||||
/// Publishes what is playing. Clients hear only about what changed.
|
||||
pub fn update(&self, now: NowPlaying) {
|
||||
self.state.send_if_modified(|s| {
|
||||
let changed = *s != now;
|
||||
*s = now;
|
||||
changed
|
||||
});
|
||||
}
|
||||
|
||||
/// Clients read the position when they want it; it sends no signal.
|
||||
pub fn set_position(&self, seconds: f64) {
|
||||
self.position.store((seconds * 1e6) as i64, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
async fn run(
|
||||
mut rx: watch::Receiver<NowPlaying>,
|
||||
position: Arc<AtomicI64>,
|
||||
on_command: Arc<dyn Fn(Command) + Send + Sync>,
|
||||
) -> Result<()> {
|
||||
let player = Player {
|
||||
now: rx.borrow().clone(),
|
||||
position,
|
||||
on_command: on_command.clone(),
|
||||
};
|
||||
let conn = zbus::connection::Builder::session()?
|
||||
.name(BUS_NAME)?
|
||||
.serve_at(PATH, Root { on_command })?
|
||||
.serve_at(PATH, player)?
|
||||
.build()
|
||||
.await?;
|
||||
log::info!("MPRIS player registered as {BUS_NAME}");
|
||||
let iface = conn.object_server().interface::<_, Player>(PATH).await?;
|
||||
while rx.changed().await.is_ok() {
|
||||
let now = rx.borrow_and_update().clone();
|
||||
let mut p = iface.get_mut().await;
|
||||
let status = p.now.status != now.status;
|
||||
let track = p.now.track != now.track;
|
||||
let volume = p.now.volume != now.volume;
|
||||
p.now = now;
|
||||
let emitter = iface.signal_emitter();
|
||||
if status {
|
||||
p.playback_status_changed(emitter).await?;
|
||||
}
|
||||
if track {
|
||||
p.metadata_changed(emitter).await?;
|
||||
p.can_play_changed(emitter).await?;
|
||||
p.can_pause_changed(emitter).await?;
|
||||
p.can_go_next_changed(emitter).await?;
|
||||
p.can_go_previous_changed(emitter).await?;
|
||||
}
|
||||
if volume {
|
||||
p.volume_changed(emitter).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct Root {
|
||||
on_command: Arc<dyn Fn(Command) + Send + Sync>,
|
||||
}
|
||||
|
||||
#[interface(name = "org.mpris.MediaPlayer2")]
|
||||
impl Root {
|
||||
fn raise(&self) {}
|
||||
|
||||
fn quit(&self) {
|
||||
(self.on_command)(Command::Quit);
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_quit(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_raise(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn has_track_list(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn identity(&self) -> &str {
|
||||
"Remus"
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn desktop_entry(&self) -> &str {
|
||||
DESKTOP_ENTRY
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn supported_uri_schemes(&self) -> Vec<String> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn supported_mime_types(&self) -> Vec<String> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
struct Player {
|
||||
now: NowPlaying,
|
||||
position: Arc<AtomicI64>,
|
||||
on_command: Arc<dyn Fn(Command) + Send + Sync>,
|
||||
}
|
||||
|
||||
#[interface(name = "org.mpris.MediaPlayer2.Player")]
|
||||
impl Player {
|
||||
fn play_pause(&self) {
|
||||
(self.on_command)(Command::PlayPause);
|
||||
}
|
||||
|
||||
fn play(&self) {
|
||||
(self.on_command)(Command::Play);
|
||||
}
|
||||
|
||||
fn pause(&self) {
|
||||
(self.on_command)(Command::Pause);
|
||||
}
|
||||
|
||||
fn stop(&self) {
|
||||
(self.on_command)(Command::Stop);
|
||||
}
|
||||
|
||||
fn next(&self) {
|
||||
(self.on_command)(Command::Next);
|
||||
}
|
||||
|
||||
fn previous(&self) {
|
||||
(self.on_command)(Command::Previous);
|
||||
}
|
||||
|
||||
// CanSeek is false, so clients do not call these; they are part of the
|
||||
// interface all the same.
|
||||
fn seek(&self, _offset: i64) {}
|
||||
|
||||
fn set_position(&self, _track_id: ObjectPath<'_>, _position: i64) {}
|
||||
|
||||
fn open_uri(&self, _uri: &str) {}
|
||||
|
||||
#[zbus(property)]
|
||||
fn playback_status(&self) -> &str {
|
||||
self.now.status.as_str()
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn rate(&self) -> f64 {
|
||||
1.0
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn minimum_rate(&self) -> f64 {
|
||||
1.0
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn maximum_rate(&self) -> f64 {
|
||||
1.0
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn metadata(&self) -> HashMap<String, OwnedValue> {
|
||||
metadata(self.now.track.as_ref())
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn volume(&self) -> f64 {
|
||||
self.now.volume
|
||||
}
|
||||
|
||||
#[zbus(property(emits_changed_signal = "false"))]
|
||||
fn position(&self) -> i64 {
|
||||
self.position.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_go_next(&self) -> bool {
|
||||
self.now.track.is_some()
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_go_previous(&self) -> bool {
|
||||
self.now.track.is_some()
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_play(&self) -> bool {
|
||||
self.now.track.is_some()
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_pause(&self) -> bool {
|
||||
self.now.track.is_some()
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_seek(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[zbus(property(emits_changed_signal = "const"))]
|
||||
fn can_control(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// The MPRIS metadata map for a track, empty when nothing is loaded.
|
||||
fn metadata(track: Option<&Track>) -> HashMap<String, OwnedValue> {
|
||||
let mut m = HashMap::new();
|
||||
let Some(t) = track else {
|
||||
let none = ObjectPath::from_static_str_unchecked("/org/mpris/MediaPlayer2/TrackList/NoTrack");
|
||||
insert(&mut m, "mpris:trackid", Value::from(none));
|
||||
return m;
|
||||
};
|
||||
// Outside /org/mpris, which the spec reserves.
|
||||
let id = format!("/me/anshorei/Fettleshed/Remus/track/{}", t.index);
|
||||
if let Ok(path) = ObjectPath::try_from(id) {
|
||||
insert(&mut m, "mpris:trackid", Value::from(path));
|
||||
}
|
||||
insert(&mut m, "xesam:title", Value::from(t.title.clone()));
|
||||
if let Some(a) = &t.artist {
|
||||
insert(&mut m, "xesam:artist", Value::from(vec![a.clone()]));
|
||||
}
|
||||
if let Some(a) = &t.album {
|
||||
insert(&mut m, "xesam:album", Value::from(a.clone()));
|
||||
}
|
||||
if let Some(s) = t.seconds {
|
||||
insert(&mut m, "mpris:length", Value::from(s as i64 * 1_000_000));
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
fn insert(m: &mut HashMap<String, OwnedValue>, key: &str, value: Value<'_>) {
|
||||
if let Ok(v) = OwnedValue::try_from(value) {
|
||||
m.insert(key.to_string(), v);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn metadata_without_a_track_says_so() {
|
||||
let m = metadata(None);
|
||||
assert_eq!(m.len(), 1);
|
||||
let id: ObjectPath = m["mpris:trackid"].clone().try_into().unwrap();
|
||||
assert_eq!(id.as_str(), "/org/mpris/MediaPlayer2/TrackList/NoTrack");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn metadata_carries_the_track() {
|
||||
let t = Track {
|
||||
index: 3,
|
||||
title: "Feijão".into(),
|
||||
artist: Some("Dr. Quandary".into()),
|
||||
album: None,
|
||||
seconds: Some(218),
|
||||
};
|
||||
let m = metadata(Some(&t));
|
||||
let title: String = m["xesam:title"].clone().try_into().unwrap();
|
||||
assert_eq!(title, "Feijão");
|
||||
let artists: Vec<String> = m["xesam:artist"].clone().try_into().unwrap();
|
||||
assert_eq!(artists, ["Dr. Quandary"]);
|
||||
let length: i64 = m["mpris:length"].clone().try_into().unwrap();
|
||||
assert_eq!(length, 218_000_000);
|
||||
assert!(!m.contains_key("xesam:album"));
|
||||
let id: ObjectPath = m["mpris:trackid"].clone().try_into().unwrap();
|
||||
assert_eq!(id.as_str(), "/me/anshorei/Fettleshed/Remus/track/3");
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -1191,6 +1191,7 @@ export component AppWindow inherits Window {
|
||||
in property <int> volume;
|
||||
in property <bool> muted;
|
||||
in property <string> version;
|
||||
in property <bool> show-hint-bar: true;
|
||||
|
||||
public function focus-main() {
|
||||
fs.focus();
|
||||
@@ -1404,7 +1405,9 @@ export component AppWindow inherits Window {
|
||||
muted: root.muted;
|
||||
}
|
||||
|
||||
HintBar {
|
||||
// Optional, except on the login screen, where the controls are
|
||||
// not known yet and Settings cannot be reached.
|
||||
if root.show-hint-bar || root.screen == Screen.login: HintBar {
|
||||
height: 46px * Theme.s;
|
||||
hints: root.hints;
|
||||
version: root.version;
|
||||
|
||||
Reference in New Issue
Block a user