1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Allow reloading all plugins with /plugin reload

This commit is contained in:
James Booth 2016-07-10 01:28:30 +01:00
parent 448bef247b
commit 9a0111c10a
4 changed files with 33 additions and 10 deletions

View File

@ -1981,13 +1981,13 @@ static struct cmd_t command_defs[] =
"/plugins",
"/plugins unload <plugin>",
"/plugins load <plugin>",
"/plugins reload <plugin>")
"/plugins reload [<plugin>]")
CMD_DESC(
"Manage plugins. Passing no arguments lists currently loaded plugins.")
CMD_ARGS(
{ "load <plugin>", "Load a plugin." },
{ "reload <plugin>", "Reload a plugin." },
{ "unload <plugin>", "Unload a plugin." })
{ "unload <plugin>", "Unload a plugin." },
{ "reload [<plugin>]", "Reload a plugin, passing no argument will reload all plugins" })
CMD_EXAMPLES(
"/plugin load browser.py",
"/plugin unload say.py",

View File

@ -6053,14 +6053,15 @@ cmd_plugins(ProfWin *window, const char *const command, gchar **args)
return TRUE;
} else if (g_strcmp0(args[0], "reload") == 0) {
if (args[1] == NULL) {
cons_bad_cmd_usage(command);
return TRUE;
}
gboolean res = plugins_reload(args[1]);
if (res) {
cons_show("Reloaded plugin: %s", args[1]);
plugins_reload_all();
cons_show("Reloaded all plugins");
} else {
cons_show("Failed to reload plugin: %s", args[1]);
gboolean res = plugins_reload(args[1]);
if (res) {
cons_show("Reloaded plugin: %s", args[1]);
} else {
cons_show("Failed to reload plugin: %s", args[1]);
}
}
return TRUE;

View File

@ -187,6 +187,27 @@ plugins_unload(const char *const name)
return TRUE;
}
void
plugins_reload_all(void)
{
GList *plugin_names = g_hash_table_get_keys(plugins);
GList *plugin_names_dup = NULL;
GList *curr = plugin_names;
while (curr) {
plugin_names_dup = g_list_append(plugin_names_dup, strdup(curr->data));
curr = g_list_next(curr);
}
g_list_free(plugin_names);
curr = plugin_names_dup;
while (curr) {
plugins_reload(curr->data);
curr = g_list_next(curr);
}
g_list_free_full(plugin_names_dup, free);
}
gboolean
plugins_reload(const char *const name)
{

View File

@ -108,6 +108,7 @@ void plugins_shutdown(void);
gboolean plugins_load(const char *const name);
gboolean plugins_unload(const char *const name);
gboolean plugins_reload(const char *const name);
void plugins_reload_all(void);
void plugins_on_start(void);
void plugins_on_shutdown(void);