mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-01 16:24:41 +08:00
Prevent continued connect / disconnect loop
If a cloud printer was connected, it would time out all the time. In some cases it would do this in a single update loop (so connect and disconnect). Depending on the machine of the user, this would either be visible or not at all.
This commit is contained in:
parent
bf9c413516
commit
f6cbb0f88c
@ -45,10 +45,6 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
# States indicating if a print job is queued.
|
# States indicating if a print job is queued.
|
||||||
QUEUED_PRINT_JOBS_STATES = {"queued", "error"}
|
QUEUED_PRINT_JOBS_STATES = {"queued", "error"}
|
||||||
|
|
||||||
# Time in seconds since last network response after which we consider this device offline.
|
|
||||||
# We set this a bit higher than some of the other intervals to make sure they don't overlap.
|
|
||||||
NETWORK_RESPONSE_CONSIDER_OFFLINE = 10.0 # seconds
|
|
||||||
|
|
||||||
def __init__(self, device_id: str, address: str, properties: Dict[bytes, bytes], connection_type: ConnectionType,
|
def __init__(self, device_id: str, address: str, properties: Dict[bytes, bytes], connection_type: ConnectionType,
|
||||||
parent=None) -> None:
|
parent=None) -> None:
|
||||||
|
|
||||||
@ -87,6 +83,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
# The job upload progress message modal.
|
# The job upload progress message modal.
|
||||||
self._progress = PrintJobUploadProgressMessage()
|
self._progress = PrintJobUploadProgressMessage()
|
||||||
|
|
||||||
|
self._timeout_time = 30
|
||||||
|
|
||||||
@pyqtProperty(str, constant=True)
|
@pyqtProperty(str, constant=True)
|
||||||
def address(self) -> str:
|
def address(self) -> str:
|
||||||
"""The IP address of the printer."""
|
"""The IP address of the printer."""
|
||||||
@ -213,8 +211,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
return Duration(seconds).getDisplayString(DurationFormat.Format.Short)
|
return Duration(seconds).getDisplayString(DurationFormat.Format.Short)
|
||||||
|
|
||||||
def _update(self) -> None:
|
def _update(self) -> None:
|
||||||
self._checkStillConnected()
|
|
||||||
super()._update()
|
super()._update()
|
||||||
|
self._checkStillConnected()
|
||||||
|
|
||||||
def _checkStillConnected(self) -> None:
|
def _checkStillConnected(self) -> None:
|
||||||
"""Check if we're still connected by comparing the last timestamps for network response and the current time.
|
"""Check if we're still connected by comparing the last timestamps for network response and the current time.
|
||||||
@ -224,7 +222,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
TODO: it would be nice to have this logic in the managers, but connecting those with signals causes crashes.
|
TODO: it would be nice to have this logic in the managers, but connecting those with signals causes crashes.
|
||||||
"""
|
"""
|
||||||
time_since_last_response = time() - self._time_of_last_response
|
time_since_last_response = time() - self._time_of_last_response
|
||||||
if time_since_last_response > self.NETWORK_RESPONSE_CONSIDER_OFFLINE:
|
if time_since_last_response > self._timeout_time:
|
||||||
|
Logger.log("d", "It has been %s seconds since the last response for outputdevice %s, so assume a timeout", time_since_last_response, self.key)
|
||||||
self.setConnectionState(ConnectionState.Closed)
|
self.setConnectionState(ConnectionState.Closed)
|
||||||
if self.key in CuraApplication.getInstance().getOutputDeviceManager().getOutputDeviceIds():
|
if self.key in CuraApplication.getInstance().getOutputDeviceManager().getOutputDeviceIds():
|
||||||
CuraApplication.getInstance().getOutputDeviceManager().removeOutputDevice(self.key)
|
CuraApplication.getInstance().getOutputDeviceManager().removeOutputDevice(self.key)
|
||||||
@ -241,6 +240,7 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Indicate this device is now connected again.
|
# Indicate this device is now connected again.
|
||||||
|
Logger.log("d", "Reconnecting output device after timeout.")
|
||||||
self.setConnectionState(ConnectionState.Connected)
|
self.setConnectionState(ConnectionState.Connected)
|
||||||
|
|
||||||
# If the device was already registered we don't need to register it again.
|
# If the device was already registered we don't need to register it again.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user