Put the firmware-update meta-data in the 'normal' printer definitions and make the code handle that.

This commit is contained in:
Remco Burema 2018-10-13 21:55:33 +02:00
parent 931143ceaa
commit 2e3abbc904
8 changed files with 73 additions and 113 deletions

View file

@ -10,15 +10,12 @@ from typing import Set
from UM.Extension import Extension
from UM.Application import Application
from UM.Logger import Logger
from UM.PluginRegistry import PluginRegistry
from UM.Qt.QtApplication import QtApplication
from UM.i18n import i18nCatalog
from UM.Settings.ContainerRegistry import ContainerRegistry
from cura.Settings.GlobalStack import GlobalStack
from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob
from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup, getSettingsKeyForMachine
from .FirmwareUpdateCheckerMessage import FirmwareUpdateCheckerMessage
i18n_catalog = i18nCatalog("cura")
@ -38,18 +35,14 @@ class FirmwareUpdateChecker(Extension):
if Application.getInstance().getPreferences().getValue("info/automatic_update_check"):
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
# Partly initialize after creation, since we need our own path from the plugin-manager.
self._download_url = None
self._check_job = None
self._checked_printer_names = set() # type: Set[str]
self._lookups = None
QtApplication.pluginsLoaded.connect(self._onPluginsLoaded)
## Callback for the message that is spawned when there is a new version.
def _onActionTriggered(self, message, action):
if action == FirmwareUpdateCheckerMessage.STR_ACTION_DOWNLOAD:
machine_id = message.getMachineId()
download_url = self._lookups.getRedirectUserFor(machine_id)
download_url = message.getDownloadUrl()
if download_url is not None:
if QDesktopServices.openUrl(QUrl(download_url)):
Logger.log("i", "Redirected browser to {0} to show newly available firmware.".format(download_url))
@ -66,18 +59,6 @@ class FirmwareUpdateChecker(Extension):
def _onJobFinished(self, *args, **kwargs):
self._check_job = None
def _onPluginsLoaded(self):
if self._lookups is not None:
return
self._lookups = FirmwareUpdateCheckerLookup(os.path.join(PluginRegistry.getInstance().getPluginPath(
"FirmwareUpdateChecker"), "resources/machines.json"))
# Initialize the Preference called `latest_checked_firmware` that stores the last version
# checked for each printer.
for machine_id in self._lookups.getMachineIds():
Application.getInstance().getPreferences().addPreference(getSettingsKeyForMachine(machine_id), "")
## 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.
@ -85,16 +66,18 @@ 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):
if self._lookups is None:
self._onPluginsLoaded()
container_name = container.definition.getName()
if container_name in self._checked_printer_names:
return
self._checked_printer_names.add(container_name)
metadata = container.definition.getMetaData().get("firmware_update_info")
if metadata is None:
Logger.log("i", "No machine with name {0} in list of firmware to check.".format(container_name))
return
self._check_job = FirmwareUpdateCheckerJob(container = container, silent = silent,
lookups = self._lookups,
machine_name = container_name, metadata = metadata,
callback = self._onActionTriggered)
self._check_job.start()
self._check_job.finished.connect(self._onJobFinished)