This commit is contained in:
Benjamin Schaaf
2022-01-09 17:51:19 +11:00
parent 6c2dbf192e
commit 6a68cd1c99
3 changed files with 27 additions and 16 deletions

View File

@@ -733,24 +733,25 @@ class SublimeMusicApp(Gtk.Application):
@dbus_propagate() @dbus_propagate()
def shuffle(self): def shuffle(self):
if self.app_config.state.shuffle_on: if self.app_config.state.current_song:
# Revert to the old play queue. if self.app_config.state.shuffle_on:
old_play_queue_copy = self.app_config.state.old_play_queue # Revert to the old play queue.
self.app_config.state.current_song_index = old_play_queue_copy.index( old_play_queue_copy = self.app_config.state.old_play_queue
self.app_config.state.current_song.id self.app_config.state.current_song_index = old_play_queue_copy.index(
) self.app_config.state.current_song.id
self.app_config.state.play_queue = old_play_queue_copy )
else: self.app_config.state.play_queue = old_play_queue_copy
self.app_config.state.old_play_queue = self.app_config.state.play_queue else:
self.app_config.state.old_play_queue = self.app_config.state.play_queue
mutable_play_queue = list(self.app_config.state.play_queue) mutable_play_queue = list(self.app_config.state.play_queue)
# Remove the current song, then shuffle and put the song back. # Remove the current song, then shuffle and put the song back.
song_id = self.app_config.state.current_song.id song_id = self.app_config.state.current_song.id
del mutable_play_queue[self.app_config.state.current_song_index] del mutable_play_queue[self.app_config.state.current_song_index]
random.shuffle(mutable_play_queue) random.shuffle(mutable_play_queue)
self.app_config.state.play_queue = (song_id,) + tuple(mutable_play_queue) self.app_config.state.play_queue = (song_id,) + tuple(mutable_play_queue)
self.app_config.state.current_song_index = 0 self.app_config.state.current_song_index = 0
self.app_config.state.shuffle_on = not self.app_config.state.shuffle_on self.app_config.state.shuffle_on = not self.app_config.state.shuffle_on
self.update_window() self.update_window()

View File

@@ -94,6 +94,8 @@ class Desktop(Gtk.Box):
self.device_button.set_icon(f"chromecast{icon}-symbolic") self.device_button.set_icon(f"chromecast{icon}-symbolic")
self.play_queue_button.set_sensitive(len(app_config.state.play_queue) > 0)
# Volume button and slider # Volume button and slider
if app_config.state.is_muted: if app_config.state.is_muted:
icon_name = "muted" icon_name = "muted"

View File

@@ -119,6 +119,14 @@ class MobileHandle(Gtk.ActionBar):
return box return box
def update(self, app_config: AppConfiguration, force: bool = False): def update(self, app_config: AppConfiguration, force: bool = False):
empty_queue = len(app_config.state.play_queue) == 0
self.play_queue_button.set_sensitive(not empty_queue)
self.menu_button.set_sensitive(not empty_queue)
if empty_queue:
self.state.play_queue_open = False
if app_config.state.current_song is not None: if app_config.state.current_song is not None:
self.song_title.set_markup(bleach.clean(app_config.state.current_song.title)) self.song_title.set_markup(bleach.clean(app_config.state.current_song.title))
# TODO (#71): use walrus once MYPY gets its act together # TODO (#71): use walrus once MYPY gets its act together