mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-11-02 20:52:20 -07:00
Merge branch 'CURA-7099_sync_sideloaded_plugins'
This commit is contained in:
commit
66e2ca6aa5
5 changed files with 49 additions and 25 deletions
|
|
@ -1,23 +1,51 @@
|
|||
from UM.Logger import Logger
|
||||
from UM.TaskManagement.HttpRequestManager import HttpRequestManager
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from ..CloudApiModel import CloudApiModel
|
||||
from ..UltimakerCloudScope import UltimakerCloudScope
|
||||
|
||||
|
||||
## Manages Cloud subscriptions. When a package is added to a user's account, the user is 'subscribed' to that package
|
||||
# Whenever the user logs in on another instance of Cura, these subscriptions can be used to sync the user's plugins
|
||||
class CloudPackageManager:
|
||||
def __init__(self, app: CuraApplication) -> None:
|
||||
self._request_manager = app.getHttpRequestManager()
|
||||
self._scope = UltimakerCloudScope(app)
|
||||
"""Manages Cloud subscriptions
|
||||
|
||||
def subscribe(self, package_id: str) -> None:
|
||||
data = "{\"data\": {\"package_id\": \"%s\", \"sdk_version\": \"%s\"}}" % (package_id, CloudApiModel.sdk_version)
|
||||
self._request_manager.put(url=CloudApiModel.api_url_user_packages,
|
||||
data=data.encode(),
|
||||
scope=self._scope
|
||||
)
|
||||
When a package is added to a user's account, the user is 'subscribed' to that package.
|
||||
Whenever the user logs in on another instance of Cura, these subscriptions can be used to sync the user's plugins
|
||||
|
||||
Singleton: use CloudPackageManager.getInstance() instead of CloudPackageManager()
|
||||
"""
|
||||
|
||||
__instance = None
|
||||
|
||||
@classmethod
|
||||
def getInstance(cls, app: CuraApplication):
|
||||
if not cls.__instance:
|
||||
cls.__instance = CloudPackageManager(app)
|
||||
return cls.__instance
|
||||
|
||||
def __init__(self, app: CuraApplication) -> None:
|
||||
if self.__instance is not None:
|
||||
raise RuntimeError("This is a Singleton. use getInstance()")
|
||||
|
||||
self._scope = UltimakerCloudScope(app) # type: UltimakerCloudScope
|
||||
|
||||
app.getPackageManager().packageInstalled.connect(self._onPackageInstalled)
|
||||
|
||||
def unsubscribe(self, package_id: str) -> None:
|
||||
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:
|
||||
"""You probably don't want to use this directly. All installed packages will be automatically subscribed."""
|
||||
|
||||
Logger.debug("Subscribing to {}", package_id)
|
||||
data = "{\"data\": {\"package_id\": \"%s\", \"sdk_version\": \"%s\"}}" % (package_id, CloudApiModel.sdk_version)
|
||||
HttpRequestManager.getInstance().put(
|
||||
url = CloudApiModel.api_url_user_packages,
|
||||
data = data.encode(),
|
||||
scope = self._scope
|
||||
)
|
||||
|
||||
def _onPackageInstalled(self, package_id: str):
|
||||
if CuraApplication.getInstance().getCuraAPI().account.isLoggedIn:
|
||||
# We might already be subscribed, but checking would take one extra request. Instead, simply subscribe
|
||||
self._subscribe(package_id)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ class SyncOrchestrator(Extension):
|
|||
self._name = "SyncOrchestrator"
|
||||
|
||||
self._package_manager = app.getPackageManager()
|
||||
self._cloud_package_manager = CloudPackageManager(app)
|
||||
# Keep a reference to the CloudPackageManager. it watches for installed packages and subscribes to them
|
||||
self._cloud_package_manager = CloudPackageManager.getInstance(app) # type: CloudPackageManager
|
||||
|
||||
self._checker = CloudPackageChecker(app) # type: CloudPackageChecker
|
||||
self._checker.discrepancies.connect(self._onDiscrepancies)
|
||||
|
|
@ -84,7 +85,6 @@ class SyncOrchestrator(Extension):
|
|||
message = "Could not install {}".format(item["package_id"])
|
||||
self._showErrorMessage(message)
|
||||
continue
|
||||
self._cloud_package_manager.subscribe(item["package_id"])
|
||||
has_changes = True
|
||||
else:
|
||||
self._cloud_package_manager.unsubscribe(item["package_id"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue