FirmwareUpdateChecker.py 3.0 KB

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