mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Set the right firmware-download-URL in the actual update-firmware-message.
This commit is contained in:
parent
472d012c08
commit
4ecac6e27f
@ -14,8 +14,8 @@ from UM.Settings.ContainerRegistry import ContainerRegistry
|
|||||||
|
|
||||||
from cura.Settings.GlobalStack import GlobalStack
|
from cura.Settings.GlobalStack import GlobalStack
|
||||||
|
|
||||||
from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob, get_settings_key_for_machine
|
from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob
|
||||||
from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup
|
from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup, get_settings_key_for_machine
|
||||||
|
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
@ -39,14 +39,15 @@ class FirmwareUpdateChecker(Extension):
|
|||||||
self._name_cache = []
|
self._name_cache = []
|
||||||
|
|
||||||
## Callback for the message that is spawned when there is a new version.
|
## Callback for the message that is spawned when there is a new version.
|
||||||
# TODO: Set the right download URL for each message!
|
|
||||||
def _onActionTriggered(self, message, action):
|
def _onActionTriggered(self, message, action):
|
||||||
if action == "download":
|
try:
|
||||||
if self._download_url is not None:
|
download_url = self._lookups.getRedirectUserFor(int(action))
|
||||||
QDesktopServices.openUrl(QUrl(self._download_url))
|
if download_url is not None:
|
||||||
|
QDesktopServices.openUrl(QUrl(download_url))
|
||||||
def _onSetDownloadUrl(self, download_url):
|
else:
|
||||||
self._download_url = download_url
|
Logger.log('e', "Can't find URL for {0}".format(action))
|
||||||
|
except:
|
||||||
|
Logger.log('e', "Don't know what to do with {0}".format(action))
|
||||||
|
|
||||||
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
|
||||||
@ -56,7 +57,7 @@ class FirmwareUpdateChecker(Extension):
|
|||||||
def _onJobFinished(self, *args, **kwargs):
|
def _onJobFinished(self, *args, **kwargs):
|
||||||
self._check_job = None
|
self._check_job = None
|
||||||
|
|
||||||
def lateInit(self):
|
def doLateInit(self):
|
||||||
self._late_init = False
|
self._late_init = False
|
||||||
|
|
||||||
self._lookups = FirmwareUpdateCheckerLookup(os.path.join(PluginRegistry.getInstance().getPluginPath(
|
self._lookups = FirmwareUpdateCheckerLookup(os.path.join(PluginRegistry.getInstance().getPluginPath(
|
||||||
@ -75,7 +76,7 @@ class FirmwareUpdateChecker(Extension):
|
|||||||
# 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):
|
||||||
if self._late_init:
|
if self._late_init:
|
||||||
self.lateInit()
|
self.doLateInit()
|
||||||
|
|
||||||
container_name = container.definition.getName()
|
container_name = container.definition.getName()
|
||||||
if container_name in self._name_cache:
|
if container_name in self._name_cache:
|
||||||
@ -84,7 +85,6 @@ class FirmwareUpdateChecker(Extension):
|
|||||||
|
|
||||||
self._check_job = FirmwareUpdateCheckerJob(container = container, silent = silent,
|
self._check_job = FirmwareUpdateCheckerJob(container = container, silent = silent,
|
||||||
lookups = self._lookups,
|
lookups = self._lookups,
|
||||||
callback = self._onActionTriggered,
|
callback = self._onActionTriggered)
|
||||||
set_download_url_callback = self._onSetDownloadUrl)
|
|
||||||
self._check_job.start()
|
self._check_job.start()
|
||||||
self._check_job.finished.connect(self._onJobFinished)
|
self._check_job.finished.connect(self._onJobFinished)
|
||||||
|
@ -11,16 +11,12 @@ import urllib.request
|
|||||||
from urllib.error import URLError
|
from urllib.error import URLError
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup
|
from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup, get_settings_key_for_machine
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
def get_settings_key_for_machine(machine_id: int) -> str:
|
|
||||||
return "info/latest_checked_firmware_for_{0}".format(machine_id)
|
|
||||||
|
|
||||||
|
|
||||||
## 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):
|
||||||
STRING_ZERO_VERSION = "0.0.0"
|
STRING_ZERO_VERSION = "0.0.0"
|
||||||
@ -28,12 +24,12 @@ class FirmwareUpdateCheckerJob(Job):
|
|||||||
ZERO_VERSION = Version(STRING_ZERO_VERSION)
|
ZERO_VERSION = Version(STRING_ZERO_VERSION)
|
||||||
EPSILON_VERSION = Version(STRING_EPSILON_VERSION)
|
EPSILON_VERSION = Version(STRING_EPSILON_VERSION)
|
||||||
|
|
||||||
def __init__(self, container=None, silent=False, lookups:FirmwareUpdateCheckerLookup=None, callback=None, set_download_url_callback=None):
|
def __init__(self, container=None, silent=False, lookups:FirmwareUpdateCheckerLookup=None, callback=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._container = container
|
self._container = container
|
||||||
self.silent = silent
|
self.silent = silent
|
||||||
self._callback = callback
|
self._callback = callback
|
||||||
self._set_download_url_callback = set_download_url_callback
|
|
||||||
self._lookups = lookups
|
self._lookups = lookups
|
||||||
self._headers = {} # Don't set headers yet.
|
self._headers = {} # Don't set headers yet.
|
||||||
|
|
||||||
@ -109,20 +105,13 @@ class FirmwareUpdateCheckerJob(Job):
|
|||||||
"@info:title The %s gets replaced with the printer name.",
|
"@info:title The %s gets replaced with the printer name.",
|
||||||
"New %s firmware available") % machine_name)
|
"New %s firmware available") % machine_name)
|
||||||
|
|
||||||
message.addAction("download",
|
message.addAction(machine_id,
|
||||||
i18n_catalog.i18nc("@action:button", "How to update"),
|
i18n_catalog.i18nc("@action:button", "How to update"),
|
||||||
"[no_icon]",
|
"[no_icon]",
|
||||||
"[no_description]",
|
"[no_description]",
|
||||||
button_style=Message.ActionButtonStyle.LINK,
|
button_style=Message.ActionButtonStyle.LINK,
|
||||||
button_align=Message.ActionButtonStyle.BUTTON_ALIGN_LEFT)
|
button_align=Message.ActionButtonStyle.BUTTON_ALIGN_LEFT)
|
||||||
|
|
||||||
# If we do this in a cool way, the download url should be available in the JSON file
|
|
||||||
if self._set_download_url_callback:
|
|
||||||
redirect = self._lookups.getRedirectUseror(machine_id)
|
|
||||||
if redirect is not None:
|
|
||||||
self._set_download_url_callback(redirect)
|
|
||||||
else:
|
|
||||||
Logger.log('w', "No callback-url for firmware of {0}".format(repr(machine_id)))
|
|
||||||
message.actionTriggered.connect(self._callback)
|
message.actionTriggered.connect(self._callback)
|
||||||
message.show()
|
message.show()
|
||||||
else:
|
else:
|
||||||
|
@ -9,6 +9,11 @@ from UM.Version import Version
|
|||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
|
def get_settings_key_for_machine(machine_id: int) -> str:
|
||||||
|
return "info/latest_checked_firmware_for_{0}".format(machine_id)
|
||||||
|
|
||||||
|
|
||||||
def default_parse_version_response(response: str) -> Version:
|
def default_parse_version_response(response: str) -> Version:
|
||||||
raw_str = response.split('\n', 1)[0].rstrip()
|
raw_str = response.split('\n', 1)[0].rstrip()
|
||||||
return Version(raw_str.split('.')) # Split it into a list; the default parsing of 'single string' is different.
|
return Version(raw_str.split('.')) # Split it into a list; the default parsing of 'single string' is different.
|
||||||
@ -63,5 +68,5 @@ class FirmwareUpdateCheckerLookup:
|
|||||||
def getCheckUrlsFor(self, machine_id: int) -> [str]:
|
def getCheckUrlsFor(self, machine_id: int) -> [str]:
|
||||||
return self._check_urls_per_machine.get(machine_id)
|
return self._check_urls_per_machine.get(machine_id)
|
||||||
|
|
||||||
def getRedirectUseror(self, machine_id: int) -> str:
|
def getRedirectUserFor(self, machine_id: int) -> str:
|
||||||
return self._redirect_user_per_machine.get(machine_id)
|
return self._redirect_user_per_machine.get(machine_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user