mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Automatic abortRequest for each API request
Defensive programming Contributes to: CURA-8587
This commit is contained in:
parent
453de95d12
commit
7be2da587b
@ -5,7 +5,7 @@ import json
|
||||
import os.path
|
||||
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, Qt
|
||||
from typing import cast, Dict, List, Optional, Set, TYPE_CHECKING
|
||||
from typing import cast, Dict, Optional, Set, TYPE_CHECKING
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
from UM.Qt.ListModel import ListModel
|
||||
@ -53,17 +53,26 @@ class PackageList(ListModel):
|
||||
self._scope = JsonDecoratorScope(UltimakerCloudScope(CuraApplication.getInstance()))
|
||||
self._license_dialogs: Dict[str, QObject] = {}
|
||||
|
||||
def __del__(self) -> None:
|
||||
""" When this object is deleted it will loop through all registered API requests and aborts them """
|
||||
self.cleanUpAPIRequest()
|
||||
|
||||
def abortRequest(self, request_id: str) -> None:
|
||||
"""Aborts a single request"""
|
||||
if request_id in self._ongoing_requests and self._ongoing_requests[request_id]:
|
||||
HttpRequestManager.getInstance().abortRequest(self._ongoing_requests[request_id])
|
||||
self._ongoing_requests[request_id] = None
|
||||
|
||||
@pyqtSlot()
|
||||
def cleanUpAPIRequest(self) -> None:
|
||||
for request_id in self._ongoing_requests:
|
||||
self.abortRequest(request_id)
|
||||
|
||||
@pyqtSlot()
|
||||
def updatePackages(self) -> None:
|
||||
""" A Qt slot which will update the List from a source. Actual implementation should be done in the child class"""
|
||||
pass
|
||||
|
||||
@pyqtSlot()
|
||||
def abortUpdating(self) -> None:
|
||||
""" A Qt slot which allows the update process to be aborted. Override this for child classes with async/callback
|
||||
updatePackges methods"""
|
||||
pass
|
||||
|
||||
def reset(self) -> None:
|
||||
""" Resets and clears the list"""
|
||||
self.clear()
|
||||
|
@ -33,13 +33,6 @@ class RemotePackageList(PackageList):
|
||||
self.isLoadingChanged.connect(self._onLoadingChanged)
|
||||
self.isLoadingChanged.emit()
|
||||
|
||||
def __del__(self) -> None:
|
||||
"""
|
||||
When deleting this object, abort the request so that we don't get a callback from it later on a deleted C++
|
||||
object.
|
||||
"""
|
||||
self.abortUpdating()
|
||||
|
||||
@pyqtSlot()
|
||||
def updatePackages(self) -> None:
|
||||
"""
|
||||
@ -57,11 +50,6 @@ class RemotePackageList(PackageList):
|
||||
error_callback = self._onError
|
||||
)
|
||||
|
||||
@pyqtSlot()
|
||||
def abortUpdating(self) -> None:
|
||||
HttpRequestManager.getInstance().abortRequest(self._ongoing_requests["get_packages"])
|
||||
self._ongoing_requests["get_packages"] = None
|
||||
|
||||
def reset(self) -> None:
|
||||
self.clear()
|
||||
self._request_url = self._initialRequestUrl()
|
||||
|
@ -24,7 +24,7 @@ ListView
|
||||
clip: true
|
||||
|
||||
Component.onCompleted: model.updatePackages()
|
||||
Component.onDestruction: model.abortUpdating()
|
||||
Component.onDestruction: model.cleanUpAPIRequest()
|
||||
|
||||
spacing: UM.Theme.getSize("default_margin").height
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user