diff --git a/cura/API/Account.py b/cura/API/Account.py index ef72d972c1..7c81358379 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -31,6 +31,8 @@ class Account(QObject): loginStateChanged = pyqtSignal(bool) accessTokenChanged = pyqtSignal() cloudPrintersDetectedChanged = pyqtSignal(bool) + isSyncingChanged = pyqtSignal(bool) + manualSyncRequested = pyqtSignal() def __init__(self, application: "CuraApplication", parent = None) -> None: super().__init__(parent) @@ -133,7 +135,7 @@ class Account(QObject): def sync(self) -> None: """Checks for new cloud printers""" - Logger.info("Starting account sync") + self.manualSyncRequested.emit() @pyqtSlot() def logout(self) -> None: diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 46136e3a1b..ef478f338a 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -54,6 +54,8 @@ class CloudOutputDeviceManager: # Ensure we don't start twice. self._running = False + self._syncing = False + def start(self): """Starts running the cloud output device manager, thus periodically requesting cloud data.""" @@ -66,6 +68,8 @@ class CloudOutputDeviceManager: self._update_timer.start() self._getRemoteClusters() + self._account.manualSyncRequested.connect(self._getRemoteClusters) + def stop(self): """Stops running the cloud output device manager.""" @@ -92,6 +96,14 @@ class CloudOutputDeviceManager: def _getRemoteClusters(self) -> None: """Gets all remote clusters from the API.""" + if self._syncing: + return + + if self._update_timer.isActive(): + self._update_timer.stop() + + self._syncing = True + self._account.isSyncingChanged.emit(True) self._api.getClusters(self._onGetRemoteClustersFinished) def _onGetRemoteClustersFinished(self, clusters: List[CloudClusterResponse]) -> None: @@ -119,6 +131,9 @@ class CloudOutputDeviceManager: if removed_device_keys: # If the removed device was active we should connect to the new active device self._connectToActiveMachine() + + self._syncing = False + self._account.isSyncingChanged.emit(False) # Schedule a new update self._update_timer.start()