[gnome-software/mwleeds/hardcoded-pwa-list] fixup! epiphany: Refine appstream-provided web apps
- From: Phaedrus Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/mwleeds/hardcoded-pwa-list] fixup! epiphany: Refine appstream-provided web apps
- Date: Wed, 16 Mar 2022 20:15:57 +0000 (UTC)
commit 61721592402ad3c6c3490a086174b2daf20a256d
Author: Phaedrus Leeds <mwleeds protonmail com>
Date: Wed Mar 16 13:15:51 2022 -0700
fixup! epiphany: Refine appstream-provided web apps
plugins/epiphany/gs-plugin-epiphany.c | 76 ++++++++++++++++++++++-------------
1 file changed, 47 insertions(+), 29 deletions(-)
---
diff --git a/plugins/epiphany/gs-plugin-epiphany.c b/plugins/epiphany/gs-plugin-epiphany.c
index b4c464cbb..702d895b9 100644
--- a/plugins/epiphany/gs-plugin-epiphany.c
+++ b/plugins/epiphany/gs-plugin-epiphany.c
@@ -345,6 +345,29 @@ gs_plugin_epiphany_finalize (GObject *object)
G_OBJECT_CLASS (gs_plugin_epiphany_parent_class)->finalize (object);
}
+static void
+gs_epiphany_refine_app_state (GsPlugin *plugin,
+ GsApp *app)
+{
+ if (gs_app_get_state (app) == GS_APP_STATE_UNKNOWN) {
+ g_autoptr(GsApp) cached_app = NULL;
+ const char *appstream_source;
+
+ /* If we have a cached app, set the state from there. Otherwise
+ * only set the state to available if the app came from
+ * appstream data, because there's no way to re-install an app
+ * in Software that was originally installed from Epiphany,
+ * unless we have appstream metainfo for it.
+ */
+ cached_app = gs_plugin_cache_lookup (GS_PLUGIN (self), gs_app_get_id (app));
+ appstream_source = gs_app_get_metadata_item (app, "appstream::source-file");
+ if (cached_app)
+ gs_app_set_state (app, gs_app_get_state (cached_app));
+ else if (appstream_source)
+ gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
+ }
+}
+
void
gs_plugin_adopt_app (GsPlugin *plugin,
GsApp *app)
@@ -354,8 +377,7 @@ gs_plugin_adopt_app (GsPlugin *plugin,
gs_app_set_management_plugin (app, plugin);
}
- if (gs_app_get_state (app) == GS_APP_STATE_UNKNOWN)
- gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
+ gs_epiphany_refine_app_state (plugin, app);
}
static void list_installed_apps_thread_cb (GTask *task,
@@ -628,6 +650,25 @@ gs_plugin_epiphany_list_installed_apps_finish (GsPlugin *plugin,
return g_task_propagate_pointer (G_TASK (result), error);
}
+static void
+gs_epiphany_refine_app (GsApp *app)
+{
+ const char *url;
+ g_autoptr(GUri) uri = NULL;
+
+ url = gs_app_get_launchable (app, AS_LAUNCHABLE_KIND_URL);
+ if (url == NULL || *url == '\0') {
+ /* A launchable URL is required by the AppStream spec */
+ g_warning ("Web app %s missing launchable url", gs_app_get_id (app));
+ return;
+ } else if (!(uri = g_uri_parse (url, G_URI_FLAGS_NONE, NULL))) {
+ g_warning ("Failed to parse URL for web app %s: %s", gs_app_get_id (app), url);
+ return;
+ }
+
+ refine_app (app, uri, url);
+}
+
static void refine_thread_cb (GTask *task,
gpointer source_object,
gpointer task_data,
@@ -669,38 +710,14 @@ refine_thread_cb (GTask *task,
for (guint i = 0; i < gs_app_list_length (list); i++) {
GsApp *app = gs_app_list_index (list, i);
- const char *url;
- g_autoptr(GUri) uri = NULL;
/* not us */
if (gs_app_get_kind (app) != AS_COMPONENT_KIND_WEB_APP ||
gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_PACKAGE)
continue;
- url = gs_app_get_launchable (app, AS_LAUNCHABLE_KIND_URL);
- if (url == NULL || *url == '\0') {
- /* A launchable URL is required by the AppStream spec */
- g_warning ("Web app %s missing launchable url", gs_app_get_id (app));
- continue;
- } else if (!(uri = g_uri_parse (url, G_URI_FLAGS_NONE, NULL))) {
- g_warning ("Failed to parse URL for web app %s: %s", gs_app_get_id (app), url);
- continue;
- }
-
- if (gs_app_get_state (app) == GS_APP_STATE_UNKNOWN) {
- g_autoptr(GsApp) cached_app = NULL;
-
- /* Set the state to available unless we have a cached
- * app already, in which case it's probably installed
- */
- cached_app = gs_plugin_cache_lookup (GS_PLUGIN (self), gs_app_get_id (app));
- if (cached_app)
- gs_app_set_state (app, gs_app_get_state (cached_app));
- else
- gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
- }
-
- refine_app (app, uri, url);
+ gs_epiphany_refine_app (app);
+ gs_epiphany_refine_app_state (GS_PLUGIN (self), app);
}
/* Refine wildcards.
@@ -724,7 +741,8 @@ refine_thread_cb (GTask *task,
continue;
new = gs_epiphany_create_app (self, gs_app_get_id (app));
-
+ gs_epiphany_refine_app (new);
+ gs_epiphany_refine_app_state (GS_PLUGIN (self), new);
gs_app_subsume_metadata (new, app);
gs_app_list_add (list, new);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]