Skip to content

Commit 0c0b493

Browse files
committed
fix(plugin_manager): call disable when plugin is disabled
this was missed in f9dcb56.
1 parent 7840510 commit 0c0b493

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

safeeyes/plugin_manager.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,31 @@ def init(self, context: Context, config: Config) -> None:
123123
for plugin in self.__plugins.values():
124124
plugin.init_plugin(context, config)
125125

126+
def reload(self, context: Context, config: Config) -> None:
127+
"""Reinitialize all the plugins with updated config."""
128+
# Load the plugins
129+
for plugin in config.get("plugins"):
130+
plugin_id = plugin["id"]
131+
if plugin_id in self.__plugins:
132+
self.__plugins[plugin_id].reload_config(plugin)
133+
else:
134+
try:
135+
loaded_plugin = LoadedPlugin(plugin)
136+
self.__plugins[loaded_plugin.id] = loaded_plugin
137+
except BaseException as e:
138+
traceback_wanted = (
139+
logging.getLogger().getEffectiveLevel() == logging.DEBUG
140+
)
141+
if traceback_wanted:
142+
import traceback
143+
144+
traceback.print_exc()
145+
logging.error("Error in loading the plugin %s: %s", plugin["id"], e)
146+
continue
147+
# Initialize the plugins
148+
for plugin in self.__plugins.values():
149+
plugin.init_plugin(context, config)
150+
126151
def needs_retry(self) -> bool:
127152
return self.get_retryable_error() is not None
128153

@@ -292,14 +317,17 @@ def __init__(self, plugin: dict) -> None:
292317
self._import_plugin()
293318

294319
def reload_config(self, plugin: dict) -> None:
295-
if self.enabled and not plugin["enabled"]:
296-
self.enabled = False
297-
if (
298-
not self.errored
299-
and self.module is not None
300-
and utility.has_method(self.module, "disable")
301-
):
302-
self.module.disable()
320+
if not plugin["enabled"]:
321+
if self.enabled:
322+
self.enabled = False
323+
if (
324+
not self.errored
325+
and self.module is not None
326+
and utility.has_method(self.module, "disable")
327+
):
328+
self.module.disable()
329+
logging.info("Successfully unloaded the plugin '%s'", plugin["id"])
330+
return
303331

304332
if not self.enabled and plugin["enabled"]:
305333
self.enabled = True

safeeyes/safeeyes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def restart(self, config, set_active=False):
471471
self.break_screen.initialize(config)
472472

473473
try:
474-
self.plugins_manager.init(self.context, self.config)
474+
self.plugins_manager.reload(self.context, self.config)
475475
except RequiredPluginException as e:
476476
self.show_required_plugin_dialog(e)
477477
return

0 commit comments

Comments
 (0)