Resolves #54 fixes the explosions when no server is configured

This commit is contained in:
Sumner Evans
2019-10-27 20:21:21 -06:00
parent c83fd171b0
commit d3856a5252
4 changed files with 28 additions and 4 deletions

View File

@@ -153,8 +153,9 @@ class SublimeMusicApp(Gtk.Application):
if (self.state.config.current_server is None
or self.state.config.current_server < 0):
self.show_configure_servers_dialog()
if self.state.config.current_server is None:
if self.current_server is None:
self.window.close()
return
self.update_window()
@@ -230,11 +231,14 @@ class SublimeMusicApp(Gtk.Application):
# ########## DBUS MANAGMENT ########## #
def do_dbus_register(self, connection, path):
def get_state_and_player():
return (self.state, getattr(self, 'player', None))
self.dbus_manager = DBusManager(
connection,
self.on_dbus_method_call,
self.on_dbus_set_property,
lambda: (self.state, self.player),
get_state_and_player,
)
return True
@@ -650,6 +654,10 @@ class SublimeMusicApp(Gtk.Application):
def on_app_shutdown(self, app):
Notify.uninit()
if self.current_server is None:
return
self.player.pause()
self.chromecast_player.shutdown()
self.mpv_player.shutdown()
@@ -662,6 +670,8 @@ class SublimeMusicApp(Gtk.Application):
# ########## PROPERTIES ########## #
@property
def current_server(self):
if len(self.state.config.servers) < 1:
return None
return self.state.config.servers[self.state.config.current_server]
# ########## HELPER METHODS ########## #

View File

@@ -72,6 +72,10 @@ class CacheManager(metaclass=Singleton):
executor: ThreadPoolExecutor = ThreadPoolExecutor(max_workers=50)
should_exit: bool = False
@staticmethod
def ready():
return CacheManager._instance is not None
@staticmethod
def shutdown():
# TODO fix this shutdown

View File

@@ -208,7 +208,7 @@ class DBusManager:
(False, True): 'Stopped',
(True, False): 'Paused',
(True, True): 'Playing',
}[player.song_loaded, state.playing],
}[player is not None and player.song_loaded, state.playing],
'LoopStatus':
state.repeat_type.as_mpris_loop_status(),
'Rate':
@@ -250,7 +250,9 @@ class DBusManager:
'org.mpris.MediaPlayer2.Playlists': {
# TODO this may do a network request. This really is a case for
# doing the whole thing with caching some data beforehand.
'PlaylistCount': len(CacheManager.get_playlists().result()),
'PlaylistCount': (
0 if not CacheManager.ready() else len(
CacheManager.get_playlists().result())),
'Orderings': ['Alphabetical', 'Created', 'Modified'],
'ActivePlaylist': ('(b(oss))', active_playlist),
},

View File

@@ -115,6 +115,9 @@ class AlbumsPanel(Gtk.Box):
state: ApplicationState,
force: bool = False,
):
if not CacheManager.ready():
return
def get_genres_done(f):
new_store = [
(genre.value, genre.value) for genre in (f.result() or [])
@@ -404,6 +407,11 @@ class AlbumsGrid(Gtk.ScrolledWindow):
children[0].update(force=force)
def update_grid(self, force=False, selected_id=None):
if not CacheManager.ready():
self.spinner.hide()
self.continuation_spinner.hide()
return
def reflow_grid(force_reload, selected_index):
selection_changed = (selected_index != self.current_selection)
self.current_selection = selected_index