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

Improve plugin load/install failure message

In case Python or C plugins are disabled install/load failed silently.
Notify the user that we can't load them because profanity was built
without support for plugins.
This commit is contained in:
Michael Vetter 2019-06-07 11:30:46 +02:00
parent c03f936390
commit cc697de051
3 changed files with 31 additions and 16 deletions

View File

@ -6904,12 +6904,14 @@ cmd_plugins_load(ProfWin *window, const char *const command, gchar **args)
return TRUE; return TRUE;
} }
gboolean res = plugins_load(args[1]); GString* error_message = g_string_new(NULL);
gboolean res = plugins_load(args[1], error_message);
if (res) { if (res) {
cons_show("Loaded plugin: %s", args[1]); cons_show("Loaded plugin: %s", args[1]);
} else { } else {
cons_show("Failed to load plugin: %s", args[1]); cons_show("Failed to load plugin: %s. %s", args[1], error_message->str);
} }
g_string_free(error_message, TRUE);
return TRUE; return TRUE;
} }
@ -6946,12 +6948,14 @@ cmd_plugins_reload(ProfWin *window, const char *const command, gchar **args)
return TRUE; return TRUE;
} }
gboolean res = plugins_reload(args[1]); GString* error_message = g_string_new(NULL);
gboolean res = plugins_reload(args[1], error_message);
if (res) { if (res) {
cons_show("Reloaded plugin: %s", args[1]); cons_show("Reloaded plugin: %s", args[1]);
} else { } else {
cons_show("Failed to reload plugin: %s", args[1]); cons_show("Failed to reload plugin: %s, %s", args[1], error_message);
} }
g_string_free(error_message, TRUE);
return TRUE; return TRUE;
} }

View File

@ -208,7 +208,7 @@ plugins_install(const char *const plugin_name, const char *const filename, GStri
g_string_free(target_path, TRUE); g_string_free(target_path, TRUE);
if (result) { if (result) {
result = plugins_load(plugin_name); result = plugins_load(plugin_name, error_message);
} }
return result; return result;
} }
@ -219,11 +219,14 @@ plugins_load_all(void)
GSList *plugins = plugins_unloaded_list(); GSList *plugins = plugins_unloaded_list();
GSList *loaded = NULL; GSList *loaded = NULL;
GSList *curr = plugins; GSList *curr = plugins;
GString *error_message = NULL;
while (curr) { while (curr) {
if (plugins_load(curr->data)) { error_message = g_string_new(NULL);
if (plugins_load(curr->data, error_message)) {
loaded = g_slist_append(loaded, strdup(curr->data)); loaded = g_slist_append(loaded, strdup(curr->data));
} }
curr = g_slist_next(curr); curr = g_slist_next(curr);
g_string_free(error_message, TRUE);
} }
g_slist_free_full(plugins, g_free); g_slist_free_full(plugins, g_free);
@ -231,7 +234,7 @@ plugins_load_all(void)
} }
gboolean gboolean
plugins_load(const char *const name) plugins_load(const char *const name, GString *error_message)
{ {
ProfPlugin *plugin = g_hash_table_lookup(plugins, name); ProfPlugin *plugin = g_hash_table_lookup(plugins, name);
if (plugin) { if (plugin) {
@ -239,16 +242,21 @@ plugins_load(const char *const name)
return FALSE; return FALSE;
} }
#ifdef HAVE_PYTHON
if (g_str_has_suffix(name, ".py")) { if (g_str_has_suffix(name, ".py")) {
#ifdef HAVE_PYTHON
plugin = python_plugin_create(name); plugin = python_plugin_create(name);
} #else
g_string_assign(error_message, "Python plugins support is disabled.");
#endif #endif
#ifdef HAVE_C }
if (g_str_has_suffix(name, ".so")) { if (g_str_has_suffix(name, ".so")) {
#ifdef HAVE_C
plugin = c_plugin_create(name); plugin = c_plugin_create(name);
} #else
g_string_assign(error_message, "C plugins support is disabled.");
#endif #endif
}
if (plugin) { if (plugin) {
g_hash_table_insert(plugins, strdup(name), plugin); g_hash_table_insert(plugins, strdup(name), plugin);
if (connection_get_status() == JABBER_CONNECTED) { if (connection_get_status() == JABBER_CONNECTED) {
@ -336,9 +344,12 @@ plugins_reload_all(void)
} }
g_list_free(plugin_names); g_list_free(plugin_names);
GString *error_message = NULL;
curr = plugin_names_dup; curr = plugin_names_dup;
while (curr) { while (curr) {
plugins_reload(curr->data); error_message = g_string_new(NULL);
plugins_reload(curr->data, error_message);
g_string_free(error_message, TRUE);
curr = g_list_next(curr); curr = g_list_next(curr);
} }
@ -346,11 +357,11 @@ plugins_reload_all(void)
} }
gboolean gboolean
plugins_reload(const char *const name) plugins_reload(const char *const name, GString *error_message)
{ {
gboolean res = plugins_unload(name); gboolean res = plugins_unload(name);
if (res) { if (res) {
res = plugins_load(name); res = plugins_load(name, error_message);
} }
return res; return res;

View File

@ -118,11 +118,11 @@ gboolean plugins_install(const char *const plugin_name, const char *const filena
gboolean plugins_uninstall(const char *const plugin_name); gboolean plugins_uninstall(const char *const plugin_name);
gboolean plugins_update(const char *const plugin_name, const char *const filename, GString * error_message); gboolean plugins_update(const char *const plugin_name, const char *const filename, GString * error_message);
PluginsInstallResult* plugins_install_all(const char *const path); PluginsInstallResult* plugins_install_all(const char *const path);
gboolean plugins_load(const char *const name); gboolean plugins_load(const char *const name, GString *error_message);
GSList* plugins_load_all(void); GSList* plugins_load_all(void);
gboolean plugins_unload(const char *const name); gboolean plugins_unload(const char *const name);
gboolean plugins_unload_all(void); gboolean plugins_unload_all(void);
gboolean plugins_reload(const char *const name); gboolean plugins_reload(const char *const name, GString *error_message);
void plugins_reload_all(void); void plugins_reload_all(void);
void plugins_on_start(void); void plugins_on_start(void);