Fixed phantom player events

This commit is contained in:
Sumner Evans
2020-06-18 22:53:35 -06:00
parent fc8b90c8a5
commit a17012739c
2 changed files with 9 additions and 6 deletions

View File

@@ -272,6 +272,7 @@ class SublimeMusicApp(Gtk.Application):
self.player_manager.set_current_device_id(
self.app_config.state.current_device
)
self.player_manager.set_volume(self.app_config.state.volume)
self.update_window()
def player_device_change_callback(event: PlayerDeviceEvent):
@@ -885,8 +886,7 @@ class SublimeMusicApp(Gtk.Application):
return
self.app_config.state.current_device = device_id
was_playing = self.app_config.state.playing
if was_playing:
if was_playing := self.app_config.state.playing:
self.on_play_pause()
self.player_manager.set_current_device_id(self.app_config.state.current_device)
@@ -1313,9 +1313,7 @@ class SublimeMusicApp(Gtk.Application):
if not can_play:
# There are no songs that can be played. Show a notification that you
# have to go online to play anything and then don't go further.
was_playing = False
if self.app_config.state.playing:
was_playing = True
if was_playing := self.app_config.state.playing:
self.on_play_pause()
def go_online_clicked():

View File

@@ -38,12 +38,17 @@ class PlayerManager:
):
self.on_timepos_change = on_timepos_change
self.on_track_end = on_track_end
self.on_player_event = on_player_event
self.config = config
self.players: Dict[Type, Any] = {}
self.device_id_type_map: Dict[str, Type] = {}
self._current_device_id: Optional[str] = None
def player_event_wrapper(pe: PlayerEvent):
if pe.device_id == self._current_device_id:
on_player_event(pe)
self.on_player_event = player_event_wrapper
def callback_wrapper(pde: PlayerDeviceEvent):
self.device_id_type_map[pde.id] = pde.player_type
player_device_change_callback(pde)