[gnome-software/mwleeds/hardcoded-pwa-list] Fix lots of stuff
- From: Phaedrus Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/mwleeds/hardcoded-pwa-list] Fix lots of stuff
- Date: Thu, 24 Mar 2022 18:47:50 +0000 (UTC)
commit b5db08d37a0e35f082716a060cd52246b39a32cd
Author: Phaedrus Leeds <mwleeds protonmail com>
Date: Thu Mar 24 11:47:38 2022 -0700
Fix lots of stuff
plugins/epiphany/gs-plugin-epiphany.c | 180 +++++++++++++++++++---------------
1 file changed, 102 insertions(+), 78 deletions(-)
---
diff --git a/plugins/epiphany/gs-plugin-epiphany.c b/plugins/epiphany/gs-plugin-epiphany.c
index 05e53df6b..411bb04cf 100644
--- a/plugins/epiphany/gs-plugin-epiphany.c
+++ b/plugins/epiphany/gs-plugin-epiphany.c
@@ -435,14 +435,14 @@ gs_plugin_epiphany_list_installed_apps_async (GsPlugin *pl
/* Run in @worker */
static void
-refine_app (GsPluginEpiphany *self,
- GsApp *app,
- GUri *uri,
- const char *url)
+refine_app (GsPluginEpiphany *self,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GUri *uri,
+ const char *url)
{
const char *hostname;
const char *installed_app_id;
- hostname = g_uri_get_host (uri);
g_return_if_fail (GS_IS_APP (app));
g_return_if_fail (uri != NULL);
@@ -452,6 +452,7 @@ refine_app (GsPluginEpiphany *self,
gs_app_set_origin_ui (app, _("GNOME Web"));
gs_app_set_scope (app, AS_COMPONENT_SCOPE_USER);
+ gs_app_set_launchable (app, AS_LAUNCHABLE_KIND_URL, url);
installed_app_id = g_hash_table_lookup (self->url_id_map, url);
if (installed_app_id) {
@@ -469,6 +470,7 @@ refine_app (GsPluginEpiphany *self,
/* Use the domain name (e.g. "discourse.gnome.org") as a fallback summary.
* FIXME: Fetch the summary from the site's webapp manifest.
*/
+ hostname = g_uri_get_host (uri);
if (gs_app_get_summary (app) == NULL) {
if (hostname != NULL && *hostname != '\0')
gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, hostname);
@@ -497,6 +499,89 @@ refine_app (GsPluginEpiphany *self,
else if (g_str_equal (hostname, "devdocs.io"))
gs_app_set_license (app, GS_APP_QUALITY_NORMAL, "MPL-2.0");
}
+
+ {
+ const gchar *name;
+ g_autofree char *icon_path = NULL;
+ goffset desktop_size = 0, icon_size = 0;
+ g_autoptr(GDesktopAppInfo) desktop_info = NULL;
+ g_autoptr(GFileInfo) file_info = NULL;
+ g_autoptr(GFile) icon_file = NULL;
+
+ desktop_info = g_desktop_app_info_new (installed_app_id);
+
+ if (desktop_info == NULL) {
+ g_warning ("Couldn't get GDesktopAppInfo for app %s", installed_app_id);
+ return;
+ }
+
+ name = g_app_info_get_name (G_APP_INFO (desktop_info));
+ gs_app_set_name (app, GS_APP_QUALITY_NORMAL, name);
+
+ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE) {
+ g_autoptr(GFile) desktop_file = NULL;
+ const gchar *desktop_path;
+ guint64 install_date = 0;
+
+ desktop_path = g_desktop_app_info_get_filename (desktop_info);
+ g_assert (desktop_path);
+ desktop_file = g_file_new_for_path (desktop_path);
+
+ /* FIXME: this should use TIME_CREATED but it does not seem to
+ * be working (copied from Epiphany) */
+ file_info = g_file_query_info (desktop_file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED ","
G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ 0, NULL, NULL);
+ if (file_info) {
+ install_date = g_file_info_get_attribute_uint64 (file_info,
G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ desktop_size = g_file_info_get_size (file_info);
+ }
+ if (install_date) {
+ gs_app_set_install_date (app, install_date);
+ }
+ }
+
+ icon_path = g_desktop_app_info_get_string (desktop_info, "Icon");
+ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE &&
+ icon_path) {
+ icon_file = g_file_new_for_path (icon_path);
+
+ g_clear_object (&file_info);
+ file_info = g_file_query_info (icon_file,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ 0, NULL, NULL);
+ if (file_info)
+ icon_size = g_file_info_get_size (file_info);
+ }
+ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON &&
+ gs_app_get_icons (app) == NULL &&
+ icon_path) {
+ g_autoptr(GIcon) icon = g_file_icon_new (icon_file);
+ g_autofree char *icon_dir = g_path_get_dirname (icon_path);
+ g_autofree char *icon_dir_basename = g_path_get_basename (icon_dir);
+ const char *x;
+ int width = 0;
+
+ /* dir should be either scalable or e.g. 512x512 */
+ if (g_strcmp0 (icon_dir_basename, "scalable") == 0) {
+ /* Ensure scalable icons are preferred */
+ width = 4096;
+ } else if ((x = strchr (icon_dir_basename, 'x')) != NULL) {
+ width = atoi (x + 1);
+ }
+ if (width > 0 && width <= 4096) {
+ gs_icon_set_width (icon, width);
+ gs_icon_set_height (icon, width);
+ } else {
+ g_warning ("Unexpectedly unable to determine width of icon %s", icon_path);
+ }
+
+ gs_app_add_icon (app, icon);
+ }
+ if (desktop_size > 0 || icon_size > 0) {
+ gs_app_set_size_installed (app, desktop_size + icon_size);
+ }
+ }
}
/* Run in @worker */
@@ -551,21 +636,15 @@ refresh_installed_apps_cache (GsPluginEpiphany *self,
g_debug ("%s: epiphany-webapp-provider returned %u installed web apps", G_STRFUNC, n_webapps);
for (guint i = 0; i < n_webapps; i++) {
const gchar *desktop_file_id = webapps[i];
- const gchar *desktop_path;
- const gchar *name;
const gchar *url = NULL;
- g_autofree char *icon_path = NULL;
g_autofree char *url_hash = NULL;
g_autofree char *metainfo_app_id = NULL;
const gchar *exec;
int argc;
+ GsPluginRefineFlags refine_flags;
g_auto(GStrv) argv = NULL;
- guint64 install_date = 0;
- goffset desktop_size = 0, icon_size = 0;
g_autoptr(GsApp) app = NULL;
g_autoptr(GDesktopAppInfo) desktop_info = NULL;
- g_autoptr(GFileInfo) file_info = NULL;
- g_autoptr(GFile) desktop_file = NULL;
g_autoptr(GUri) uri = NULL;
g_debug ("%s: Working on installed web app %s", G_STRFUNC, desktop_file_id);
@@ -577,8 +656,6 @@ refresh_installed_apps_cache (GsPluginEpiphany *self,
continue;
}
- name = g_app_info_get_name (G_APP_INFO (desktop_info));
-
/* This way of getting the URL is a bit hacky but it's what Epiphany does */
exec = g_app_info_get_commandline (G_APP_INFO (desktop_info));
if (g_shell_parse_argv (exec, &argc, &argv, NULL)) {
@@ -591,22 +668,6 @@ refresh_installed_apps_cache (GsPluginEpiphany *self,
continue;
}
- icon_path = g_desktop_app_info_get_string (desktop_info, "Icon");
-
- desktop_path = g_desktop_app_info_get_filename (desktop_info);
- g_assert (desktop_path);
- desktop_file = g_file_new_for_path (desktop_path);
-
- /* FIXME: this should use TIME_CREATED but it does not seem to
- * be working (copied from Epiphany) */
- file_info = g_file_query_info (desktop_file,
- G_FILE_ATTRIBUTE_TIME_MODIFIED ","
G_FILE_ATTRIBUTE_STANDARD_SIZE,
- 0, NULL, NULL);
- if (file_info) {
- install_date = g_file_info_get_attribute_uint64 (file_info,
G_FILE_ATTRIBUTE_TIME_MODIFIED);
- desktop_size = g_file_info_get_size (file_info);
- }
-
/* Store the installed app id for use in refine_app() */
g_hash_table_insert (self->url_id_map, g_strdup (url),
g_strdup (desktop_file_id));
@@ -627,50 +688,11 @@ refresh_installed_apps_cache (GsPluginEpiphany *self,
app = gs_epiphany_create_app (self, metainfo_app_id);
gs_app_set_state (app, GS_APP_STATE_INSTALLED);
- gs_app_set_name (app, GS_APP_QUALITY_NORMAL, name);
- gs_app_set_launchable (app, AS_LAUNCHABLE_KIND_URL, url);
-
- refine_app (self, app, uri, url);
-
- if (icon_path) {
- g_autoptr(GFile) icon_file = g_file_new_for_path (icon_path);
- g_autoptr(GIcon) icon = g_file_icon_new (icon_file);
- g_autofree char *icon_dir = g_path_get_dirname (icon_path);
- g_autofree char *icon_dir_basename = g_path_get_basename (icon_dir);
- const char *x;
- int size = 0;
-
- g_debug ("%s: finding size for icon %s", G_STRFUNC, icon_path);
-
- g_clear_object (&file_info);
- file_info = g_file_query_info (icon_file,
- G_FILE_ATTRIBUTE_STANDARD_SIZE,
- 0, NULL, NULL);
- if (file_info)
- icon_size = g_file_info_get_size (file_info);
- /* dir should be either scalable or e.g. 512x512 */
- if (g_strcmp0 (icon_dir_basename, "scalable") == 0) {
- /* Ensure scalable icons are preferred */
- size = 4096;
- } else if ((x = strchr (icon_dir_basename, 'x')) != NULL) {
- size = atoi (x + 1);
- }
- if (size > 0 && size <= 4096) {
- gs_icon_set_width (icon, size);
- gs_icon_set_height (icon, size);
- } else {
- g_warning ("Unexpectedly unable to determine size of icon %s", icon_path);
- }
-
- gs_app_add_icon (app, icon);
- }
- if (install_date) {
- gs_app_set_install_date (app, install_date);
- }
- if (desktop_size > 0 || icon_size > 0) {
- gs_app_set_size_installed (app, desktop_size + icon_size);
- }
+ refine_flags = GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_ID;
+ refine_app (self, app, refine_flags, uri, url);
}
/* Update the state on any apps that were uninstalled outside
@@ -734,9 +756,10 @@ gs_plugin_epiphany_list_installed_apps_finish (GsPlugin *plugin,
}
static void
-gs_epiphany_refine_app (GsPluginEpiphany *self,
- GsApp *app,
- const char *url)
+gs_epiphany_refine_app (GsPluginEpiphany *self,
+ GsApp *app,
+ GsPluginRefineFlags refine_flags,
+ const char *url)
{
g_autoptr(GUri) uri = NULL;
@@ -747,7 +770,7 @@ gs_epiphany_refine_app (GsPluginEpiphany *self,
return;
}
- refine_app (self, app, uri, url);
+ refine_app (self, app, refine_flags, uri, url);
}
static void refine_thread_cb (GTask *task,
@@ -783,6 +806,7 @@ refine_thread_cb (GTask *task,
{
GsPluginEpiphany *self = GS_PLUGIN_EPIPHANY (source_object);
GsPluginRefineData *data = task_data;
+ GsPluginRefineFlags flags = data->flags;
GsAppList *list = data->list;
g_autoptr(GError) local_error = NULL;
@@ -805,7 +829,7 @@ refine_thread_cb (GTask *task,
}
g_debug ("epiphany: refining app %s", gs_app_get_id (app));
- gs_epiphany_refine_app (self, app, url);
+ gs_epiphany_refine_app (self, app, flags, url);
gs_epiphany_refine_app_state (GS_PLUGIN (self), app);
/* Usually the way to refine wildcard apps is to create a new
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]