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()
def shuffle(self):
if self.app_config.state.shuffle_on:
# Revert to the old play queue.
old_play_queue_copy = self.app_config.state.old_play_queue
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.old_play_queue = self.app_config.state.play_queue
if self.app_config.state.current_song:
if self.app_config.state.shuffle_on:
# Revert to the old play queue.
old_play_queue_copy = self.app_config.state.old_play_queue
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.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.
song_id = self.app_config.state.current_song.id
del mutable_play_queue[self.app_config.state.current_song_index]
random.shuffle(mutable_play_queue)
self.app_config.state.play_queue = (song_id,) + tuple(mutable_play_queue)
self.app_config.state.current_song_index = 0
# Remove the current song, then shuffle and put the song back.
song_id = self.app_config.state.current_song.id
del mutable_play_queue[self.app_config.state.current_song_index]
random.shuffle(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.shuffle_on = not self.app_config.state.shuffle_on
self.update_window()

View File

@@ -94,6 +94,8 @@ class Desktop(Gtk.Box):
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
if app_config.state.is_muted:
icon_name = "muted"

View File

@@ -119,6 +119,14 @@ class MobileHandle(Gtk.ActionBar):
return box
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:
self.song_title.set_markup(bleach.clean(app_config.state.current_song.title))
# TODO (#71): use walrus once MYPY gets its act together