mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 03:07:53 -06:00
Fix download for firmware upgrade notification
Same issue as the download for Cura version upgrade in CURA-4464.
This commit is contained in:
parent
d65ae62876
commit
2be529668e
2 changed files with 23 additions and 15 deletions
|
@ -1,6 +1,9 @@
|
||||||
# Copyright (c) 2017 Ultimaker B.V.
|
# Copyright (c) 2017 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QUrl
|
||||||
|
from PyQt5.QtGui import QDesktopServices
|
||||||
|
|
||||||
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.Logger import Logger
|
||||||
|
@ -32,6 +35,17 @@ class FirmwareUpdateChecker(Extension):
|
||||||
if Preferences.getInstance().getValue("info/automatic_update_check"):
|
if Preferences.getInstance().getValue("info/automatic_update_check"):
|
||||||
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
|
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
|
||||||
|
|
||||||
|
self._download_url = None
|
||||||
|
|
||||||
|
## Callback for the message that is spawned when there is a new version.
|
||||||
|
def _onActionTriggered(self, message, action):
|
||||||
|
if action == "download":
|
||||||
|
if self._download_url is not None:
|
||||||
|
QDesktopServices.openUrl(QUrl(self._download_url))
|
||||||
|
|
||||||
|
def _onSetDownloadUrl(self, download_url):
|
||||||
|
self._download_url = download_url
|
||||||
|
|
||||||
def _onContainerAdded(self, container):
|
def _onContainerAdded(self, container):
|
||||||
# Only take care when a new GlobalStack was added
|
# Only take care when a new GlobalStack was added
|
||||||
if isinstance(container, GlobalStack):
|
if isinstance(container, GlobalStack):
|
||||||
|
@ -45,5 +59,7 @@ 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, container = None, silent = False):
|
def checkFirmwareVersion(self, container = None, silent = False):
|
||||||
job = FirmwareUpdateCheckerJob(container = container, silent = silent, url = self.JEDI_VERSION_URL)
|
job = FirmwareUpdateCheckerJob(container = container, silent = silent, url = self.JEDI_VERSION_URL,
|
||||||
|
callback = self._onActionTriggered,
|
||||||
|
set_download_url_callback = self._onSetDownloadUrl)
|
||||||
job.start()
|
job.start()
|
||||||
|
|
|
@ -10,30 +10,21 @@ from UM.Job import Job
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl
|
|
||||||
from PyQt5.QtGui import QDesktopServices
|
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
i18n_catalog = i18nCatalog("cura")
|
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, container = None, silent = False, url = None):
|
def __init__(self, container = None, silent = False, url = None, callback = None, set_download_url_callback = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._container = container
|
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._callback = callback
|
||||||
|
self._set_download_url_callback = set_download_url_callback
|
||||||
## Callback for the message that is spawned when there is a new version.
|
|
||||||
def actionTriggered(self, message, action):
|
|
||||||
if action == "download":
|
|
||||||
if self._download_url is not None:
|
|
||||||
QDesktopServices.openUrl(QUrl(self._download_url))
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._download_url = None # Reset download ur.
|
|
||||||
if not self._url:
|
if not self._url:
|
||||||
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
|
||||||
|
@ -75,8 +66,9 @@ class FirmwareUpdateCheckerJob(Job):
|
||||||
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"
|
if self._set_download_url_callback:
|
||||||
message.actionTriggered.connect(self.actionTriggered)
|
self._set_download_url_callback("https://ultimaker.com/en/resources/20500-upgrade-firmware")
|
||||||
|
message.actionTriggered.connect(self._callback)
|
||||||
message.show()
|
message.show()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue