Fixed some bugs with first time launch

This commit is contained in:
Sumner Evans
2020-05-30 12:06:10 -06:00
parent 5c08ba7217
commit e456e3be7e
4 changed files with 31 additions and 24 deletions

View File

@@ -53,7 +53,7 @@ class SublimeMusicApp(Gtk.Application):
self.connect("shutdown", self.on_app_shutdown)
player: Player
player: Optional[Player] = None
exiting: bool = False
def do_startup(self):
@@ -128,19 +128,6 @@ class SublimeMusicApp(Gtk.Application):
screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER
)
self.window.stack.connect(
"notify::visible-child", self.on_stack_change,
)
self.window.connect("song-clicked", self.on_song_clicked)
self.window.connect("songs-removed", self.on_songs_removed)
self.window.connect("refresh-window", self.on_refresh_window)
self.window.connect("notification-closed", self.on_notification_closed)
self.window.connect("go-to", self.on_window_go_to)
self.window.connect("key-press-event", self.on_window_key_press)
self.window.player_controls.connect("song-scrub", self.on_song_scrub)
self.window.player_controls.connect("device-update", self.on_device_update)
self.window.player_controls.connect("volume-change", self.on_volume_change)
self.window.show_all()
self.window.present()
@@ -156,6 +143,18 @@ class SublimeMusicApp(Gtk.Application):
self.window.close()
return
# Connect after we know there's a server configured.
self.window.stack.connect("notify::visible-child", self.on_stack_change)
self.window.connect("song-clicked", self.on_song_clicked)
self.window.connect("songs-removed", self.on_songs_removed)
self.window.connect("refresh-window", self.on_refresh_window)
self.window.connect("notification-closed", self.on_notification_closed)
self.window.connect("go-to", self.on_window_go_to)
self.window.connect("key-press-event", self.on_window_key_press)
self.window.player_controls.connect("song-scrub", self.on_song_scrub)
self.window.player_controls.connect("device-update", self.on_device_update)
self.window.player_controls.connect("volume-change", self.on_volume_change)
# Configure the players
self.last_play_queue_update = timedelta(0)
self.loading_state = False

View File

@@ -161,12 +161,14 @@ class AppConfiguration:
return
self._current_server_hash = self.server.strhash()
if self.state_file_location.exists():
if (
state_file_location := self.state_file_location
) and state_file_location.exists():
try:
with open(self.state_file_location, "rb") as f:
with open(state_file_location, "rb") as f:
self._state = pickle.load(f)
except Exception:
logging.warning(f"Couldn't load state from {self.state_file_location}")
logging.warning(f"Couldn't load state from {state_file_location}")
# Just ignore any errors, it is only UI state.
self._state = UIState()
@@ -176,8 +178,10 @@ class AppConfiguration:
AdapterManager.reset(self)
@property
def state_file_location(self) -> Path:
assert self.server is not None
def state_file_location(self) -> Optional[Path]:
if self.server is None:
return None
server_hash = self.server.strhash()
state_file_location = Path(os.environ.get("XDG_DATA_HOME") or "~/.local/share")
@@ -192,6 +196,7 @@ class AppConfiguration:
f.write(yaml.dump(asdict(self)))
# Save the state for the current server.
self.state_file_location.parent.mkdir(parents=True, exist_ok=True)
with open(self.state_file_location, "wb+") as f:
pickle.dump(self.state, f)
if state_file_location := self.state_file_location:
state_file_location.parent.mkdir(parents=True, exist_ok=True)
with open(state_file_location, "wb+") as f:
pickle.dump(self.state, f)

View File

@@ -165,6 +165,9 @@ class DBusManager:
def property_dict(self) -> Dict[str, Any]:
config, player = self.get_config_and_player()
if config is None or player is None:
return {}
state = config.state
has_current_song = state.current_song is not None
has_next_song = False

View File

@@ -337,10 +337,10 @@ class MainWindow(Gtk.ApplicationWindow):
current_downloads_header.pack_end(cancel_all_button, False, False, 0)
vbox.add(current_downloads_header)
current_downloads_box = Gtk.Box(
self.current_downloads_box = Gtk.Box(
orientation=Gtk.Orientation.VERTICAL, name="current-downloads-list"
)
vbox.add(current_downloads_box)
vbox.add(self.current_downloads_box)
clear_cache = self._create_model_button("Clear Cache", menu_name="clear-cache")
vbox.add(clear_cache)