Process review comments

CURA-7099
This commit is contained in:
Nino van Hooff 2020-01-29 11:28:29 +01:00
parent d4eb463f2d
commit 8c250cfbbc
2 changed files with 11 additions and 13 deletions

View file

@ -474,7 +474,7 @@ class CuraApplication(QtApplication):
"CuraEngineBackend", #Cura is useless without this one since you can't slice. "CuraEngineBackend", #Cura is useless without this one since you can't slice.
"FileLogger", #You want to be able to read the log if something goes wrong. "FileLogger", #You want to be able to read the log if something goes wrong.
"XmlMaterialProfile", #Cura crashes without this one. "XmlMaterialProfile", #Cura crashes without this one.
"Toolbox", #This contains the interface to enable/disable plug-ins and the Cloud functionality. "Toolbox", #This contains the interface to enable/disable plug-ins, so if you disable it you can't enable it back.
"PrepareStage", #Cura is useless without this one since you can't load models. "PrepareStage", #Cura is useless without this one since you can't load models.
"PreviewStage", #This shows the list of the plugin views that are installed in Cura. "PreviewStage", #This shows the list of the plugin views that are installed in Cura.
"MonitorStage", #Major part of Cura's functionality. "MonitorStage", #Major part of Cura's functionality.

View file

@ -1,6 +1,5 @@
from UM.Logger import Logger from UM.Logger import Logger
from UM.TaskManagement.HttpRequestManager import HttpRequestManager from UM.TaskManagement.HttpRequestManager import HttpRequestManager
from cura.API import Account
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from ..CloudApiModel import CloudApiModel from ..CloudApiModel import CloudApiModel
from ..UltimakerCloudScope import UltimakerCloudScope from ..UltimakerCloudScope import UltimakerCloudScope
@ -25,29 +24,28 @@ class CloudPackageManager:
def __init__(self, app: CuraApplication) -> None: def __init__(self, app: CuraApplication) -> None:
if self.__instance is not None: if self.__instance is not None:
raise Exception("This is a Singleton. use getInstance()") raise RuntimeError("This is a Singleton. use getInstance()")
self._request_manager = app.getHttpRequestManager() # type: HttpRequestManager
self.account = app.getCuraAPI().account # type: Account
self._scope = UltimakerCloudScope(app) # type: UltimakerCloudScope self._scope = UltimakerCloudScope(app) # type: UltimakerCloudScope
app.getPackageManager().packageInstalled.connect(self._onPackageInstalled) app.getPackageManager().packageInstalled.connect(self._onPackageInstalled)
def unsubscribe(self, package_id: str) -> None: def unsubscribe(self, package_id: str) -> None:
url = CloudApiModel.userPackageUrl(package_id) url = CloudApiModel.userPackageUrl(package_id)
self._request_manager.delete(url=url, scope=self._scope) HttpRequestManager.getInstance().delete(url=url, scope=self._scope)
def subscribe(self, package_id: str) -> None: def _subscribe(self, package_id: str) -> None:
"""You probably don't want to use this directly. All installed packages will be automatically subscribed.""" """You probably don't want to use this directly. All installed packages will be automatically subscribed."""
Logger.debug("Subscribing to {}", package_id) Logger.debug("Subscribing to {}", package_id)
data = "{\"data\": {\"package_id\": \"%s\", \"sdk_version\": \"%s\"}}" % (package_id, CloudApiModel.sdk_version) data = "{\"data\": {\"package_id\": \"%s\", \"sdk_version\": \"%s\"}}" % (package_id, CloudApiModel.sdk_version)
self._request_manager.put(url=CloudApiModel.api_url_user_packages, HttpRequestManager.getInstance().put(
url=CloudApiModel.api_url_user_packages,
data=data.encode(), data=data.encode(),
scope=self._scope scope=self._scope
) )
def _onPackageInstalled(self, package_id: str): def _onPackageInstalled(self, package_id: str):
if self.account.isLoggedIn: if CuraApplication.getInstance().getCuraAPI().account.isLoggedIn:
# We might already be subscribed, but checking would take one extra request. Instead, simply subscribe # We might already be subscribed, but checking would take one extra request. Instead, simply subscribe
self.subscribe(package_id) self._subscribe(package_id)