FirmwareUpdateChecker.py 2.4 KB

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