Implement refresh
This commit is contained in:
@@ -100,6 +100,7 @@ class SublimeMusicApp(Gtk.Application):
|
||||
add_action("go-to-playlist", self.on_go_to_playlist, parameter_type="s")
|
||||
|
||||
add_action("go-online", self.on_go_online)
|
||||
add_action("refresh-devices", self.on_refresh_devices)
|
||||
add_action(
|
||||
"refresh-window", lambda *a: self.on_refresh_window(None, {}, True),
|
||||
)
|
||||
@@ -294,6 +295,8 @@ class SublimeMusicApp(Gtk.Application):
|
||||
)
|
||||
|
||||
elif event.delta == PlayerDeviceEvent.Delta.REMOVE:
|
||||
if state_device == event.id:
|
||||
self.player_manager.pause()
|
||||
self.app_config.state.available_players[event.player_type].remove(
|
||||
(event.id, event.name)
|
||||
)
|
||||
@@ -574,6 +577,7 @@ class SublimeMusicApp(Gtk.Application):
|
||||
player_name, option_name, value = player_setting
|
||||
self.app_config.player_config[player_name][option_name] = value
|
||||
del state_updates["__player_setting__"]
|
||||
# TODO update the actual player settings
|
||||
|
||||
for k, v in state_updates.items():
|
||||
setattr(self.app_config.state, k, v)
|
||||
@@ -771,6 +775,9 @@ class SublimeMusicApp(Gtk.Application):
|
||||
def on_go_online(self, *args):
|
||||
self.on_refresh_window(None, {"__settings__": {"offline_mode": False}})
|
||||
|
||||
def on_refresh_devices(self, *args):
|
||||
self.player_manager.refresh_players()
|
||||
|
||||
def reset_state(self):
|
||||
if self.app_config.state.playing:
|
||||
self.on_play_pause()
|
||||
|
@@ -47,10 +47,10 @@ class PlayerEvent:
|
||||
DISCONNECT = 5
|
||||
|
||||
type: EventType
|
||||
device_id: str
|
||||
playing: Optional[bool] = None
|
||||
volume: Optional[float] = None
|
||||
stream_cache_duration: Optional[float] = None
|
||||
device_id: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@@ -77,7 +77,7 @@ class ChromecastPlayer(Player):
|
||||
self._chromecasts: Dict[UUID, pychromecast.Chromecast] = {}
|
||||
self._current_chromecast: Optional[pychromecast.Chromecast] = None
|
||||
|
||||
self.get_chromecasts_job = None
|
||||
self.stop_get_chromecasts = None
|
||||
self.refresh_players()
|
||||
|
||||
def chromecast_discovered_callback(self, chromecast: Any):
|
||||
@@ -115,22 +115,22 @@ class ChromecastPlayer(Player):
|
||||
if not chromecast_imported:
|
||||
return
|
||||
|
||||
if self.get_chromecasts_job is not None:
|
||||
pychromecast.discovery.stop_discovery(self.get_chromecasts_job)
|
||||
if self.stop_get_chromecasts is not None:
|
||||
self.stop_get_chromecasts()
|
||||
|
||||
for id_, chromecast in self._chromecasts.items():
|
||||
self.player_device_change_callback(
|
||||
PlayerDeviceEvent(
|
||||
PlayerDeviceEvent.Delta.REMOVE,
|
||||
type(self),
|
||||
id_,
|
||||
str(id_),
|
||||
chromecast.device.friendly_name,
|
||||
)
|
||||
)
|
||||
|
||||
self._chromecasts = {}
|
||||
|
||||
self.get_chromecasts_job = pychromecast.get_chromecasts(
|
||||
self.stop_get_chromecasts = pychromecast.get_chromecasts(
|
||||
blocking=False, callback=self.chromecast_discovered_callback
|
||||
)
|
||||
|
||||
@@ -141,9 +141,11 @@ class ChromecastPlayer(Player):
|
||||
self._current_chromecast.wait()
|
||||
|
||||
def new_cast_status(self, status: Any):
|
||||
assert self._current_chromecast
|
||||
self.on_player_event(
|
||||
PlayerEvent(
|
||||
PlayerEvent.EventType.VOLUME_CHANGE,
|
||||
str(self._current_chromecast.device.uuid),
|
||||
volume=(status.volume_level * 100 if not status.volume_muted else 0),
|
||||
)
|
||||
)
|
||||
@@ -152,9 +154,18 @@ class ChromecastPlayer(Player):
|
||||
# Home app.
|
||||
if status.session_id is None:
|
||||
self.on_player_event(
|
||||
PlayerEvent(PlayerEvent.EventType.PLAY_STATE_CHANGE, playing=False)
|
||||
PlayerEvent(
|
||||
PlayerEvent.EventType.PLAY_STATE_CHANGE,
|
||||
str(self._current_chromecast.device.uuid),
|
||||
playing=False,
|
||||
)
|
||||
)
|
||||
self.on_player_event(
|
||||
PlayerEvent(
|
||||
PlayerEvent.EventType.DISCONNECT,
|
||||
str(self._current_chromecast.device.uuid),
|
||||
)
|
||||
)
|
||||
self.on_player_event(PlayerEvent(PlayerEvent.EventType.DISCONNECT))
|
||||
self.song_loaded = False
|
||||
|
||||
time_increment_order_token = 0
|
||||
@@ -173,9 +184,11 @@ class ChromecastPlayer(Player):
|
||||
|
||||
self._timepos = status.current_time
|
||||
|
||||
assert self._current_chromecast
|
||||
self.on_player_event(
|
||||
PlayerEvent(
|
||||
PlayerEvent.EventType.PLAY_STATE_CHANGE,
|
||||
str(self._current_chromecast.device.uuid),
|
||||
playing=(status.player_state in ("PLAYING", "BUFFERING")),
|
||||
)
|
||||
)
|
||||
@@ -307,6 +320,7 @@ class ChromecastPlayer(Player):
|
||||
self.on_player_event(
|
||||
PlayerEvent(
|
||||
PlayerEvent.EventType.STREAM_CACHE_PROGRESS_CHANGE,
|
||||
str(self._current_chromecast.device.uuid),
|
||||
stream_cache_duration=0,
|
||||
)
|
||||
)
|
||||
|
@@ -57,6 +57,7 @@ class MPVPlayer(Player):
|
||||
on_player_event(
|
||||
PlayerEvent(
|
||||
PlayerEvent.EventType.STREAM_CACHE_PROGRESS_CHANGE,
|
||||
"this device",
|
||||
stream_cache_duration=value,
|
||||
)
|
||||
)
|
||||
|
@@ -457,11 +457,6 @@ class PlayerControls(Gtk.ActionBar):
|
||||
self.device_popover.popup()
|
||||
self.device_popover.show_all()
|
||||
|
||||
def on_device_refresh_click(self, _: Any):
|
||||
# TODO: make this an action that does stuff with the player manager to delete
|
||||
# all of the things and then restart retrieving the players.
|
||||
pass
|
||||
|
||||
def on_play_queue_button_press(self, tree: Any, event: Gdk.EventButton) -> bool:
|
||||
if event.button == 3: # Right click
|
||||
clicked_path = tree.get_path_at_pos(event.x, event.y)
|
||||
@@ -677,7 +672,7 @@ class PlayerControls(Gtk.ActionBar):
|
||||
device_popover_header.add(self.popover_label)
|
||||
|
||||
refresh_devices = IconButton("view-refresh-symbolic", "Refresh device list")
|
||||
refresh_devices.connect("clicked", self.on_device_refresh_click)
|
||||
refresh_devices.set_action_name("app.refresh-devices")
|
||||
device_popover_header.pack_end(refresh_devices, False, False, 0)
|
||||
|
||||
device_popover_box.add(device_popover_header)
|
||||
|
Reference in New Issue
Block a user