mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
The checker now runs also when the user adds a new printer - CURA-4224
This commit is contained in:
parent
b17ff081d6
commit
80992dd44c
2 changed files with 48 additions and 28 deletions
|
@ -1,11 +1,14 @@
|
||||||
# Copyright (c) 2015 Ultimaker B.V.
|
# Copyright (c) 2015 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the AGPLv3 or higher.
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
from UM.Application import Application
|
||||||
from UM.Extension import Extension
|
from UM.Extension import Extension
|
||||||
from UM.Preferences import Preferences
|
from UM.Preferences import Preferences
|
||||||
|
from UM.Logger import Logger
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
|
from cura.Settings.GlobalStack import GlobalStack
|
||||||
|
|
||||||
from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob
|
from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob
|
||||||
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
@ -19,8 +22,18 @@ class FirmwareUpdateChecker(Extension):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
# Initialize the Preference called `latest_checked_firmware` that stores the last version
|
||||||
|
# checked for the UM3. In the future if we need to check other printers' firmware
|
||||||
Preferences.getInstance().addPreference("info/latest_checked_firmware", "")
|
Preferences.getInstance().addPreference("info/latest_checked_firmware", "")
|
||||||
self.checkFirmwareVersion(True)
|
|
||||||
|
# Listen to a Signal that indicates a change in the active printer
|
||||||
|
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
|
||||||
|
|
||||||
|
def _onContainerAdded(self, container):
|
||||||
|
# Only take care when a new GlobaStack was added
|
||||||
|
if (isinstance(container, GlobalStack)):
|
||||||
|
Logger.log("i", "You have a '%s' in printer list. Let's check the firmware!" % container.getId())
|
||||||
|
self.checkFirmwareVersion(container, True)
|
||||||
|
|
||||||
## Connect with software.ultimaker.com, load latest.version and check version info.
|
## 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
|
# If the version info is different from the current version, spawn a message to
|
||||||
|
@ -28,6 +41,6 @@ class FirmwareUpdateChecker(Extension):
|
||||||
#
|
#
|
||||||
# \param silent type(boolean) Suppresses messages other than "new version found" messages.
|
# \param silent type(boolean) Suppresses messages other than "new version found" messages.
|
||||||
# This is used when checking for a new firmware version at startup.
|
# This is used when checking for a new firmware version at startup.
|
||||||
def checkFirmwareVersion(self, silent = False):
|
def checkFirmwareVersion(self, container = None, silent = False):
|
||||||
job = FirmwareUpdateCheckerJob(silent = silent, url = self.url)
|
job = FirmwareUpdateCheckerJob(container = container, silent = silent, url = self.url)
|
||||||
job.start()
|
job.start()
|
|
@ -20,8 +20,9 @@ i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
## This job checks if there is an update available on the provided URL.
|
## This job checks if there is an update available on the provided URL.
|
||||||
class FirmwareUpdateCheckerJob(Job):
|
class FirmwareUpdateCheckerJob(Job):
|
||||||
def __init__(self, silent = False, url = None):
|
def __init__(self, container = None, silent = False, url = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self._container = container
|
||||||
self.silent = silent
|
self.silent = silent
|
||||||
self._url = url
|
self._url = url
|
||||||
self._download_url = None # If an update was found, the download_url will be set to the location of the new version.
|
self._download_url = None # If an update was found, the download_url will be set to the location of the new version.
|
||||||
|
@ -38,38 +39,44 @@ class FirmwareUpdateCheckerJob(Job):
|
||||||
Logger.log("e", "Can not check for a new release. URL not set!")
|
Logger.log("e", "Can not check for a new release. URL not set!")
|
||||||
return
|
return
|
||||||
|
|
||||||
Logger.log("i", "Checking for new version of firmware")
|
|
||||||
try:
|
try:
|
||||||
request = urllib.request.Request(self._url)
|
request = urllib.request.Request(self._url)
|
||||||
current_version_file = urllib.request.urlopen(request)
|
current_version_file = urllib.request.urlopen(request)
|
||||||
reader = codecs.getreader("utf-8")
|
reader = codecs.getreader("utf-8")
|
||||||
|
|
||||||
|
machine_name = self._container.getId()
|
||||||
|
|
||||||
|
# If it is not None, then we compare between the checked_version and the current_version
|
||||||
|
# Now we just do that if the active printer is Ultimaker 3 or Ultimaker 3 Extended or any
|
||||||
|
# other Ultimaker 3 that will come in the future
|
||||||
|
if (machine_name[0:11] == "Ultimaker 3"):
|
||||||
|
|
||||||
# Nothing to parse, just get the string
|
# Nothing to parse, just get the string
|
||||||
# TODO: In the future may be done by parsing a JSON file
|
# TODO: In the future may be done by parsing a JSON file with diferent version for each printer model
|
||||||
current_version = reader(current_version_file).readline().rstrip()
|
current_version = reader(current_version_file).readline().rstrip()
|
||||||
Logger.log("i", "Reading firmware version: %s" % current_version)
|
Logger.log("i", "Reading firmware version of %s: %s" % (machine_name, current_version))
|
||||||
|
|
||||||
# If it is the first time the version is checked, the checked_version is None
|
# If it is the first time the version is checked, the checked_version is None
|
||||||
checked_version = Preferences.getInstance().getValue("info/latest_checked_firmware")
|
checked_version = Preferences.getInstance().getValue("info/latest_checked_firmware")
|
||||||
active_machine = Preferences.getInstance().getValue("cura/active_machine")
|
|
||||||
# If it is not None, then we compare between the checked_version and the current_version
|
# If the checked_version is '', it's because is the first time we check firmware and in this case
|
||||||
# Now we just do that if the active printer is Ultimaker 3 or Ultimaker 3 Extended
|
# we will not show the notification, but we will store it for the next time
|
||||||
if ((active_machine == "Ultimaker 3 Extended") or (active_machine == "Ultimaker 3"))\
|
if (checked_version != "") and (checked_version != current_version):
|
||||||
and ((checked_version is None) or (checked_version != current_version)):
|
|
||||||
message = Message(i18n_catalog.i18nc("@info", "<b>New %s firmware available</b><br/><br/>To ensure that your "
|
message = Message(i18n_catalog.i18nc("@info", "<b>New %s firmware available</b><br/><br/>To ensure that your "
|
||||||
"%s is equiped with the latest features it is recommended "
|
"%s is equiped with the latest features it is recommended "
|
||||||
"to update the firmware regularly. This can be done on the "
|
"to update the firmware regularly. This can be done on the "
|
||||||
"%s (when connected to the network) or via USB."
|
"%s (when connected to the network) or via USB."
|
||||||
% (active_machine, active_machine, active_machine)))
|
% (machine_name, machine_name, machine_name)))
|
||||||
message.addAction("download", i18n_catalog.i18nc("@action:button", "Download"), "[no_icon]", "[no_description]")
|
message.addAction("download", i18n_catalog.i18nc("@action:button", "Download"), "[no_icon]", "[no_description]")
|
||||||
|
|
||||||
# If we do this in a cool way, the download url should be available in the JSON file
|
# If we do this in a cool way, the download url should be available in the JSON file
|
||||||
self._download_url = "https://ultimaker.com/en/resources/20500-upgrade-firmware"
|
self._download_url = "https://ultimaker.com/en/resources/20500-upgrade-firmware"
|
||||||
message.actionTriggered.connect(self.actionTriggered)
|
message.actionTriggered.connect(self.actionTriggered)
|
||||||
# Sometimes it's shown, sometimes not
|
|
||||||
#message.show()
|
|
||||||
Application.getInstance().showMessage(message)
|
Application.getInstance().showMessage(message)
|
||||||
|
|
||||||
|
# The first time we want to store the current version, the notification will not be shown,
|
||||||
|
# because the new version of Cura will be release before the firmware and we don't want to
|
||||||
|
# notify the user when no new firmware version is available.
|
||||||
Preferences.getInstance().setValue("info/latest_checked_firmware", current_version)
|
Preferences.getInstance().setValue("info/latest_checked_firmware", current_version)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue