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

Add /plugin reload command

This commit is contained in:
James Booth 2016-07-10 01:07:41 +01:00
parent 44862fe842
commit 448bef247b
5 changed files with 55 additions and 2 deletions

View File

@ -186,6 +186,7 @@ static Autocomplete autoping_ac;
static Autocomplete plugins_ac; static Autocomplete plugins_ac;
static Autocomplete plugins_load_ac; static Autocomplete plugins_load_ac;
static Autocomplete plugins_unload_ac; static Autocomplete plugins_unload_ac;
static Autocomplete plugins_reload_ac;
static Autocomplete sendfile_ac; static Autocomplete sendfile_ac;
static Autocomplete blocked_ac; static Autocomplete blocked_ac;
static Autocomplete tray_ac; static Autocomplete tray_ac;
@ -486,6 +487,7 @@ cmd_ac_init(void)
theme_load_ac = NULL; theme_load_ac = NULL;
plugins_load_ac = NULL; plugins_load_ac = NULL;
plugins_unload_ac = NULL; plugins_unload_ac = NULL;
plugins_reload_ac = NULL;
who_roster_ac = autocomplete_new(); who_roster_ac = autocomplete_new();
autocomplete_add(who_roster_ac, "chat"); autocomplete_add(who_roster_ac, "chat");
@ -705,6 +707,7 @@ cmd_ac_init(void)
plugins_ac = autocomplete_new(); plugins_ac = autocomplete_new();
autocomplete_add(plugins_ac, "load"); autocomplete_add(plugins_ac, "load");
autocomplete_add(plugins_ac, "unload"); autocomplete_add(plugins_ac, "unload");
autocomplete_add(plugins_ac, "reload");
sendfile_ac = autocomplete_new(); sendfile_ac = autocomplete_new();
@ -924,6 +927,10 @@ cmd_ac_reset(ProfWin *window)
autocomplete_free(plugins_unload_ac); autocomplete_free(plugins_unload_ac);
plugins_unload_ac = NULL; plugins_unload_ac = NULL;
} }
if (plugins_reload_ac) {
autocomplete_free(plugins_reload_ac);
plugins_reload_ac = NULL;
}
autocomplete_reset(account_ac); autocomplete_reset(account_ac);
autocomplete_reset(account_set_ac); autocomplete_reset(account_set_ac);
autocomplete_reset(account_clear_ac); autocomplete_reset(account_clear_ac);
@ -1103,6 +1110,7 @@ cmd_ac_uninit(void)
autocomplete_free(plugins_ac); autocomplete_free(plugins_ac);
autocomplete_free(plugins_load_ac); autocomplete_free(plugins_load_ac);
autocomplete_free(plugins_unload_ac); autocomplete_free(plugins_unload_ac);
autocomplete_free(plugins_reload_ac);
autocomplete_free(sendfile_ac); autocomplete_free(sendfile_ac);
autocomplete_free(blocked_ac); autocomplete_free(blocked_ac);
autocomplete_free(tray_ac); autocomplete_free(tray_ac);
@ -1899,6 +1907,23 @@ _plugins_autocomplete(ProfWin *window, const char *const input)
} }
} }
if (strncmp(input, "/plugins reload ", 16) == 0) {
if (plugins_reload_ac == NULL) {
plugins_reload_ac = autocomplete_new();
GList *plugins = plugins_loaded_list();
GList *curr = plugins;
while (curr) {
autocomplete_add(plugins_reload_ac, curr->data);
curr = g_list_next(curr);
}
g_list_free(plugins);
}
result = autocomplete_param_with_ac(input, "/plugins reload", plugins_reload_ac, TRUE);
if (result) {
return result;
}
}
if (strncmp(input, "/plugins unload ", 16) == 0) { if (strncmp(input, "/plugins unload ", 16) == 0) {
if (plugins_unload_ac == NULL) { if (plugins_unload_ac == NULL) {
plugins_unload_ac = autocomplete_new(); plugins_unload_ac = autocomplete_new();

View File

@ -1980,15 +1980,18 @@ static struct cmd_t command_defs[] =
CMD_SYN( CMD_SYN(
"/plugins", "/plugins",
"/plugins unload <plugin>", "/plugins unload <plugin>",
"/plugins load <plugin>") "/plugins load <plugin>",
"/plugins reload <plugin>")
CMD_DESC( CMD_DESC(
"Manage plugins. Passing no arguments lists currently loaded plugins.") "Manage plugins. Passing no arguments lists currently loaded plugins.")
CMD_ARGS( CMD_ARGS(
{ "load <plugin>", "Load a plugin." }, { "load <plugin>", "Load a plugin." },
{ "reload <plugin>", "Reload a plugin." },
{ "unload <plugin>", "Unload a plugin." }) { "unload <plugin>", "Unload a plugin." })
CMD_EXAMPLES( CMD_EXAMPLES(
"/plugin load browser.py", "/plugin load browser.py",
"/plugin unload say.py") "/plugin unload say.py",
"/plugin reload wikipedia.py")
}, },
{ "/prefs", { "/prefs",

View File

@ -6050,6 +6050,19 @@ cmd_plugins(ProfWin *window, const char *const command, gchar **args)
cons_show("Failed to unload plugin: %s", args[1]); cons_show("Failed to unload plugin: %s", args[1]);
} }
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]);
} else {
cons_show("Failed to reload plugin: %s", args[1]);
}
return TRUE; return TRUE;
} else { } else {
GList *plugins = plugins_loaded_list(); GList *plugins = plugins_loaded_list();

View File

@ -187,6 +187,17 @@ plugins_unload(const char *const name)
return TRUE; return TRUE;
} }
gboolean
plugins_reload(const char *const name)
{
gboolean res = plugins_unload(name);
if (res) {
res = plugins_load(name);
}
return res;
}
static gchar* static gchar*
_get_plugins_dir(void) _get_plugins_dir(void)
{ {

View File

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