Made the DBus functions aware of whether or not they are recieving futures

This commit is contained in:
Sumner Evans
2019-12-28 12:54:04 -07:00
parent f84f97732d
commit 2804bba34d
2 changed files with 40 additions and 20 deletions

View File

@@ -317,7 +317,14 @@ class SublimeMusicApp(Gtk.Application):
) )
def get_playlists(index, max_count, order, reverse_order): def get_playlists(index, max_count, order, reverse_order):
playlists = CacheManager.get_playlists().result() playlists_result = CacheManager.get_playlists()
if playlists_result.is_future:
# We don't want to wait for the response in this case, so just
# return an empty array.
return GLib.Variant('(a(oss))', ([], ))
playlists = playlists_result.result()
sorters = { sorters = {
'Alphabetical': lambda p: p.name, 'Alphabetical': lambda p: p.name,
'Created': lambda p: p.created, 'Created': lambda p: p.created,

View File

@@ -173,22 +173,33 @@ class DBusManager:
if state.active_playlist_id is None: if state.active_playlist_id is None:
active_playlist = (False, GLib.Variant('(oss)', ('/', '', ''))) active_playlist = (False, GLib.Variant('(oss)', ('/', '', '')))
else: else:
playlist = CacheManager.get_playlist( playlist_result = CacheManager.get_playlist(
state.active_playlist_id).result() state.active_playlist_id)
active_playlist = (
True, if playlist_result.is_future:
GLib.Variant( # If we have to wait for the playlist result, just return
'(oss)', # no playlist.
( active_playlist = (False, GLib.Variant('(oss)', ('/', '', '')))
'/playlist/' + playlist.id, else:
playlist.name, playlist = playlist_result.result()
CacheManager.get_cover_art_filename(
playlist.coverArt, active_playlist = (
allow_download=False, True,
).result() or '', GLib.Variant(
'(oss)',
(
'/playlist/' + playlist.id,
playlist.name,
CacheManager.get_cover_art_url(playlist.coverArt),
),
), ),
), )
)
get_playlists_result = CacheManager.get_playlists()
if get_playlists_result.is_future:
playlist_count = 0
else:
playlist_count = len(get_playlists_result.result())
return { return {
'org.mpris.MediaPlayer2': { 'org.mpris.MediaPlayer2': {
@@ -251,16 +262,18 @@ class DBusManager:
'org.mpris.MediaPlayer2.Playlists': { 'org.mpris.MediaPlayer2.Playlists': {
# TODO this may do a network request. This really is a case for # TODO this may do a network request. This really is a case for
# doing the whole thing with caching some data beforehand. # doing the whole thing with caching some data beforehand.
'PlaylistCount': ( 'PlaylistCount': playlist_count,
0 if not CacheManager.ready() else len(
CacheManager.get_playlists().result())),
'Orderings': ['Alphabetical', 'Created', 'Modified'], 'Orderings': ['Alphabetical', 'Created', 'Modified'],
'ActivePlaylist': ('(b(oss))', active_playlist), 'ActivePlaylist': ('(b(oss))', active_playlist),
}, },
} }
def get_mpris_metadata(self, idx: int, play_queue): def get_mpris_metadata(self, idx: int, play_queue):
song = CacheManager.get_song_details(play_queue[idx]).result() song_result = CacheManager.get_song_details(play_queue[idx])
if song_result.is_future:
return {}
song = song_result.result()
trackid = self.get_dbus_playlist(play_queue)[idx] trackid = self.get_dbus_playlist(play_queue)[idx]
duration = ( duration = (
'x', 'x',