Fixed some bugs with first time launch
This commit is contained in:
@@ -53,7 +53,7 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
|
|
||||||
self.connect("shutdown", self.on_app_shutdown)
|
self.connect("shutdown", self.on_app_shutdown)
|
||||||
|
|
||||||
player: Player
|
player: Optional[Player] = None
|
||||||
exiting: bool = False
|
exiting: bool = False
|
||||||
|
|
||||||
def do_startup(self):
|
def do_startup(self):
|
||||||
@@ -128,19 +128,6 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER
|
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.show_all()
|
||||||
self.window.present()
|
self.window.present()
|
||||||
|
|
||||||
@@ -156,6 +143,18 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
self.window.close()
|
self.window.close()
|
||||||
return
|
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
|
# Configure the players
|
||||||
self.last_play_queue_update = timedelta(0)
|
self.last_play_queue_update = timedelta(0)
|
||||||
self.loading_state = False
|
self.loading_state = False
|
||||||
|
@@ -161,12 +161,14 @@ class AppConfiguration:
|
|||||||
return
|
return
|
||||||
|
|
||||||
self._current_server_hash = self.server.strhash()
|
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:
|
try:
|
||||||
with open(self.state_file_location, "rb") as f:
|
with open(state_file_location, "rb") as f:
|
||||||
self._state = pickle.load(f)
|
self._state = pickle.load(f)
|
||||||
except Exception:
|
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.
|
# Just ignore any errors, it is only UI state.
|
||||||
self._state = UIState()
|
self._state = UIState()
|
||||||
|
|
||||||
@@ -176,8 +178,10 @@ class AppConfiguration:
|
|||||||
AdapterManager.reset(self)
|
AdapterManager.reset(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_file_location(self) -> Path:
|
def state_file_location(self) -> Optional[Path]:
|
||||||
assert self.server is not None
|
if self.server is None:
|
||||||
|
return None
|
||||||
|
|
||||||
server_hash = self.server.strhash()
|
server_hash = self.server.strhash()
|
||||||
|
|
||||||
state_file_location = Path(os.environ.get("XDG_DATA_HOME") or "~/.local/share")
|
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)))
|
f.write(yaml.dump(asdict(self)))
|
||||||
|
|
||||||
# Save the state for the current server.
|
# Save the state for the current server.
|
||||||
self.state_file_location.parent.mkdir(parents=True, exist_ok=True)
|
if state_file_location := self.state_file_location:
|
||||||
with open(self.state_file_location, "wb+") as f:
|
state_file_location.parent.mkdir(parents=True, exist_ok=True)
|
||||||
pickle.dump(self.state, f)
|
with open(state_file_location, "wb+") as f:
|
||||||
|
pickle.dump(self.state, f)
|
||||||
|
@@ -165,6 +165,9 @@ class DBusManager:
|
|||||||
|
|
||||||
def property_dict(self) -> Dict[str, Any]:
|
def property_dict(self) -> Dict[str, Any]:
|
||||||
config, player = self.get_config_and_player()
|
config, player = self.get_config_and_player()
|
||||||
|
if config is None or player is None:
|
||||||
|
return {}
|
||||||
|
|
||||||
state = config.state
|
state = config.state
|
||||||
has_current_song = state.current_song is not None
|
has_current_song = state.current_song is not None
|
||||||
has_next_song = False
|
has_next_song = False
|
||||||
|
@@ -337,10 +337,10 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||||||
current_downloads_header.pack_end(cancel_all_button, False, False, 0)
|
current_downloads_header.pack_end(cancel_all_button, False, False, 0)
|
||||||
vbox.add(current_downloads_header)
|
vbox.add(current_downloads_header)
|
||||||
|
|
||||||
current_downloads_box = Gtk.Box(
|
self.current_downloads_box = Gtk.Box(
|
||||||
orientation=Gtk.Orientation.VERTICAL, name="current-downloads-list"
|
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")
|
clear_cache = self._create_model_button("Clear Cache", menu_name="clear-cache")
|
||||||
vbox.add(clear_cache)
|
vbox.add(clear_cache)
|
||||||
|
Reference in New Issue
Block a user