[gnome-software/wip/hughsie/show-event-on-file-not-supported] Show an in-application notification when a local file or URI is not supported
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/show-event-on-file-not-supported] Show an in-application notification when a local file or URI is not supported
- Date: Tue, 30 Jan 2018 14:24:05 +0000 (UTC)
commit b11c0bd600f434106f04ee6c66acfbdf1e42aa2d
Author: Richard Hughes <richard hughsie com>
Date: Tue Jan 30 14:02:38 2018 +0000
Show an in-application notification when a local file or URI is not supported
This can be reproduced doing: xdg-open appstream://this.is.invalid
Fixes https://gitlab.gnome.org/GNOME/gnome-software/issues/236
lib/gs-plugin-loader.c | 75 ++++++++++++++++++++++++++++++++++----------------
src/gs-shell.c | 4 +++
2 files changed, 56 insertions(+), 23 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 50b8c5e6..f52d170e 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -338,15 +338,45 @@ gs_plugin_loader_add_event (GsPluginLoader *plugin_loader, GsPluginEvent *event)
g_idle_add (gs_plugin_loader_notify_idle_cb, plugin_loader);
}
+static GsPluginEvent *
+gs_plugin_job_to_failed_event (GsPluginJob *plugin_job, const GError *error)
+{
+ GsPluginEvent *event;
+ GsPluginFailureFlags flags;
+
+ /* invalid */
+ if (error == NULL)
+ return NULL;
+ if (error->domain != GS_PLUGIN_ERROR) {
+ g_critical ("not GsPlugin error %s:%i: %s",
+ g_quark_to_string (error->domain),
+ error->code,
+ error->message);
+ return NULL;
+ }
+
+ /* only add this if the caller is interactive */
+ flags = gs_plugin_job_get_failure_flags (plugin_job);
+ if ((flags & GS_PLUGIN_FAILURE_FLAGS_USE_EVENTS) == 0)
+ return NULL;
+
+ /* create plugin event */
+ event = gs_plugin_event_new ();
+ gs_plugin_event_set_error (event, error);
+ gs_plugin_event_set_action (event, gs_plugin_job_get_action (plugin_job));
+ if (gs_plugin_job_get_app (plugin_job) != NULL)
+ gs_plugin_event_set_app (event, gs_plugin_job_get_app (plugin_job));
+ gs_plugin_event_add_flag (event, GS_PLUGIN_EVENT_FLAG_WARNING);
+ return event;
+}
+
/* if the error is worthy of notifying then create a plugin event */
static void
gs_plugin_loader_create_event_from_error (GsPluginLoader *plugin_loader,
- GsPluginAction action,
+ GsPluginJob *plugin_job,
GsPlugin *plugin,
- GsApp *app,
const GError *error)
{
- guint i;
g_autoptr(GsApp) origin = NULL;
g_auto(GStrv) split = NULL;
g_autoptr(GsPluginEvent) event = NULL;
@@ -364,16 +394,13 @@ gs_plugin_loader_create_event_from_error (GsPluginLoader *plugin_loader,
}
/* create plugin event */
- event = gs_plugin_event_new ();
- if (app != NULL)
- gs_plugin_event_set_app (event, app);
- gs_plugin_event_set_error (event, error);
- gs_plugin_event_set_action (event, action);
- gs_plugin_event_add_flag (event, GS_PLUGIN_EVENT_FLAG_WARNING);
+ event = gs_plugin_job_to_failed_event (plugin_job, error);
+ if (event == NULL)
+ return;
/* can we find a unique ID */
split = g_strsplit_set (error->message, "[]: ", -1);
- for (i = 0; split[i] != NULL; i++) {
+ for (guint i = 0; split[i] != NULL; i++) {
if (as_utils_unique_id_valid (split[i])) {
origin = gs_plugin_cache_lookup (plugin, split[i]);
if (origin != NULL) {
@@ -425,16 +452,13 @@ gs_plugin_error_handle_failure (GsPluginLoaderHelper *helper,
}
/* create event which is handled by the GsShell */
- flags = gs_plugin_job_get_failure_flags (helper->plugin_job);
- if (flags & GS_PLUGIN_FAILURE_FLAGS_USE_EVENTS) {
- gs_plugin_loader_create_event_from_error (helper->plugin_loader,
- gs_plugin_job_get_action (helper->plugin_job),
- plugin,
- gs_plugin_job_get_app (helper->plugin_job),
- error_local);
- }
+ gs_plugin_loader_create_event_from_error (helper->plugin_loader,
+ helper->plugin_job,
+ plugin,
+ error_local);
/* abort early to allow main thread to process */
+ flags = gs_plugin_job_get_failure_flags (helper->plugin_job);
if (gs_plugin_loader_is_error_fatal (flags, error_local)) {
if (error != NULL)
*error = g_error_copy (error_local);
@@ -3378,11 +3402,16 @@ gs_plugin_loader_process_thread_cb (GTask *task,
action == GS_PLUGIN_ACTION_FILE_TO_APP) {
if (gs_app_list_length (list) == 0) {
g_autofree gchar *str = gs_plugin_job_to_string (helper->plugin_job);
- g_task_return_new_error (task,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_NOT_SUPPORTED,
- "no application was created for %s",
- str);
+ g_autoptr(GError) error_local = NULL;
+ g_autoptr(GsPluginEvent) event = NULL;
+ g_set_error (&error_local,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_NOT_SUPPORTED,
+ "no application was created for %s", str);
+ event = gs_plugin_job_to_failed_event (helper->plugin_job, error_local);
+ if (event != NULL)
+ gs_plugin_loader_add_event (plugin_loader, event);
+ g_task_return_error (task, g_steal_pointer (&error_local));
return;
}
if (gs_app_list_length (list) > 1) {
diff --git a/src/gs-shell.c b/src/gs-shell.c
index ae9eab5f..eb76b2a0 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -1469,6 +1469,10 @@ gs_shell_show_event_file_to_app (GsShell *shell, GsPluginEvent *event)
g_autoptr(GString) str = g_string_new (NULL);
switch (error->code) {
+ case GS_PLUGIN_ERROR_NOT_SUPPORTED:
+ /* TRANSLATORS: failure text for the in-app notification */
+ g_string_append (str, _("Unable to open – not supported"));
+ break;
case GS_PLUGIN_ERROR_NO_SECURITY:
/* TRANSLATORS: failure text for the in-app notification */
g_string_append (str, _("Failed to install file: "
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]