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:
Jonte Bergfeld
2024-09-19 23:31:29 +02:00
committed by GitHub
parent 8eb7d1d42a
commit 3893a0ef6d
4 changed files with 59 additions and 45 deletions

View File

@@ -8,7 +8,7 @@ use notify_rust::Notification;
use rand::prelude::*;
use strum_macros::Display;
use crate::config::{Config, PlaybackState};
use crate::config::Config;
use crate::library::Library;
use crate::model::playable::Playable;
use crate::spotify::PlayerEvent;
@@ -50,34 +50,15 @@ pub struct Queue {
impl Queue {
pub fn new(spotify: Spotify, cfg: Arc<Config>, library: Arc<Library>) -> Self {
let queue_state = cfg.state().queuestate.clone();
let playback_state = cfg.state().playback_state.clone();
let queue = Self {
Self {
queue: Arc::new(RwLock::new(queue_state.queue)),
spotify: spotify.clone(),
current_track: RwLock::new(queue_state.current_track),
random_order: RwLock::new(queue_state.random_order),
cfg,
library,
};
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();
}
}
}
queue
}
/// The index of the next item in `self.queue` that should be played. None