From c3b0fa5bd3d7cb9604bb856f11f4f4c2c8f1a821 Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Wed, 27 Mar 2024 16:42:45 +0100 Subject: [PATCH] Implement syncing feature for Ultimaker account Updated account syncing functionality for logged-in and non-logged-in sessions in Ultimaker. More specifically, syncing is now engaged when the UI becomes visible and stopped when adding a machine action is triggered. The modifications also include fallback to login if the user is not logged in. CURA-11465 --- cura/API/Account.py | 14 ++++++++++++++ resources/qml/Cura.qml | 2 ++ resources/qml/WelcomePages/AddUltimakerPrinter.qml | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cura/API/Account.py b/cura/API/Account.py index 2651037e9e4..c6027acdb5f 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -190,6 +190,20 @@ def is_staging(self) -> bool: def isLoggedIn(self) -> bool: return self._logged_in + @pyqtSlot() + def stopSyncing(self) -> None: + Logger.debug(f"Stopping sync of cloud printers") + self._setManualSyncEnabled(True) + if self._update_timer.isActive(): + self._update_timer.stop() + + @pyqtSlot() + def startSyncing(self) -> None: + Logger.debug(f"Starting sync of cloud printers") + self._setManualSyncEnabled(False) + if not self._update_timer.isActive(): + self._update_timer.start() + def _onLoginStateChanged(self, logged_in: bool = False, error_message: Optional[str] = None) -> None: if error_message: if self._error_message: diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 776417e15d7..678bf85c974 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -864,6 +864,7 @@ UM.MainWindow if(!visible) { wizardDialog = null + Cura.API.account.startSyncing() } } } @@ -891,6 +892,7 @@ UM.MainWindow target: Cura.Actions.addMachine function onTriggered() { + Cura.API.account.stopSyncing() wizardDialog = addMachineDialogLoader.createObject() wizardDialog.show() } diff --git a/resources/qml/WelcomePages/AddUltimakerPrinter.qml b/resources/qml/WelcomePages/AddUltimakerPrinter.qml index ff87a723302..0c9b7d4f7f5 100644 --- a/resources/qml/WelcomePages/AddUltimakerPrinter.qml +++ b/resources/qml/WelcomePages/AddUltimakerPrinter.qml @@ -133,7 +133,7 @@ Control text = catalog.i18nc("@button", "Waiting for new printers") busy = true; enabled = false; - Cura.API.account.login(); + Cura.API.account.isLoggedIn? Cura.API.account.sync():Cura.API.account.login(); } } }