mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 00:07:51 -06:00
Re-create the network manager every 30 seconds of not being connected
CURA-1851
This commit is contained in:
parent
5825793f28
commit
0c931424f9
1 changed files with 26 additions and 9 deletions
|
@ -134,6 +134,8 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
|
|
||||||
self._last_response_time = time()
|
self._last_response_time = time()
|
||||||
self._response_timeout_time = 10
|
self._response_timeout_time = 10
|
||||||
|
self._recreate_network_manager_time = 30 # If we have no connection, re-create network manager every 30 sec.
|
||||||
|
self._recreate_network_manager_count = 1
|
||||||
self._not_authenticated_message = None
|
self._not_authenticated_message = None
|
||||||
|
|
||||||
self._last_command = ""
|
self._last_command = ""
|
||||||
|
@ -227,6 +229,16 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
|
|
||||||
## Request data from the connected device.
|
## Request data from the connected device.
|
||||||
def _update(self):
|
def _update(self):
|
||||||
|
# Connection is in timeout, check if we need to re-start the connection.
|
||||||
|
# Sometimes the qNetwork manager incorrectly reports the network status on Mac & Windows.
|
||||||
|
# Re-creating the QNetworkManager seems to fix this issue.
|
||||||
|
if self._last_response_time and self._connection_state_before_timeout:
|
||||||
|
if time() - self._last_response_time > self._recreate_network_manager_time * self._recreate_network_manager_count:
|
||||||
|
self._recreate_network_manager_count += 1
|
||||||
|
Logger.log("d", "Timeout lasted over 30 seconds, re-checking connection.")
|
||||||
|
self._createNetworkManager()
|
||||||
|
return
|
||||||
|
|
||||||
# Check if we have an connection in the first place.
|
# Check if we have an connection in the first place.
|
||||||
if not self._manager.networkAccessible():
|
if not self._manager.networkAccessible():
|
||||||
if not self._connection_state_before_timeout:
|
if not self._connection_state_before_timeout:
|
||||||
|
@ -246,6 +258,8 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
pass # The disconnection can fail on mac in some cases. Ignore that.
|
pass # The disconnection can fail on mac in some cases. Ignore that.
|
||||||
self._progress_message.hide()
|
self._progress_message.hide()
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
self._recreate_network_manager_count = 1
|
||||||
|
|
||||||
# Check that we aren't in a timeout state
|
# Check that we aren't in a timeout state
|
||||||
if self._last_response_time and not self._connection_state_before_timeout:
|
if self._last_response_time and not self._connection_state_before_timeout:
|
||||||
|
@ -282,6 +296,17 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
print_job_request = QNetworkRequest(url)
|
print_job_request = QNetworkRequest(url)
|
||||||
self._manager.get(print_job_request)
|
self._manager.get(print_job_request)
|
||||||
|
|
||||||
|
def _createNetworkManager(self):
|
||||||
|
if self._manager:
|
||||||
|
self._manager.finished.disconnect(self._onFinished)
|
||||||
|
self._manager.networkAccessibleChanged.disconnect(self._onNetworkAccesibleChanged)
|
||||||
|
self._manager.authenticationRequired.disconnect(self._onAuthenticationRequired)
|
||||||
|
|
||||||
|
self._manager = QNetworkAccessManager()
|
||||||
|
self._manager.finished.connect(self._onFinished)
|
||||||
|
self._manager.authenticationRequired.connect(self._onAuthenticationRequired)
|
||||||
|
self._manager.networkAccessibleChanged.connect(self._onNetworkAccesibleChanged) # for debug purposes
|
||||||
|
|
||||||
## Convenience function that gets information from the received json data and converts it to the right internal
|
## Convenience function that gets information from the received json data and converts it to the right internal
|
||||||
# values / variables
|
# values / variables
|
||||||
def _spliceJSONData(self):
|
def _spliceJSONData(self):
|
||||||
|
@ -376,15 +401,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.close() # Ensure that previous connection (if any) is killed.
|
self.close() # Ensure that previous connection (if any) is killed.
|
||||||
|
|
||||||
if self._manager:
|
self._createNetworkManager()
|
||||||
self._manager.finished.disconnect(self._onFinished)
|
|
||||||
self._manager.networkAccessibleChanged.disconnect(self._onNetworkAccesibleChanged)
|
|
||||||
self._manager.authenticationRequired.disconnect(self._onAuthenticationRequired)
|
|
||||||
|
|
||||||
self._manager = QNetworkAccessManager()
|
|
||||||
self._manager.finished.connect(self._onFinished)
|
|
||||||
self._manager.authenticationRequired.connect(self._onAuthenticationRequired)
|
|
||||||
self._manager.networkAccessibleChanged.connect(self._onNetworkAccesibleChanged) # for debug purposes
|
|
||||||
|
|
||||||
self.setConnectionState(ConnectionState.connecting)
|
self.setConnectionState(ConnectionState.connecting)
|
||||||
self._update() # Manually trigger the first update, as we don't want to wait a few secs before it starts.
|
self._update() # Manually trigger the first update, as we don't want to wait a few secs before it starts.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue