mirror of
https://github.com/talwat/lowfi
synced 2024-12-27 11:41:54 +00:00
feat: make MPRIS bus suffixes unique
This commit is contained in:
parent
b12a7077a8
commit
56b03290d0
@ -290,6 +290,8 @@ impl Player {
|
|||||||
///
|
///
|
||||||
/// `rx` & `tx` are used to communicate with it, for example when to
|
/// `rx` & `tx` are used to communicate with it, for example when to
|
||||||
/// skip tracks or pause.
|
/// skip tracks or pause.
|
||||||
|
///
|
||||||
|
/// This will also initialize a [Downloader] as well as an MPRIS server if enabled.
|
||||||
pub async fn play(
|
pub async fn play(
|
||||||
player: Arc<Self>,
|
player: Arc<Self>,
|
||||||
tx: Sender<Messages>,
|
tx: Sender<Messages>,
|
||||||
@ -302,7 +304,11 @@ impl Player {
|
|||||||
// specifically when it occurs, unlike the UI which passively reads the
|
// specifically when it occurs, unlike the UI which passively reads the
|
||||||
// information each frame. Blame MPRIS, not me.
|
// information each frame. Blame MPRIS, not me.
|
||||||
#[cfg(feature = "mpris")]
|
#[cfg(feature = "mpris")]
|
||||||
let mpris = mpris::Server::new(Arc::clone(&player), tx.clone()).await?;
|
let mpris = mpris::Server::new(Arc::clone(&player), tx.clone())
|
||||||
|
.await
|
||||||
|
.inspect_err(|x| {
|
||||||
|
dbg!(x);
|
||||||
|
})?;
|
||||||
|
|
||||||
// `itx` is used to notify the `Downloader` when it needs to download new tracks.
|
// `itx` is used to notify the `Downloader` when it needs to download new tracks.
|
||||||
let downloader = Downloader::new(Arc::clone(&player));
|
let downloader = Downloader::new(Arc::clone(&player));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Contains the code for the MPRIS server & other helper functions.
|
//! Contains the code for the MPRIS server & other helper functions.
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::{process, sync::Arc};
|
||||||
|
|
||||||
use mpris_server::{
|
use mpris_server::{
|
||||||
zbus::{self, fdo, Result},
|
zbus::{self, fdo, Result},
|
||||||
@ -262,9 +262,9 @@ impl Server {
|
|||||||
|
|
||||||
/// Creates a new MPRIS server.
|
/// Creates a new MPRIS server.
|
||||||
pub async fn new(player: Arc<super::Player>, sender: Sender<Messages>) -> eyre::Result<Self> {
|
pub async fn new(player: Arc<super::Player>, sender: Sender<Messages>) -> eyre::Result<Self> {
|
||||||
let server = mpris_server::Server::new("lowfi", Player { player, sender })
|
let suffix = format!("lowfi.{}.instance{}", player.list.name, process::id());
|
||||||
.await
|
|
||||||
.unwrap();
|
let server = mpris_server::Server::new(&suffix, Player { player, sender }).await?;
|
||||||
|
|
||||||
Ok(Self { inner: server })
|
Ok(Self { inner: server })
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
//! as well as obtaining track names & downloading the raw mp3 data.
|
//! as well as obtaining track names & downloading the raw mp3 data.
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use eyre::OptionExt;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
@ -13,6 +14,9 @@ use super::Track;
|
|||||||
/// See the [README](https://github.com/talwat/lowfi?tab=readme-ov-file#the-format) for more details about the format.
|
/// See the [README](https://github.com/talwat/lowfi?tab=readme-ov-file#the-format) for more details about the format.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct List {
|
pub struct List {
|
||||||
|
/// The "name" of the list, usually derived from a filename.
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
/// Just the raw file, but seperated by `/n` (newlines).
|
/// Just the raw file, but seperated by `/n` (newlines).
|
||||||
/// `lines[0]` is the base, with the rest being tracks.
|
/// `lines[0]` is the base, with the rest being tracks.
|
||||||
lines: Vec<String>,
|
lines: Vec<String>,
|
||||||
@ -59,13 +63,16 @@ impl List {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parses text into a [List].
|
/// Parses text into a [List].
|
||||||
pub fn new(text: &str) -> Self {
|
pub fn new(name: &str, text: &str) -> Self {
|
||||||
let lines: Vec<String> = text
|
let lines: Vec<String> = text
|
||||||
.split_ascii_whitespace()
|
.split_ascii_whitespace()
|
||||||
.map(ToOwned::to_owned)
|
.map(ToOwned::to_owned)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Self { lines }
|
Self {
|
||||||
|
lines,
|
||||||
|
name: name.to_owned(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a [List] from the filesystem using the CLI argument provided.
|
/// Reads a [List] from the filesystem using the CLI argument provided.
|
||||||
@ -77,15 +84,21 @@ impl List {
|
|||||||
.join("lowfi")
|
.join("lowfi")
|
||||||
.join(format!("{}.txt", arg));
|
.join(format!("{}.txt", arg));
|
||||||
|
|
||||||
let raw = if name.exists() {
|
let name = if name.exists() { name } else { arg.into() };
|
||||||
fs::read_to_string(name).await?
|
|
||||||
} else {
|
|
||||||
fs::read_to_string(arg).await?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self::new(&raw))
|
let raw = fs::read_to_string(name.clone()).await?;
|
||||||
|
|
||||||
|
let name = name
|
||||||
|
.file_stem()
|
||||||
|
.and_then(|x| x.to_str())
|
||||||
|
.ok_or_eyre("invalid track path")?;
|
||||||
|
|
||||||
|
Ok(Self::new(name, &raw))
|
||||||
} else {
|
} else {
|
||||||
Ok(Self::new(include_str!("../../data/lofigirl.txt")))
|
Ok(Self::new(
|
||||||
|
"lofigirl",
|
||||||
|
include_str!("../../data/lofigirl.txt"),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user