feat(mpris): Restructuring and cleanup
* MPRIS: Restructured existing implementation
My pr addresses some of the inconsistencies in ncspot's mpris
implementation. While the previous logic was technically good enough, it
was inflexible and reported redundant information.
This will make it easier for software, that processes mpris events in
some way, to accurately react to player updates.
- 'Metadata' and 'Playback' updates have been separated into there own
command
- Mpris commands are only emitted from within spotify.rs
- Some parts of the application creation logic has been
restructured to allow for mpris events to be emitted upon startup
- The initial song loading code has been moved from 'Queue::new'
into 'Application::new'.
* MPRIS: implemented most clippy suggestions
* Fix: applied clippy suggestions + format
* MPRIS: Renamed MprisCommands to be more resonable
I've added a clippy exception so it does not complain to us about enum
variants starting with the same prefix.
---------
Co-authored-by: haruInDisguise <--help>
This commit is contained in:
@@ -16,7 +16,7 @@ use librespot_playback::config::PlayerConfig;
|
||||
use librespot_playback::mixer::softmixer::SoftMixer;
|
||||
use librespot_playback::mixer::MixerConfig;
|
||||
use librespot_playback::player::Player;
|
||||
use log::{debug, error, info};
|
||||
use log::{debug, error, info, warn};
|
||||
use tokio::sync::mpsc;
|
||||
use url::Url;
|
||||
|
||||
@@ -319,6 +319,9 @@ impl Spotify {
|
||||
start_playing,
|
||||
position_ms,
|
||||
));
|
||||
|
||||
#[cfg(feature = "mpris")]
|
||||
self.send_mpris(MprisCommand::EmitMetadataStatus);
|
||||
}
|
||||
|
||||
/// Update the cached status of the [Player]. This makes sure the status
|
||||
@@ -342,6 +345,9 @@ impl Spotify {
|
||||
|
||||
let mut status = self.status.write().unwrap();
|
||||
*status = new_status;
|
||||
|
||||
#[cfg(feature = "mpris")]
|
||||
self.send_mpris(MprisCommand::EmitPlaybackStatus);
|
||||
}
|
||||
|
||||
/// Reset the time tracking stats for the current song. This should be called when a new song is
|
||||
@@ -366,6 +372,17 @@ impl Spotify {
|
||||
}
|
||||
}
|
||||
|
||||
/// Send an [MprisCommand] to the mpris thread.
|
||||
#[cfg(feature = "mpris")]
|
||||
fn send_mpris(&self, cmd: MprisCommand) {
|
||||
debug!("Sending mpris command: {:?}", cmd);
|
||||
if let Some(mpris_manager) = self.mpris.lock().unwrap().as_ref() {
|
||||
mpris_manager.send(cmd);
|
||||
} else {
|
||||
warn!("mpris context is unitialized");
|
||||
}
|
||||
}
|
||||
|
||||
/// Send a [WorkerCommand] to the worker thread.
|
||||
fn send_worker(&self, cmd: WorkerCommand) {
|
||||
info!("sending command to worker: {:?}", cmd);
|
||||
@@ -422,10 +439,7 @@ impl Spotify {
|
||||
// MPRIS implementation.
|
||||
if notify {
|
||||
#[cfg(feature = "mpris")]
|
||||
if let Some(mpris_manager) = self.mpris.lock().unwrap().as_ref() {
|
||||
info!("updating MPRIS volume");
|
||||
mpris_manager.send(MprisCommand::NotifyVolumeUpdate);
|
||||
}
|
||||
self.send_mpris(MprisCommand::EmitVolumeStatus)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user