diff --git a/lutris/gui/config/accounts_box.py b/lutris/gui/config/accounts_box.py index 37a78836d..f220ef108 100644 --- a/lutris/gui/config/accounts_box.py +++ b/lutris/gui/config/accounts_box.py @@ -8,7 +8,12 @@ from lutris.gui.config.base_config_box import BaseConfigBox from lutris.gui.config.updates_box import UpdateButtonBox from lutris.gui.dialogs import ClientLoginDialog, QuestionDialog from lutris.util.jobs import AsyncCall -from lutris.util.library_sync import LOCAL_LIBRARY_SYNCED, LOCAL_LIBRARY_SYNCING, LibrarySyncer +from lutris.util.library_sync import ( + LOCAL_LIBRARY_SYNCED, + LOCAL_LIBRARY_SYNCING, + LibrarySyncer, + is_local_library_syncing, +) from lutris.util.steam.config import STEAM_ACCOUNT_SETTING, get_steam_users from lutris.util.strings import time_ago @@ -55,8 +60,7 @@ class AccountsBox(BaseConfigBox): def on_realize(self, _widget): self.library_syncing_source_id = LOCAL_LIBRARY_SYNCING.register(self.on_local_library_syncing) self.library_synced_source_id = LOCAL_LIBRARY_SYNCED.register(self.on_local_library_synced) - library_syncer = LibrarySyncer() - if library_syncer.is_syncing: + if is_local_library_syncing(): self.on_local_library_syncing() def on_unrealize(self, _widget): diff --git a/lutris/util/library_sync.py b/lutris/util/library_sync.py index 65d07314e..5bc435842 100644 --- a/lutris/util/library_sync.py +++ b/lutris/util/library_sync.py @@ -14,11 +14,18 @@ LIBRARY_URL = settings.SITE_URL + "/api/users/library" LOCAL_LIBRARY_SYNCING = NotificationSource() LOCAL_LIBRARY_SYNCED = NotificationSource() LOCAL_LIBRARY_UPDATED = NotificationSource() +_IS_LOCAL_LIBRARY_SYNCING = False + + +def is_local_library_syncing(): + """True if the library is syncing now; attempting to sync again will do nothing if so.""" + # This provides access to the mutable global _IS_LOCAL_LIBRARY_SYNCING in a safer + # way; if you just import the global directly you get a copy of its current state at import + # time which is not very useful. + return _IS_LOCAL_LIBRARY_SYNCING class LibrarySyncer: - is_syncing = False - def get_local_library(self, since=None): game_library = [] pga_games = get_games() @@ -47,9 +54,9 @@ class LibrarySyncer: return game_library def sync_local_library(self, force: bool = False) -> None: - global IS_LOCAL_LIBRARY_SYNCING + global _IS_LOCAL_LIBRARY_SYNCING - if self.is_syncing: + if _IS_LOCAL_LIBRARY_SYNCING: return if not force and settings.read_setting("last_library_sync_at"): @@ -69,7 +76,8 @@ class LibrarySyncer: LOCAL_LIBRARY_SYNCING.fire() any_local_changes = False try: - self.is_syncing = True + _IS_LOCAL_LIBRARY_SYNCING = True + time.sleep(15) request = http.Request( url, headers={ @@ -151,7 +159,7 @@ class LibrarySyncer: ) settings.write_setting("last_library_sync_at", int(time.time())) finally: - self.is_syncing = False + _IS_LOCAL_LIBRARY_SYNCING = False LOCAL_LIBRARY_SYNCED.fire() if any_local_changes: LOCAL_LIBRARY_UPDATED.fire()