diff --git a/cura/API/ConnectionStatus.py b/cura/API/ConnectionStatus.py index 483284d1c7..36f804e3cf 100644 --- a/cura/API/ConnectionStatus.py +++ b/cura/API/ConnectionStatus.py @@ -2,11 +2,16 @@ from typing import Optional from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty -from UM.Logger import Logger +from UM.TaskManagement.HttpRequestManager import HttpRequestManager class ConnectionStatus(QObject): - """Status info for some web services""" + """Provides an estimation of whether internet is reachable + + Estimation is updated with every request through HttpRequestManager. + Acts as a proxy to HttpRequestManager.internetReachableChanged without + exposing the HttpRequestManager in its entirety. + """ __instance = None # type: Optional[ConnectionStatus] @@ -21,16 +26,16 @@ class ConnectionStatus(QObject): def __init__(self, parent: Optional["QObject"] = None) -> None: super().__init__(parent) - self._is_internet_reachable = True # type: bool + manager = HttpRequestManager.getInstance() + self._is_internet_reachable = manager.isInternetReachable # type: bool + manager.internetReachableChanged.connect(self._onInternetReachableChanged) @pyqtProperty(bool, notify = internetReachableChanged) def isInternetReachable(self) -> bool: return self._is_internet_reachable - def setOnlineStatus(self, new_status: bool) -> None: - old_status = self._is_internet_reachable - self._is_internet_reachable = new_status - if old_status != new_status: - Logger.debug( - "Connection status has been set to {}".format("online" if self._is_internet_reachable else "offline")) + def _onInternetReachableChanged(self, reachable: bool): + if reachable != self._is_internet_reachable: + self._is_internet_reachable = reachable self.internetReachableChanged.emit() + diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 852af0de4c..da200c7fc2 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -106,8 +106,6 @@ class CloudOutputDeviceManager: def _onGetRemoteClustersFinished(self, clusters: List[CloudClusterResponse]) -> None: """Callback for when the request for getting the clusters is successful and finished.""" - # Remote clusters were successfully retrieved, which means that the computer is online - CuraApplication.getInstance().getCuraAPI().connectionStatus.setOnlineStatus(True) self._um_cloud_printers = {m.getMetaDataEntry(self.META_CLUSTER_ID): m for m in CuraApplication.getInstance().getContainerRegistry().findContainerStacks( type = "machine") if m.getMetaDataEntry(self.META_CLUSTER_ID, None)} @@ -152,9 +150,6 @@ class CloudOutputDeviceManager: def _onGetRemoteClusterFailed(self, reply: QNetworkReply, error: QNetworkReply.NetworkError) -> None: self._syncing = False self._account.setSyncState(self.SYNC_SERVICE_NAME, SyncState.ERROR) - # If getting the remote clusters fails, then the cloud printers are unreachable, so we need to inform the - # connection status - CuraApplication.getInstance().getCuraAPI().connectionStatus.setOnlineStatus(False) def _onDevicesDiscovered(self, clusters: List[CloudClusterResponse]) -> None: """**Synchronously** create machines for discovered devices