Skip to content

Commit

Permalink
check config for changes on tick
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGoogle committed May 9, 2022
1 parent e401ef8 commit 417b184
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
fog.buildtools~=1.0
types-toml==0.10.7
14 changes: 9 additions & 5 deletions src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()


Expand Down
1 change: 0 additions & 1 deletion tests/common/test_subscription_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 10 additions & 0 deletions tests/common/test_tick.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 417b184

Please sign in to comment.