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:
@@ -12,7 +12,7 @@ use signal_hook::{consts::SIGHUP, consts::SIGTERM, iterator::Signals};
|
||||
|
||||
use crate::command::Command;
|
||||
use crate::commands::CommandManager;
|
||||
use crate::config::Config;
|
||||
use crate::config::{Config, PlaybackState};
|
||||
use crate::events::{Event, EventManager};
|
||||
use crate::library::Library;
|
||||
use crate::queue::Queue;
|
||||
@@ -22,7 +22,7 @@ use crate::{authentication, ui, utils};
|
||||
use crate::{command, queue, spotify};
|
||||
|
||||
#[cfg(feature = "mpris")]
|
||||
use crate::mpris::{self, MprisCommand, MprisManager};
|
||||
use crate::mpris::MprisManager;
|
||||
|
||||
#[cfg(unix)]
|
||||
use crate::ipc::{self, IpcSocket};
|
||||
@@ -68,9 +68,6 @@ pub struct Application {
|
||||
/// Internally shared
|
||||
event_manager: EventManager,
|
||||
/// An IPC implementation using the D-Bus MPRIS protocol, used to control and inspect ncspot.
|
||||
#[cfg(feature = "mpris")]
|
||||
mpris_manager: MprisManager,
|
||||
/// An IPC implementation using a Unix domain socket, used to control and inspect ncspot.
|
||||
#[cfg(unix)]
|
||||
ipc: Option<IpcSocket>,
|
||||
/// The object to render to the terminal.
|
||||
@@ -130,7 +127,7 @@ impl Application {
|
||||
));
|
||||
|
||||
#[cfg(feature = "mpris")]
|
||||
let mpris_manager = mpris::MprisManager::new(
|
||||
let mpris_manager = MprisManager::new(
|
||||
event_manager.clone(),
|
||||
queue.clone(),
|
||||
library.clone(),
|
||||
@@ -140,6 +137,27 @@ impl Application {
|
||||
#[cfg(feature = "mpris")]
|
||||
spotify.set_mpris(mpris_manager.clone());
|
||||
|
||||
// Load the last played track into the player
|
||||
let playback_state = configuration.state().playback_state.clone();
|
||||
let queue_state = configuration.state().queuestate.clone();
|
||||
|
||||
if let Some(playable) = queue.get_current() {
|
||||
spotify.load(
|
||||
&playable,
|
||||
playback_state == PlaybackState::Playing,
|
||||
queue_state.track_progress.as_millis() as u32,
|
||||
);
|
||||
spotify.update_track();
|
||||
match playback_state {
|
||||
PlaybackState::Stopped => {
|
||||
spotify.stop();
|
||||
}
|
||||
PlaybackState::Paused | PlaybackState::Playing | PlaybackState::Default => {
|
||||
spotify.pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
let ipc = if let Ok(runtime_directory) = utils::create_runtime_directory() {
|
||||
Some(
|
||||
@@ -208,8 +226,6 @@ impl Application {
|
||||
queue,
|
||||
spotify,
|
||||
event_manager,
|
||||
#[cfg(feature = "mpris")]
|
||||
mpris_manager,
|
||||
#[cfg(unix)]
|
||||
ipc,
|
||||
cursive,
|
||||
@@ -240,9 +256,6 @@ impl Application {
|
||||
trace!("event received: {:?}", state);
|
||||
self.spotify.update_status(state.clone());
|
||||
|
||||
#[cfg(feature = "mpris")]
|
||||
self.mpris_manager.send(MprisCommand::NotifyPlaybackUpdate);
|
||||
|
||||
#[cfg(unix)]
|
||||
if let Some(ref ipc) = self.ipc {
|
||||
ipc.publish(&state, self.queue.get_current());
|
||||
|
||||
Reference in New Issue
Block a user