Don't cache PluginRegistry instance

Several reasons:
* It's bad style, making it harder to test with mocked PluginRegistry since all sorts of objects have copies of the un-mocked object in their fields.
* It's causing errors in this case when checkIfRestartNeeded is called before show().

Fixes Sentry issue CURA-3P6.
This commit is contained in:
Ghostkeeper 2022-06-22 11:52:13 +02:00
parent a17b68b17d
commit ac67dcc045
No known key found for this signature in database
GPG Key ID: D2A8871EE34EC59A

View File

@ -22,7 +22,6 @@ class Marketplace(Extension, QObject):
QObject.__init__(self, parent) QObject.__init__(self, parent)
Extension.__init__(self) Extension.__init__(self)
self._window: Optional["QObject"] = None # If the window has been loaded yet, it'll be cached in here. self._window: Optional["QObject"] = None # If the window has been loaded yet, it'll be cached in here.
self._plugin_registry: Optional[PluginRegistry] = None
self._package_manager = CuraApplication.getInstance().getPackageManager() self._package_manager = CuraApplication.getInstance().getPackageManager()
self._material_package_list: Optional[RemotePackageList] = None self._material_package_list: Optional[RemotePackageList] = None
@ -81,9 +80,9 @@ class Marketplace(Extension, QObject):
If the window hadn't been loaded yet into Qt, it will be created lazily. If the window hadn't been loaded yet into Qt, it will be created lazily.
""" """
if self._window is None: if self._window is None:
self._plugin_registry = PluginRegistry.getInstance() plugin_registry = PluginRegistry.getInstance()
self._plugin_registry.pluginsEnabledOrDisabledChanged.connect(self.checkIfRestartNeeded) plugin_registry.pluginsEnabledOrDisabledChanged.connect(self.checkIfRestartNeeded)
plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId()) plugin_path = plugin_registry.getPluginPath(self.getPluginId())
if plugin_path is None: if plugin_path is None:
plugin_path = os.path.dirname(__file__) plugin_path = os.path.dirname(__file__)
path = os.path.join(plugin_path, "resources", "qml", "Marketplace.qml") path = os.path.join(plugin_path, "resources", "qml", "Marketplace.qml")
@ -108,7 +107,7 @@ class Marketplace(Extension, QObject):
return return
if self._package_manager.hasPackagesToRemoveOrInstall or \ if self._package_manager.hasPackagesToRemoveOrInstall or \
cast(PluginRegistry, self._plugin_registry).getCurrentSessionActivationChangedPlugins(): PluginRegistry.getInstance().getCurrentSessionActivationChangedPlugins():
self._restart_needed = True self._restart_needed = True
else: else:
self._restart_needed = False self._restart_needed = False
@ -116,7 +115,7 @@ class Marketplace(Extension, QObject):
showRestartNotificationChanged = pyqtSignal() showRestartNotificationChanged = pyqtSignal()
@pyqtProperty(bool, notify=showRestartNotificationChanged) @pyqtProperty(bool, notify = showRestartNotificationChanged)
def showRestartNotification(self) -> bool: def showRestartNotification(self) -> bool:
return self._restart_needed return self._restart_needed