mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-12 01:07:52 -06:00
Register CloudPackageChecker as Account sync service
CURA-7290
This commit is contained in:
parent
049c1946d4
commit
eeea1692fd
1 changed files with 13 additions and 4 deletions
|
@ -20,6 +20,9 @@ from ..CloudApiModel import CloudApiModel
|
||||||
|
|
||||||
|
|
||||||
class CloudPackageChecker(QObject):
|
class CloudPackageChecker(QObject):
|
||||||
|
|
||||||
|
SYNC_SERVICE_NAME = "CloudPackageChecker"
|
||||||
|
|
||||||
def __init__(self, application: CuraApplication) -> None:
|
def __init__(self, application: CuraApplication) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
@ -38,17 +41,19 @@ class CloudPackageChecker(QObject):
|
||||||
def _onAppInitialized(self) -> None:
|
def _onAppInitialized(self) -> None:
|
||||||
self._package_manager = self._application.getPackageManager()
|
self._package_manager = self._application.getPackageManager()
|
||||||
# initial check
|
# initial check
|
||||||
self._onLoginStateChanged()
|
self._getPackagesIfLoggedIn()
|
||||||
# check again whenever the login state changes
|
|
||||||
self._application.getCuraAPI().account.loginStateChanged.connect(self._onLoginStateChanged)
|
|
||||||
|
|
||||||
def _onLoginStateChanged(self) -> None:
|
self._application.getCuraAPI().account.loginStateChanged.connect(self._getPackagesIfLoggedIn)
|
||||||
|
self._application.getCuraAPI().account.manualSyncRequested.connect(self._getPackagesIfLoggedIn)
|
||||||
|
|
||||||
|
def _getPackagesIfLoggedIn(self) -> None:
|
||||||
if self._application.getCuraAPI().account.isLoggedIn:
|
if self._application.getCuraAPI().account.isLoggedIn:
|
||||||
self._getUserSubscribedPackages()
|
self._getUserSubscribedPackages()
|
||||||
else:
|
else:
|
||||||
self._hideSyncMessage()
|
self._hideSyncMessage()
|
||||||
|
|
||||||
def _getUserSubscribedPackages(self) -> None:
|
def _getUserSubscribedPackages(self) -> None:
|
||||||
|
self._application.getCuraAPI().account.setSyncState(self.SYNC_SERVICE_NAME, "syncing")
|
||||||
Logger.debug("Requesting subscribed packages metadata from server.")
|
Logger.debug("Requesting subscribed packages metadata from server.")
|
||||||
url = CloudApiModel.api_url_user_packages
|
url = CloudApiModel.api_url_user_packages
|
||||||
self._application.getHttpRequestManager().get(url,
|
self._application.getHttpRequestManager().get(url,
|
||||||
|
@ -61,6 +66,7 @@ class CloudPackageChecker(QObject):
|
||||||
Logger.log("w",
|
Logger.log("w",
|
||||||
"Requesting user packages failed, response code %s while trying to connect to %s",
|
"Requesting user packages failed, response code %s while trying to connect to %s",
|
||||||
reply.attribute(QNetworkRequest.HttpStatusCodeAttribute), reply.url())
|
reply.attribute(QNetworkRequest.HttpStatusCodeAttribute), reply.url())
|
||||||
|
self._application.getCuraAPI().account.setSyncState(self.SYNC_SERVICE_NAME, "error")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -69,11 +75,14 @@ class CloudPackageChecker(QObject):
|
||||||
if "errors" in json_data:
|
if "errors" in json_data:
|
||||||
for error in json_data["errors"]:
|
for error in json_data["errors"]:
|
||||||
Logger.log("e", "%s", error["title"])
|
Logger.log("e", "%s", error["title"])
|
||||||
|
self._application.getCuraAPI().account.setSyncState(self.SYNC_SERVICE_NAME, "error")
|
||||||
return
|
return
|
||||||
self._handleCompatibilityData(json_data["data"])
|
self._handleCompatibilityData(json_data["data"])
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
Logger.log("w", "Received invalid JSON for user subscribed packages from the Web Marketplace")
|
Logger.log("w", "Received invalid JSON for user subscribed packages from the Web Marketplace")
|
||||||
|
|
||||||
|
self._application.getCuraAPI().account.setSyncState(self.SYNC_SERVICE_NAME, "success")
|
||||||
|
|
||||||
def _handleCompatibilityData(self, subscribed_packages_payload: List[Dict[str, Any]]) -> None:
|
def _handleCompatibilityData(self, subscribed_packages_payload: List[Dict[str, Any]]) -> None:
|
||||||
user_subscribed_packages = [plugin["package_id"] for plugin in subscribed_packages_payload]
|
user_subscribed_packages = [plugin["package_id"] for plugin in subscribed_packages_payload]
|
||||||
user_installed_packages = self._package_manager.getUserInstalledPackages()
|
user_installed_packages = self._package_manager.getUserInstalledPackages()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue