[gnome-software/wip/ubuntu: 4/5] Support snap launching



commit 14c416d95590b310e3306851769f2a7b8745e18b
Author: Robert Ancell <robert ancell canonical com>
Date:   Wed Jun 22 15:05:34 2016 +1200

    Support snap launching

 src/plugins/gs-plugin-snappy.c |   55 ++++++++++++++++++++++++++++++++++++---
 1 files changed, 50 insertions(+), 5 deletions(-)
---
diff --git a/src/plugins/gs-plugin-snappy.c b/src/plugins/gs-plugin-snappy.c
index fb84629..fbbb656 100644
--- a/src/plugins/gs-plugin-snappy.c
+++ b/src/plugins/gs-plugin-snappy.c
@@ -94,9 +94,9 @@ parse_result (const gchar *response, const gchar *response_type, GError **error)
 }
 
 static void
-refine_app (GsPlugin *plugin, GsApp *app, JsonObject *package)
+refine_app (GsPlugin *plugin, GsApp *app, JsonObject *package, gboolean from_search)
 {
-       const gchar *status, *icon_url;
+       const gchar *status, *icon_url, *launch_name = NULL;
        g_autoptr(GdkPixbuf) icon_pixbuf = NULL;
        gint64 size = -1;
 
@@ -166,6 +166,19 @@ refine_app (GsPlugin *plugin, GsApp *app, JsonObject *package)
                as_icon_set_name (icon, "package-x-generic");
                gs_app_set_icon (app, icon);
        }
+
+       if (!from_search) {
+               JsonArray *apps;
+
+               apps = json_object_get_array_member (package, "apps");
+               if (apps && json_array_get_length (apps) > 0)
+                       launch_name = json_object_get_string_member (json_array_get_object_element (apps, 0), 
"name");
+
+               if (launch_name)
+                       gs_app_set_metadata (app, "snap::launch-name", launch_name);
+               else
+                       gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
+       }
 }
 
 static gboolean
@@ -235,8 +248,7 @@ get_apps (GsPlugin *plugin, const gchar *sources, gchar **search_terms, GList **
                gs_app_set_origin (app, _("Ubuntu Snappy Store"));
                gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
                gs_app_add_quirk (app, AS_APP_QUIRK_NOT_REVIEWABLE);
-               gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
-               refine_app (plugin, app, package);
+               refine_app (plugin, app, package, TRUE);
                gs_plugin_add_app (list, app);
        }
 
@@ -278,7 +290,7 @@ get_app (GsPlugin *plugin, GsApp *app, GError **error)
                return FALSE;
        }
 
-       refine_app (plugin, app, result);
+       refine_app (plugin, app, result, FALSE);
 
        return TRUE;
 }
@@ -467,6 +479,39 @@ gs_plugin_app_install (GsPlugin *plugin,
 }
 
 gboolean
+gs_plugin_launch (GsPlugin *plugin,
+                 GsApp *app,
+                 GCancellable *cancellable,
+                 GError **error)
+{
+       const gchar *launch_name;
+       g_autofree gchar *binary_name = NULL;
+       g_autoptr(GAppInfo) info = NULL;
+
+       /* We can only launch apps we know of */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), "snappy") != 0)
+               return TRUE;
+
+       launch_name = gs_app_get_metadata_item (app, "snap::launch-name");
+       if (!launch_name)
+               return TRUE;
+
+       if (strcmp (launch_name, gs_app_get_id (app)) == 0)
+               binary_name = g_strdup_printf ("/snap/bin/%s", launch_name);
+       else
+               binary_name = g_strdup_printf ("/snap/bin/%s.%s", gs_app_get_id (app), launch_name);
+       g_printerr ("BINARY='%s'\n", binary_name);
+
+       // FIXME: Since we don't currently know if this app needs a terminal or not we launch everything with 
one
+       // https://bugs.launchpad.net/bugs/1595023
+       info = g_app_info_create_from_commandline (binary_name, NULL, G_APP_INFO_CREATE_NEEDS_TERMINAL, 
error);
+       if (info == NULL)
+               return FALSE;
+
+       return g_app_info_launch (info, NULL, NULL, error);
+}
+
+gboolean
 gs_plugin_app_remove (GsPlugin *plugin,
                      GsApp *app,
                      GCancellable *cancellable,


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