Move the logged in event to auth state

This commit is contained in:
DevilXD committed 2022-09-15 07:44:20 +02:00
1 parent fb3c6bf0ce
commit 8da6ae8c8b
1 file changed
+6 -6
+6 -6
View File
@@ -92,6 +92,7 @@ class _AuthState:
self.access_token: str self.access_token: str
self.client_version: str self.client_version: str
self.integrity_token: _IntegrityToken self.integrity_token: _IntegrityToken
self._logged_in = asyncio.Event()
async def _login(self) -> str: async def _login(self) -> str:
logger.debug("Login flow started") logger.debug("Login flow started")
@@ -249,7 +250,7 @@ class _AuthState:
headers=self.gql_headers(integrity=False) headers=self.gql_headers(integrity=False)
) as response: ) as response:
self.integrity_token = _IntegrityToken(await response.json()) self.integrity_token = _IntegrityToken(await response.json())
self._twitch._is_logged_in.set() self._logged_in.set()
class Twitch: class Twitch:
@@ -261,12 +262,11 @@ class Twitch:
self.games: dict[Game, int] = {} self.games: dict[Game, int] = {}
self.inventory: list[DropsCampaign] = [] self.inventory: list[DropsCampaign] = []
self._drops: dict[str, TimedDrop] = {} self._drops: dict[str, TimedDrop] = {}
# GUI # Session and auth
self.gui = GUIManager(self)
# Cookies, session and auth
self._session: aiohttp.ClientSession | None = None self._session: aiohttp.ClientSession | None = None
self._auth_state: _AuthState = _AuthState(self) self._auth_state: _AuthState = _AuthState(self)
self._is_logged_in = asyncio.Event() # GUI
self.gui = GUIManager(self)
# Storing and watching channels # Storing and watching channels
self.channels: OrderedDict[int, Channel] = OrderedDict() self.channels: OrderedDict[int, Channel] = OrderedDict()
self.watching_channel: AwaitableValue[Channel] = AwaitableValue() self.watching_channel: AwaitableValue[Channel] = AwaitableValue()
@@ -315,7 +315,7 @@ class Twitch:
await asyncio.sleep(start_time + 0.5 - time()) await asyncio.sleep(start_time + 0.5 - time())
def wait_until_login(self) -> abc.Coroutine[Any, Any, Literal[True]]: def wait_until_login(self) -> abc.Coroutine[Any, Any, Literal[True]]:
return self._is_logged_in.wait() return self._auth_state._logged_in.wait()
def change_state(self, state: State) -> None: def change_state(self, state: State) -> None:
if self._state is not State.EXIT: if self._state is not State.EXIT: