Do not run firmware update check jobs in parallel

CURA-5418

To avoid showing multiple update messages.
This commit is contained in:
Lipu Fei 2018-06-07 13:43:43 +02:00
parent af2d05ebfa
commit afc5c1fbbd

View file

@ -6,11 +6,13 @@ from PyQt5.QtGui import QDesktopServices
from UM.Extension import Extension
from UM.Application import Application
from UM.Logger import Logger
from UM.i18n import i18nCatalog
from UM.Settings.ContainerRegistry import ContainerRegistry
from cura.Settings.GlobalStack import GlobalStack
from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob
from UM.Settings.ContainerRegistry import ContainerRegistry
i18n_catalog = i18nCatalog("cura")
@ -35,6 +37,7 @@ class FirmwareUpdateChecker(Extension):
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
self._download_url = None
self._check_job = None
## Callback for the message that is spawned when there is a new version.
def _onActionTriggered(self, message, action):
@ -50,6 +53,9 @@ class FirmwareUpdateChecker(Extension):
if isinstance(container, GlobalStack):
self.checkFirmwareVersion(container, True)
def _onJobFinished(self, *args, **kwargs):
self._check_job = None
## Connect with software.ultimaker.com, load latest.version and check version info.
# If the version info is different from the current version, spawn a message to
# allow the user to download it.
@ -57,7 +63,13 @@ class FirmwareUpdateChecker(Extension):
# \param silent type(boolean) Suppresses messages other than "new version found" messages.
# This is used when checking for a new firmware version at startup.
def checkFirmwareVersion(self, container = None, silent = False):
job = FirmwareUpdateCheckerJob(container = container, silent = silent, url = self.JEDI_VERSION_URL,
callback = self._onActionTriggered,
set_download_url_callback = self._onSetDownloadUrl)
job.start()
# Do not run multiple check jobs in parallel
if self._check_job is not None:
Logger.log("i", "A firmware update check is already running, do nothing.")
return
self._check_job = FirmwareUpdateCheckerJob(container = container, silent = silent, url = self.JEDI_VERSION_URL,
callback = self._onActionTriggered,
set_download_url_callback = self._onSetDownloadUrl)
self._check_job.start()
self._check_job.finished.connect(self._onJobFinished)