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.
This commit is contained in:
Gina Häußge 2017-03-30 14:08:47 +02:00
parent c3ad1d3691
commit 18e14aa412
3 changed files with 37 additions and 3 deletions

View file

@ -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):
"""

View file

@ -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,

View file

@ -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})
+ "</p><p>" + 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();
}
}
};