From 417b18481beb780d5d52dbc365790088744eb8b9 Mon Sep 17 00:00:00 2001 From: Mieszko Date: Mon, 9 May 2022 23:28:13 +0200 Subject: [PATCH] check config for changes on tick --- requirements-dev.txt | 3 ++- src/plugin.py | 14 +++++++++----- tests/common/test_subscription_games.py | 1 - tests/common/test_tick.py | 10 ++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 tests/common/test_tick.py diff --git a/requirements-dev.txt b/requirements-dev.txt index 4c91fb6..a3c010f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -10,4 +10,5 @@ pytest-flakes==4.0.0 pytest-mock==1.10.4 freezegun==1.2.1 PyGithub==1.53 -fog.buildtools~=1.0 \ No newline at end of file +fog.buildtools~=1.0 +types-toml==0.10.7 \ No newline at end of file diff --git a/src/plugin.py b/src/plugin.py index 105f333..9cad4ef 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -82,6 +82,7 @@ def __init__(self, reader, writer, token): self._owned_check: asyncio.Task = asyncio.create_task(asyncio.sleep(8)) self._statuses_check: asyncio.Task = asyncio.create_task(asyncio.sleep(4)) self._installed_check: asyncio.Task = asyncio.create_task(asyncio.sleep(4)) + self._humbleapp_config_check: asyncio.Task = asyncio.create_task(asyncio.sleep(0)) self._rescan_needed = True self._under_installation = set() @@ -241,10 +242,6 @@ async def get_subscriptions(self): return choice_perks + choice_months - async def prepare_subscription_games_context(self, subscription_names: t.List[str]) -> None: - if any(name.value in subscription_names for name in HumbleAppGameCategory): - self._humbleapp_client.refresh_game_list() - async def get_subscription_games(self, subscription_name: str, context: None) -> t.AsyncGenerator[t.List[SubscriptionGame], None]: if subscription_name in [n.value for n in HumbleAppGameCategory]: yield self._humbleapp_client.get_subscription_games(HumbleAppGameCategory(subscription_name)) @@ -350,7 +347,6 @@ async def get_game_library_settings(self, game_id: str, context: t.Any) -> GameL gls.tags = [] # remove redundant tags since Galaxy support for subscripitons return gls - # @double_click_effect(timeout=0.4, effect='_launch_directly') async def launch_game(self, game_id): if game_id in self._humbleapp_client: self._humbleapp_client.launch(game_id) @@ -458,6 +454,10 @@ async def _check_statuses(self): self.update_local_game_status(LocalGame(game.id, state)) self._cached_game_states[game.id] = state await asyncio.sleep(0.5) + + async def _check_humbleapp(self): + self._humbleapp_client.refresh_game_list() + await asyncio.sleep(1) def tick(self): self._settings.reload_config_if_changed() @@ -473,11 +473,15 @@ def tick(self): if self._statuses_check.done(): self._statuses_check = asyncio.create_task(self._check_statuses()) + + if self._humbleapp_config_check.done(): + self._humbleapp_config_check = asyncio.create_task(self._check_humbleapp()) async def shutdown(self): self._owned_check.cancel() self._statuses_check.cancel() self._installed_check.cancel() + self._humbleapp_config_check.cancel() await self._api.close_session() diff --git a/tests/common/test_subscription_games.py b/tests/common/test_subscription_games.py index 7c6c151..d6cab0a 100644 --- a/tests/common/test_subscription_games.py +++ b/tests/common/test_subscription_games.py @@ -158,4 +158,3 @@ def fake_get_sub_games(game_cat: HumbleAppGameCategory) : async for games_batch in plugin.get_subscription_games(subscription_name, ctx): assert games_batch == expected - humbleapp_client_mock.refresh_game_list.assert_called_once() \ No newline at end of file diff --git a/tests/common/test_tick.py b/tests/common/test_tick.py new file mode 100644 index 0000000..8e83db3 --- /dev/null +++ b/tests/common/test_tick.py @@ -0,0 +1,10 @@ +import pytest + +from galaxy.unittest.mock import skip_loop + + +@pytest.mark.asyncio +async def test_humbleapp_refresh_game_list(plugin, humbleapp_client_mock): + plugin.tick() + await skip_loop() + humbleapp_client_mock.refresh_game_list.assert_called_once()