Restart queue if pressing play when stopped (#399)
* Restart queue if pressing play when stopped * Remove FinishedTrack from match * Formatting
This commit is contained in:
@@ -400,9 +400,9 @@ fn run_dbus_server(
|
||||
});
|
||||
|
||||
let method_playpause = {
|
||||
let spotify = spotify.clone();
|
||||
let queue = queue.clone();
|
||||
f.method("PlayPause", (), move |m| {
|
||||
spotify.toggleplayback();
|
||||
queue.toggleplayback();
|
||||
Ok(vec![m.msg.method_return()])
|
||||
})
|
||||
};
|
||||
|
||||
13
src/queue.rs
13
src/queue.rs
@@ -7,9 +7,9 @@ use notify_rust::Notification;
|
||||
use rand::prelude::*;
|
||||
use strum_macros::Display;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::playable::Playable;
|
||||
use crate::spotify::Spotify;
|
||||
use crate::{config::Config, spotify::PlayerEvent};
|
||||
|
||||
#[derive(Display, Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub enum RepeatSetting {
|
||||
@@ -264,7 +264,16 @@ impl Queue {
|
||||
}
|
||||
|
||||
pub fn toggleplayback(&self) {
|
||||
self.spotify.toggleplayback();
|
||||
match self.spotify.get_current_status() {
|
||||
PlayerEvent::Playing | PlayerEvent::Paused => {
|
||||
self.spotify.toggleplayback();
|
||||
}
|
||||
PlayerEvent::Stopped => match self.next_index() {
|
||||
Some(_) => self.next(false),
|
||||
None => self.play(0, false, false),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(&self) {
|
||||
|
||||
@@ -890,11 +890,7 @@ impl Spotify {
|
||||
}
|
||||
|
||||
pub fn toggleplayback(&self) {
|
||||
let status = self
|
||||
.status
|
||||
.read()
|
||||
.expect("could not acquire read lock on player state");
|
||||
match *status {
|
||||
match self.get_current_status() {
|
||||
PlayerEvent::Playing => self.pause(),
|
||||
PlayerEvent::Paused => self.play(),
|
||||
_ => (),
|
||||
|
||||
Reference in New Issue
Block a user