[gnome-software] Fix launching applications by using the main thread only



commit 4079c99243b5d09906ce18fe4730a1186eea10fe
Author: Richard Hughes <richard hughsie com>
Date:   Fri Jan 15 15:33:49 2016 +0000

    Fix launching applications by using the main thread only
    
    Kalev, you were right all along. My mistake, apologies.

 src/gs-plugin.c                    |   54 ++++++++++++++++++++++++++++++++++++
 src/gs-plugin.h                    |    3 ++
 src/plugins/gs-plugin-epiphany.c   |   29 +------------------
 src/plugins/gs-plugin-packagekit.c |   29 +------------------
 4 files changed, 59 insertions(+), 56 deletions(-)
---
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 78763f3..b987e33 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -40,6 +40,7 @@
 #include "config.h"
 
 #include <glib.h>
+#include <gio/gdesktopappinfo.h>
 
 #include "gs-plugin.h"
 
@@ -322,6 +323,59 @@ gs_plugin_progress_update (GsPlugin *plugin, GsApp *app, guint percentage)
 }
 
 /**
+ * gs_plugin_app_launch_cb:
+ **/
+static gboolean
+gs_plugin_app_launch_cb (gpointer user_data)
+{
+       GAppInfo *appinfo = (GAppInfo *) user_data;
+       GdkDisplay *display;
+       g_autoptr(GAppLaunchContext) context = NULL;
+       g_autoptr(GError) error = NULL;
+
+       display = gdk_display_get_default ();
+       context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display));
+       if (!g_app_info_launch (appinfo, NULL, context, &error))
+               g_warning ("Failed to launch: %s", error->message);
+
+       return FALSE;
+}
+
+/**
+ * gs_plugin_app_launch:
+ **/
+gboolean
+gs_plugin_app_launch (GsPlugin *plugin, GsApp *app, GError **error)
+{
+       const gchar *desktop_id;
+       g_autoptr(GAppInfo) appinfo = NULL;
+
+       desktop_id = gs_app_get_id (app);
+       if (desktop_id == NULL) {
+               g_set_error (error,
+                            GS_PLUGIN_ERROR,
+                            GS_PLUGIN_ERROR_NOT_SUPPORTED,
+                            "no such desktop file: %s",
+                            desktop_id);
+               return FALSE;
+       }
+       appinfo = G_APP_INFO (g_desktop_app_info_new (desktop_id));
+       if (appinfo == NULL) {
+               g_set_error (error,
+                            GS_PLUGIN_ERROR,
+                            GS_PLUGIN_ERROR_NOT_SUPPORTED,
+                            "no such desktop file: %s",
+                            desktop_id);
+               return FALSE;
+       }
+       g_idle_add_full (G_PRIORITY_DEFAULT,
+                        gs_plugin_app_launch_cb,
+                        g_object_ref (appinfo),
+                        (GDestroyNotify) g_object_unref);
+       return TRUE;
+}
+
+/**
  * gs_plugin_updates_changed_cb:
  **/
 static gboolean
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index aa30144..126211d 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -185,6 +185,9 @@ void                 gs_plugin_status_update                (GsPlugin       *plugin,
 void            gs_plugin_progress_update              (GsPlugin       *plugin,
                                                         GsApp          *app,
                                                         guint           percentage);
+gboolean        gs_plugin_app_launch                   (GsPlugin       *plugin,
+                                                        GsApp          *app,
+                                                        GError         **error);
 void            gs_plugin_updates_changed              (GsPlugin       *plugin);
 const gchar    *gs_plugin_status_to_string             (GsPluginStatus  status);
 gboolean        gs_plugin_add_search                   (GsPlugin       *plugin,
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
index 685581f..b0348d9 100644
--- a/src/plugins/gs-plugin-epiphany.c
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -25,7 +25,6 @@
 #include <string.h>
 
 #include <glib/gi18n.h>
-#include <gio/gdesktopappinfo.h>
 #include <libsoup/soup.h>
 
 #include <gs-plugin.h>
@@ -313,34 +312,8 @@ gs_plugin_launch (GsPlugin *plugin,
                  GCancellable *cancellable,
                  GError **error)
 {
-       GdkDisplay *display;
-       const gchar *desktop_id;
-       g_autoptr(GAppInfo) appinfo = NULL;
-       g_autoptr(GAppLaunchContext) context = NULL;
-
        /* only process this app if was created by this plugin */
        if (g_strcmp0 (gs_app_get_management_plugin (app), "Epiphany") != 0)
                return TRUE;
-
-       desktop_id = gs_app_get_id (app);
-       if (desktop_id == NULL) {
-               g_set_error (error,
-                            GS_PLUGIN_ERROR,
-                            GS_PLUGIN_ERROR_NOT_SUPPORTED,
-                            "no such desktop file: %s",
-                            desktop_id);
-               return FALSE;
-       }
-       appinfo = G_APP_INFO (g_desktop_app_info_new (desktop_id));
-       if (appinfo == NULL) {
-               g_set_error (error,
-                            GS_PLUGIN_ERROR,
-                            GS_PLUGIN_ERROR_NOT_SUPPORTED,
-                            "no such desktop file: %s",
-                            desktop_id);
-               return FALSE;
-       }
-       display = gdk_display_get_default ();
-       context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display));
-       return g_app_info_launch (appinfo, NULL, context, error);
+       return gs_plugin_app_launch (plugin, app, error);
 }
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index d107f48..0210db3 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -24,7 +24,6 @@
 #define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
 #include <packagekit-glib2/packagekit.h>
 #include <glib/gi18n.h>
-#include <gio/gdesktopappinfo.h>
 
 #include <gs-plugin.h>
 
@@ -712,34 +711,8 @@ gs_plugin_launch (GsPlugin *plugin,
                  GCancellable *cancellable,
                  GError **error)
 {
-       GdkDisplay *display;
-       const gchar *desktop_id;
-       g_autoptr(GAppInfo) appinfo = NULL;
-       g_autoptr(GAppLaunchContext) context = NULL;
-
        /* only process this app if was created by this plugin */
        if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") != 0)
                return TRUE;
-
-       desktop_id = gs_app_get_id (app);
-       if (desktop_id == NULL) {
-               g_set_error (error,
-                            GS_PLUGIN_ERROR,
-                            GS_PLUGIN_ERROR_NOT_SUPPORTED,
-                            "no such desktop file: %s",
-                            desktop_id);
-               return FALSE;
-       }
-       appinfo = G_APP_INFO (g_desktop_app_info_new (desktop_id));
-       if (appinfo == NULL) {
-               g_set_error (error,
-                            GS_PLUGIN_ERROR,
-                            GS_PLUGIN_ERROR_NOT_SUPPORTED,
-                            "no such desktop file: %s",
-                            desktop_id);
-               return FALSE;
-       }
-       display = gdk_display_get_default ();
-       context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display));
-       return g_app_info_launch (appinfo, NULL, context, error);
+       return gs_plugin_app_launch (plugin, app, error);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]