diff --git a/main.py b/main.py index 3516750..05d72b1 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import threading import time from typing import NewType @@ -21,8 +22,11 @@ class Cast(wx.Frame): :param kw: """ super().__init__(*args, **kw) - self.m_chromecasts, self.m_browser = pychromecast.get_chromecasts() self.m_index = 0 + self.m_chromecast_thr = threading.Thread(target=self.get_chromecasts, + args=(), + kwargs={}) + self.m_chromecast_thr.start() self.m_sizer: wx.Sizer = wx.BoxSizer(wx.VERTICAL) self.m_panel: wx.lib.scrolledpanel.ScrolledPanel = scrolled.ScrolledPanel( self, -1, style=wx.VSCROLL) @@ -32,6 +36,9 @@ class Cast(wx.Frame): self.m_channels: list[ChannelProvider] = [SVT.SVT()] self.show_list(None) + def get_chromecasts(self): + self.m_chromecasts, self.m_browser = pychromecast.get_chromecasts() + def show_list(self, _): self.m_sizer.Clear(delete_windows=True) self.m_sizer = wx.BoxSizer(wx.VERTICAL) @@ -133,6 +140,7 @@ class Cast(wx.Frame): if player_state == "PLAYING": has_played = True + break if cast.socket_client.is_connected and has_played and player_state != "PLAYING":