FirmwareUpdateChecker.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Extension import Extension
  4. from UM.Preferences import Preferences
  5. from UM.Logger import Logger
  6. from UM.i18n import i18nCatalog
  7. from cura.Settings.GlobalStack import GlobalStack
  8. from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob
  9. from UM.Settings.ContainerRegistry import ContainerRegistry
  10. i18n_catalog = i18nCatalog("cura")
  11. ## This Extension checks for new versions of the firmware based on the latest checked version number.
  12. # The plugin is currently only usable for applications maintained by Ultimaker. But it should be relatively easy
  13. # to change it to work for other applications.
  14. class FirmwareUpdateChecker(Extension):
  15. JEDI_VERSION_URL = "http://software.ultimaker.com/jedi/releases/latest.version"
  16. def __init__(self):
  17. super().__init__()
  18. # Initialize the Preference called `latest_checked_firmware` that stores the last version
  19. # checked for the UM3. In the future if we need to check other printers' firmware
  20. Preferences.getInstance().addPreference("info/latest_checked_firmware", "")
  21. # Listen to a Signal that indicates a change in the list of printers, just if the user has enabled the
  22. # 'check for updates' option
  23. Preferences.getInstance().addPreference("info/automatic_update_check", True)
  24. if Preferences.getInstance().getValue("info/automatic_update_check"):
  25. ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
  26. def _onContainerAdded(self, container):
  27. # Only take care when a new GlobalStack was added
  28. if isinstance(container, GlobalStack):
  29. Logger.log("i", "You have a '%s' in printer list. Let's check the firmware!", container.getId())
  30. self.checkFirmwareVersion(container, True)
  31. ## Connect with software.ultimaker.com, load latest.version and check version info.
  32. # If the version info is different from the current version, spawn a message to
  33. # allow the user to download it.
  34. #
  35. # \param silent type(boolean) Suppresses messages other than "new version found" messages.
  36. # This is used when checking for a new firmware version at startup.
  37. def checkFirmwareVersion(self, container = None, silent = False):
  38. job = FirmwareUpdateCheckerJob(container = container, silent = silent, url = self.JEDI_VERSION_URL)
  39. job.start()