[gnome-software] Prefer the launchable tag for the URL of web apps
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Prefer the launchable tag for the URL of web apps
- Date: Tue, 5 Dec 2017 11:25:28 +0000 (UTC)
commit d720b6ce46cd7b137e23cfbea1d869ea85682a7b
Author: Dimitrios Christidis <dimitrios christidis me>
Date: Tue Nov 14 22:11:49 2017 +0100
Prefer the launchable tag for the URL of web apps
Beginning with AppStream specification 0.11.7, a launchable tag of type
"url" must be present for web applications and it should be used as the
target location.
This commit adds the available launchables to GsApp and uses the "url"
one during the creation of web applications. If it isn't present, it
falls back to the url tag of type "homepage".
The appstream-glib dependency is bumped to version 0.7.3.
https://bugzilla.gnome.org/show_bug.cgi?id=789762
Signed-off-by: Richard Hughes <richard hughsie com>
lib/gs-app.c | 55 +++++++++++++++++++++++++++++++++
lib/gs-app.h | 5 +++
meson.build | 2 +-
plugins/core/gs-appstream.c | 31 ++++++++++++++++++
plugins/epiphany/gs-plugin-epiphany.c | 6 +++-
5 files changed, 97 insertions(+), 2 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 9c69349..bbf7773 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -82,6 +82,7 @@ typedef struct
GPtrArray *key_colors;
GPtrArray *keywords;
GHashTable *urls;
+ GHashTable *launchables;
gchar *license;
GsAppQuality license_quality;
gchar **menu_path;
@@ -505,6 +506,14 @@ gs_app_to_string_append (GsApp *app, GString *str)
tmp = g_hash_table_lookup (priv->urls, as_url_kind_to_string (AS_URL_KIND_HOMEPAGE));
if (tmp != NULL)
gs_app_kv_lpad (str, "url{homepage}", tmp);
+ keys = g_hash_table_get_keys (priv->launchables);
+ for (l = keys; l != NULL; l = l->next) {
+ g_autofree gchar *key = NULL;
+ key = g_strdup_printf ("launchable{%s}", (const gchar *) l->data);
+ tmp = g_hash_table_lookup (priv->launchables, l->data);
+ gs_app_kv_lpad (str, key, tmp);
+ }
+ g_list_free (keys);
if (priv->license != NULL) {
gs_app_kv_lpad (str, "license", priv->license);
gs_app_kv_lpad (str, "license-is-free",
@@ -2132,6 +2141,47 @@ gs_app_set_url (GsApp *app, AsUrlKind kind, const gchar *url)
}
/**
+ * gs_app_get_launchable:
+ * @app: a #GsApp
+ * @kind: a #AsLaunchableKind, e.g. %AS_LAUNCHABLE_KIND_DESKTOP_ID
+ *
+ * Gets a launchable of a specific type.
+ *
+ * Returns: a string, or %NULL for unset
+ *
+ * Since: 3.28
+ **/
+const gchar *
+gs_app_get_launchable (GsApp *app, AsLaunchableKind kind)
+{
+ GsAppPrivate *priv = gs_app_get_instance_private (app);
+ g_return_val_if_fail (GS_IS_APP (app), NULL);
+ return g_hash_table_lookup (priv->launchables,
+ as_launchable_kind_to_string (kind));
+}
+
+/**
+ * gs_app_set_launchable:
+ * @app: a #GsApp
+ * @kind: a #AsLaunchableKind, e.g. %AS_LAUNCHABLE_KIND_DESKTOP_ID
+ * @launchable: a way to launch, e.g. "org.gnome.Sysprof2.desktop"
+ *
+ * Sets a launchable of a specific type.
+ *
+ * Since: 3.28
+ **/
+void
+gs_app_set_launchable (GsApp *app, AsLaunchableKind kind, const gchar *launchable)
+{
+ GsAppPrivate *priv = gs_app_get_instance_private (app);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+ g_return_if_fail (GS_IS_APP (app));
+ g_hash_table_insert (priv->launchables,
+ g_strdup (as_launchable_kind_to_string (kind)),
+ g_strdup (launchable));
+}
+
+/**
* gs_app_get_license:
* @app: a #GsApp
*
@@ -3974,6 +4024,7 @@ gs_app_finalize (GObject *object)
g_free (priv->branch);
g_free (priv->name);
g_hash_table_unref (priv->urls);
+ g_hash_table_unref (priv->launchables);
g_free (priv->license);
g_strfreev (priv->menu_path);
g_free (priv->origin);
@@ -4152,6 +4203,10 @@ gs_app_init (GsApp *app)
g_str_equal,
g_free,
g_free);
+ priv->launchables = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
priv->allow_cancel = TRUE;
g_mutex_init (&priv->mutex);
}
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 6876bf8..c41a67a 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -185,6 +185,11 @@ const gchar *gs_app_get_url (GsApp *app,
void gs_app_set_url (GsApp *app,
AsUrlKind kind,
const gchar *url);
+const gchar *gs_app_get_launchable (GsApp *app,
+ AsLaunchableKind kind);
+void gs_app_set_launchable (GsApp *app,
+ AsLaunchableKind kind,
+ const gchar *launchable);
const gchar *gs_app_get_license (GsApp *app);
gboolean gs_app_get_license_is_free (GsApp *app);
void gs_app_set_license (GsApp *app,
diff --git a/meson.build b/meson.build
index e305dfb..914ade8 100644
--- a/meson.build
+++ b/meson.build
@@ -92,7 +92,7 @@ add_global_link_arguments(
# Needed for PATH_MAX and symlink()
add_project_arguments('-D_XOPEN_SOURCE=500', language : 'c')
-appstream_glib = dependency('appstream-glib', version : '>= 0.7.0')
+appstream_glib = dependency('appstream-glib', version : '>= 0.7.3')
gdk_pixbuf = dependency('gdk-pixbuf-2.0', version : '>= 2.31.5')
gio_unix = dependency('gio-unix-2.0')
gmodule = dependency('gmodule-2.0')
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 0059bd6..e4bcc3d 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -498,6 +498,7 @@ gs_appstream_refine_app (GsPlugin *plugin,
AsRequire *req;
g_autoptr(GError) error_local = NULL;
GHashTable *urls;
+ GPtrArray *launchables;
GPtrArray *array;
GPtrArray *pkgnames;
GPtrArray *kudos;
@@ -628,6 +629,36 @@ gs_appstream_refine_app (GsPlugin *plugin,
}
}
+ /* add launchables */
+ launchables = as_app_get_launchables (item);
+ for (i = 0; i < launchables->len; i++) {
+ AsLaunchable *launchable = g_ptr_array_index (launchables, i);
+ switch (as_launchable_get_kind (launchable)) {
+ case AS_LAUNCHABLE_KIND_DESKTOP_ID:
+ gs_app_set_launchable (app,
+ AS_LAUNCHABLE_KIND_DESKTOP_ID,
+ as_launchable_get_value (launchable));
+ break;
+ case AS_LAUNCHABLE_KIND_SERVICE:
+ gs_app_set_launchable (app,
+ AS_LAUNCHABLE_KIND_SERVICE,
+ as_launchable_get_value (launchable));
+ break;
+ case AS_LAUNCHABLE_KIND_COCKPIT_MANIFEST:
+ gs_app_set_launchable (app,
+ AS_LAUNCHABLE_KIND_COCKPIT_MANIFEST,
+ as_launchable_get_value (launchable));
+ break;
+ case AS_LAUNCHABLE_KIND_URL:
+ gs_app_set_launchable (app,
+ AS_LAUNCHABLE_KIND_URL,
+ as_launchable_get_value (launchable));
+ break;
+ default:
+ break;
+ }
+ }
+
/* set license */
if (as_app_get_project_license (item) != NULL && gs_app_get_license (app) == NULL)
gs_app_set_license (app,
diff --git a/plugins/epiphany/gs-plugin-epiphany.c b/plugins/epiphany/gs-plugin-epiphany.c
index 61a7d7d..b245506 100644
--- a/plugins/epiphany/gs-plugin-epiphany.c
+++ b/plugins/epiphany/gs-plugin-epiphany.c
@@ -94,6 +94,7 @@ gs_plugin_app_install (GsPlugin *plugin, GsApp *app,
g_autoptr(GKeyFile) kf = NULL;
g_autoptr(GFile) symlink_desktop = NULL;
g_autoptr(GFile) symlink_icon = NULL;
+ const gchar *url = NULL;
/* only process this app if was created by this plugin */
if (g_strcmp0 (gs_app_get_management_plugin (app),
@@ -151,9 +152,12 @@ gs_plugin_app_install (GsPlugin *plugin, GsApp *app,
G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_COMMENT,
gs_app_get_summary (app));
+ url = gs_app_get_launchable (app, AS_LAUNCHABLE_KIND_URL);
+ if (url == NULL)
+ url = gs_app_get_url (app, AS_URL_KIND_HOMEPAGE);
exec = g_strdup_printf ("epiphany --application-mode --profile=\"%s\" %s",
epi_dir,
- gs_app_get_url (app, AS_URL_KIND_HOMEPAGE));
+ url);
g_key_file_set_string (kf,
G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_EXEC,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]