Browse Source

Introduced a Manager to centralize plugin/package management

Should have done this from the start.
Will move other relevant scattered functions to this type.
For now it checks if the restart banner needs to show.
Taking into account that a user can toggle between enable
and disable without an actual restart. Even with multiple
plugins.

Contributes to: CURA-8587
Jelle Spijker 3 years ago
parent
commit
6c976bc9b0

+ 32 - 0
plugins/Marketplace/Manager.py

@@ -0,0 +1,32 @@
+#  Copyright (c) 2021 Ultimaker B.V.
+#  Cura is released under the terms of the LGPLv3 or higher.
+from typing import Optional
+
+from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal
+
+from cura.CuraApplication import CuraApplication
+from UM.PluginRegistry import PluginRegistry
+
+class Manager(QObject):
+    def __init__(self, parent: Optional[QObject] = None):
+        super().__init__(parent = parent)
+        self._manager: "CuraPackageManager" = CuraApplication.getInstance().getPackageManager()
+        self._plugin_registry: PluginRegistry = CuraApplication.getInstance().getPluginRegistry()
+
+        self._manager.installedPackagesChanged.connect(self.checkIfRestartNeeded)
+        self._plugin_registry.hasPluginsEnabledOrDisabledChanged.connect(self.checkIfRestartNeeded)
+
+        self._restart_needed = False
+
+    def checkIfRestartNeeded(self):
+        if self._manager.hasPackagesToRemoveOrInstall or len(self._plugin_registry.getCurrentSessionActivationChangedPlugins()) > 0:
+            self._restart_needed = True
+        else:
+            self._restart_needed = False
+        self.showRestartNotificationChanged.emit()
+
+    showRestartNotificationChanged = pyqtSignal()
+
+    @pyqtProperty(bool, notify = showRestartNotificationChanged)
+    def showRestartNotification(self) -> bool:
+        return self._restart_needed

+ 3 - 1
plugins/Marketplace/Marketplace.py

@@ -13,6 +13,7 @@ from UM.PluginRegistry import PluginRegistry  # To find out where we are stored
 
 from .RemotePackageList import RemotePackageList  # To register this type with QML.
 from .LocalPackageList import LocalPackageList  # To register this type with QML.
+from .Manager import Manager  # To register this type with QML.
 
 if TYPE_CHECKING:
     from PyQt5.QtCore import QObject
@@ -30,6 +31,7 @@ class Marketplace(Extension):
 
         qmlRegisterType(RemotePackageList, "Marketplace", 1, 0, "RemotePackageList")
         qmlRegisterType(LocalPackageList, "Marketplace", 1, 0, "LocalPackageList")
+        qmlRegisterType(Manager, "Marketplace", 1, 0, "Manager")
 
     @pyqtSlot()
     def show(self) -> None:
@@ -44,7 +46,7 @@ class Marketplace(Extension):
             if plugin_path is None:
                 plugin_path = os.path.dirname(__file__)
             path = os.path.join(plugin_path, "resources", "qml", "Marketplace.qml")
-            self._window = CuraApplication.getInstance().createQmlComponent(path, {"plugin_registry": self.plugin_registry})
+            self._window = CuraApplication.getInstance().createQmlComponent(path, {})
         if self._window is None:  # Still None? Failed to load the QML then.
             return
         self._window.show()

+ 0 - 2
plugins/Marketplace/PackageModel.py

@@ -300,8 +300,6 @@ class PackageModel(QObject):
         """The state of the manage Enable Button of this package"""
         if self._is_enabling == ManageState.PROCESSING:
             return "busy"
-        if self._is_recently_enabled:
-            return "confirmed"
         if self._package_type == "material" or not self._is_installed:
             return "hidden"
         if self._is_installed and self._is_active:

+ 3 - 1
plugins/Marketplace/resources/qml/Marketplace.qml

@@ -8,11 +8,13 @@ import QtQuick.Window 2.2
 
 import UM 1.2 as UM
 import Cura 1.6 as Cura
+import Marketplace 1.0 as Marketplace
 
 Window
 {
     id: marketplaceDialog
     property variant catalog: UM.I18nCatalog { name: "cura" }
+    property variant manager: Marketplace.Manager { }
 
     signal searchStringChanged(string new_search)
 
@@ -232,7 +234,7 @@ Window
     {
         height: quitButton.height + 2 * UM.Theme.getSize("default_margin").width
         color: UM.Theme.getColor("primary")
-        visible: CuraApplication.getPackageManager().hasPackagesToRemoveOrInstall || plugin_registry.hasPluginsEnabledOrDisabled
+        visible: manager.showRestartNotification
         anchors
         {
             left: parent.left