Don't change metadata if there is no global stack

We'll miss that status update then, but the next time Cura starts it'll update the printer status anyway.

Found during testing of CURA-8591.
This commit is contained in:
Ghostkeeper 2022-01-05 17:15:38 +01:00
parent c8ed3634ed
commit ec5bb444c0
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -1,4 +1,4 @@
# Copyright (c) 2021 Ultimaker B.V.
# Copyright (c) 2022 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from enum import IntEnum
@ -137,7 +137,11 @@ class PrinterOutputDevice(QObject, OutputDevice):
"""
if self.connectionState != connection_state:
self._connection_state = connection_state
cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack().setMetaDataEntry("is_online", self.isConnected())
application = cura.CuraApplication.CuraApplication.getInstance()
if application is not None: # Might happen during the closing of Cura or in a test.
global_stack = application.getGlobalContainerStack()
if global_stack is not None:
global_stack.setMetaDataEntry("is_online", self.isConnected())
self.connectionStateChanged.emit(self._id)
@pyqtProperty(int, constant = True)