Move runtime cancellables to a class attribute

This commit is contained in:
Mathieu Comandon 2016-10-24 12:48:41 -07:00
parent 08f21625ae
commit aed30cad03
2 changed files with 5 additions and 6 deletions

View file

@ -11,7 +11,7 @@ from lutris.game import Game
from lutris.sync import sync_from_remote
from lutris.runtime import RuntimeUpdater
from lutris.util import display, resources
from lutris.util import resources
from lutris.util.log import logger
from lutris.util.jobs import AsyncCall
from lutris.util import http
@ -351,8 +351,8 @@ class LutrisWindow(Gtk.Application):
self.set_status("")
def update_runtime(self):
cancellables = self.runtime_updater.update(self.set_status)
self.threads_stoppers += cancellables
self.runtime_updater.update(self.set_status)
self.threads_stoppers += self.runtime_updater.cancellables
def sync_icons(self):
resources.fetch_icons([game['slug'] for game in self.game_list],

View file

@ -25,6 +25,7 @@ def is_disabled():
class RuntimeUpdater:
current_updates = 0
status_updater = None
cancellables = []
def is_updating(self):
return self.current_updates > 0
@ -52,7 +53,6 @@ class RuntimeUpdater:
def get_runtimes(self):
request = http.Request(RUNTIME_URL)
response = request.get()
cancellables = []
runtimes = response.json or []
for runtime in runtimes:
name = runtime['name']
@ -69,10 +69,9 @@ class RuntimeUpdater:
archive_path = os.path.join(RUNTIME_DIR, os.path.basename(url))
self.current_updates += 1
downloader = Downloader(url, archive_path, overwrite=True)
cancellables.append(downloader.cancel)
self.cancellables.append(downloader.cancel)
downloader.start()
GLib.timeout_add(100, self.check_download_progress, downloader)
return cancellables
def check_download_progress(self, downloader):
"""Call download.check_progress(), return True if download finished."""