From 18e14aa41284aa1745ccf8b788d23015cda668b1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?=
Date: Thu, 30 Mar 2017 14:08:47 +0200
Subject: [PATCH] Support "disabling unrecommended" for bundled plugins
* Extended plugin metadata by new property, only evaluated for bundled
plugins.
* Adjusted plugin manager to evaluate new metadata and add
confirmation dialog with details when attempting to disable such
a plugin.
---
src/octoprint/plugin/core.py | 16 +++++++++++++
.../plugins/pluginmanager/__init__.py | 1 +
.../pluginmanager/static/js/pluginmanager.js | 23 ++++++++++++++++---
3 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py
index 62da7633..f8a168f5 100644
--- a/src/octoprint/plugin/core.py
+++ b/src/octoprint/plugin/core.py
@@ -71,6 +71,9 @@ class PluginInfo(object):
attr_description = '__plugin_description__'
""" Module attribute from which to retrieve the plugin's description. """
+ attr_disabling_discouraged = '__plugin_disabling_discouraged__'
+ """ Module attribute from which to retrieve the reason why disabling the plugin is discouraged. Only effective if ``self.bundled`` is True. """
+
attr_version = '__plugin_version__'
""" Module attribute from which to retrieve the plugin's version. """
@@ -294,6 +297,19 @@ class PluginInfo(object):
"""
return self._get_instance_attribute(self.__class__.attr_description, default=self._description)
+ @property
+ def disabling_discouraged(self):
+ """
+ Reason why disabling of this plugin is discouraged. Only evaluated for bundled plugins! Will be taken from
+ the disabling_discouraged attribute of the plugin module as defined in :attr:`attr_disabling_discouraged` if
+ available. False if unset or plugin not bundled.
+
+ Returns:
+ str or None: Reason why disabling this plugin is discouraged (only for bundled plugins)
+ """
+ return self._get_instance_attribute(self.__class__.attr_disabling_discouraged, default=False) if self.bundled \
+ else False
+
@property
def version(self):
"""
diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py
index 90605517..bad8392f 100644
--- a/src/octoprint/plugins/pluginmanager/__init__.py
+++ b/src/octoprint/plugins/pluginmanager/__init__.py
@@ -706,6 +706,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
key=plugin.key,
name=plugin.name,
description=plugin.description,
+ disabling_discouraged=gettext(plugin.disabling_discouraged) if plugin.disabling_discouraged else False,
author=plugin.author,
version=plugin.version,
url=plugin.url,
diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js
index 173f31cd..2ca5b1f3 100644
--- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js
+++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js
@@ -360,9 +360,26 @@ $(function() {
.done(onSuccess)
.fail(onError);
} else {
- OctoPrint.plugins.pluginmanager.disable(data.key)
- .done(onSuccess)
- .fail(onError);
+ var perform = function() {
+ OctoPrint.plugins.pluginmanager.disable(data.key)
+ .done(onSuccess)
+ .fail(onError);
+ };
+
+ if (data.disabling_discouraged) {
+ var message = _.sprintf(gettext("You are about to disable \"%(name)s\"."), {name: data.name})
+ + "
" + data.disabling_discouraged;
+ showConfirmationDialog({
+ title: gettext("This is not recommended"),
+ message: message,
+ question: gettext("Do you still want to disable it?"),
+ cancel: gettext("Keep enabled"),
+ proceed: gettext("Disable anyway"),
+ onproceed: perform
+ })
+ } else {
+ perform();
+ }
}
};