[gnome-software: 3/5] plugins: Find upgrade background images from new well-known locations
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 3/5] plugins: Find upgrade background images from new well-known locations
- Date: Tue, 8 Feb 2022 09:19:00 +0000 (UTC)
commit 87d84e55f3dcf8573bea00b2189dcc61ff17313b
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Feb 4 14:39:37 2022 +0000
plugins: Find upgrade background images from new well-known locations
Rather than shipping one in-tree and requiring distributions to patch
gnome-software downstream to customise it.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
NEWS | 9 +++++
data/assets/meson.build | 6 ----
data/assets/upgrade-bg.png | Bin 17507 -> 0 bytes
doc/vendor-customisation.md | 20 +++++++++++
lib/gs-utils.c | 40 +++++++++++++++++++++
lib/gs-utils.h | 2 ++
plugins/dummy/gs-plugin-dummy.c | 15 +++++---
plugins/eos-updater/gs-plugin-eos-updater.c | 13 +++++--
.../gs-plugin-fedora-pkgdb-collections.c | 8 +++++
9 files changed, 100 insertions(+), 13 deletions(-)
---
diff --git a/NEWS b/NEWS
index 01b5ea01e..ea1a7e37c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,12 @@
+UNRELEASED
+~~~~~~~~~~
+
+ * The background image for upgrades is now looked for using several well-known
+ (and distribution-specific) names in `${DATADIR}/gnome-software/backgrounds`,
+ and the previous Fedora-specific default background image is no longer
+ distributed. Distributions may need to update how they ship background
+ images. See `doc/vendor-customisation.md`.
+
Version 42.alpha
~~~~~~~~~~~~~~~~
Released: 2022-01-07
diff --git a/data/assets/meson.build b/data/assets/meson.build
index ec036be91..7eed5cd65 100644
--- a/data/assets/meson.build
+++ b/data/assets/meson.build
@@ -1,9 +1,3 @@
-install_data([
- 'upgrade-bg.png',
- ],
- install_dir : 'share/gnome-software'
-)
-
if get_option('default_featured_apps')
install_data('org.gnome.Software.Featured.xml',
install_dir : join_paths(get_option('datadir'), 'app-info', 'xmls'),
diff --git a/doc/vendor-customisation.md b/doc/vendor-customisation.md
index 9529d3d6b..2e450eba9 100644
--- a/doc/vendor-customisation.md
+++ b/doc/vendor-customisation.md
@@ -49,3 +49,23 @@ The principles which guide vendor customisation features in GNOME Software are:
which is a burden.
- It’s easier to allow distributions to put customisations specific to a new
OS version into a separate package.
+
+Upgrade background image
+------------------------
+
+The background image which is shown when a new OS upgrade is available is
+customisable in several ways. It’s displayed by the `GsUpgradeBanner` widget,
+and shown on the updates page.
+
+If your distribution has a specific GNOME Software plugin providing its upgrade
+information, that plugin can provide CSS for rendering the background. See the
+`fedora-pkgdb-collections` plugin for an example of this.
+
+Otherwise, the background image is looked up from several well-known locations,
+in order:
+ * `${DATADIR}/gnome-software/backgrounds/${os_id}-${version}.png`
+ * `${DATADIR}/gnome-software/backgrounds/${os_id}.png`
+
+`${DATADIR}` is the configured data directory (typically `/usr/share`).
+`${os_id}` is the `ID=` value from `/etc/os-release`, and `${version}` is the
+version string being upgraded to.
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index 47b6ded61..8f8b59e96 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -1591,3 +1591,43 @@ gs_utils_set_file_etag (const gchar *filename,
return g_file_set_attribute_string (file, METADATA_ETAG_ATTRIBUTE, etag, G_FILE_QUERY_INFO_NONE,
cancellable, NULL);
}
+
+/**
+ * gs_utils_get_upgrade_background:
+ * @version: (nullable): version string of the upgrade (which must be non-empty
+ * if provided), or %NULL if unknown
+ *
+ * Get the path to a background image to display as the background for a banner
+ * advertising an upgrade to the given @version.
+ *
+ * If a path is returned, it’s guaranteed to exist on the file system.
+ *
+ * Vendors can drop their customised backgrounds in this directory for them to
+ * be used by gnome-software. See `doc/vendor-customisation.md`.
+ *
+ * Returns: (transfer full) (type filename) (nullable): path to an upgrade
+ * background image to use, or %NULL if a suitable one didn’t exist
+ * Since: 42
+*/
+gchar *
+gs_utils_get_upgrade_background (const gchar *version)
+{
+ g_autofree gchar *filename = NULL;
+ g_autofree gchar *os_id = g_get_os_info (G_OS_INFO_KEY_ID);
+
+ g_return_val_if_fail (version == NULL || *version != '\0', NULL);
+
+ if (version != NULL) {
+ filename = g_strdup_printf (DATADIR "/gnome-software/backgrounds/%s-%s.png", os_id, version);
+ if (g_file_test (filename, G_FILE_TEST_EXISTS))
+ return g_steal_pointer (&filename);
+ g_clear_pointer (&filename, g_free);
+ }
+
+ filename = g_strdup_printf (DATADIR "/gnome-software/backgrounds/%s.png", os_id);
+ if (g_file_test (filename, G_FILE_TEST_EXISTS))
+ return g_steal_pointer (&filename);
+ g_clear_pointer (&filename, g_free);
+
+ return NULL;
+}
diff --git a/lib/gs-utils.h b/lib/gs-utils.h
index b5f590df8..ef33ed9ac 100644
--- a/lib/gs-utils.h
+++ b/lib/gs-utils.h
@@ -140,4 +140,6 @@ gboolean gs_utils_set_file_etag (const gchar *filename,
const gchar *etag,
GCancellable *cancellable);
+gchar *gs_utils_get_upgrade_background (const gchar *version);
+
G_END_DECLS
diff --git a/plugins/dummy/gs-plugin-dummy.c b/plugins/dummy/gs-plugin-dummy.c
index 49a5ff6fc..b7e91d185 100644
--- a/plugins/dummy/gs-plugin-dummy.c
+++ b/plugins/dummy/gs-plugin-dummy.c
@@ -828,6 +828,8 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
{
g_autoptr(GsApp) app = NULL;
g_autoptr(GIcon) ic = NULL;
+ g_autofree gchar *background_filename = NULL;
+ g_autofree gchar *css = NULL;
/* use stock icon */
ic = g_themed_icon_new ("system-component-addon");
@@ -857,10 +859,15 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
gs_app_set_size_download (app, 1024 * 1024 * 1024);
gs_app_set_license (app, GS_APP_QUALITY_LOWEST, "LicenseRef-free");
gs_app_set_management_plugin (app, plugin);
- gs_app_set_metadata (app, "GnomeSoftware::UpgradeBanner-css",
- "background: url('file://" DATADIR "/gnome-software/upgrade-bg.png');"
- "background-size: 100% 100%;"
- "border-width: 0;");
+
+ /* Check for a background image in the standard location. */
+ background_filename = gs_utils_get_upgrade_background ("34");
+
+ if (background_filename != NULL)
+ css = g_strconcat ("background: url('file://", background_filename, "');"
+ "background-size: 100% 100%;", NULL);
+ gs_app_set_metadata (app, "GnomeSoftware::UpgradeBanner-css", css);
+
gs_app_add_icon (app, ic);
gs_app_list_add (list, app);
diff --git a/plugins/eos-updater/gs-plugin-eos-updater.c b/plugins/eos-updater/gs-plugin-eos-updater.c
index d182e376c..6ce246edf 100644
--- a/plugins/eos-updater/gs-plugin-eos-updater.c
+++ b/plugins/eos-updater/gs-plugin-eos-updater.c
@@ -545,6 +545,8 @@ proxy_new_cb (GObject *source_object,
g_autofree gchar *name_owner = NULL;
g_autoptr(GsApp) app = NULL;
g_autoptr(GIcon) ic = NULL;
+ g_autofree gchar *background_filename = NULL;
+ g_autofree gchar *css = NULL;
g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(GError) local_error = NULL;
@@ -581,6 +583,13 @@ proxy_new_cb (GObject *source_object,
/* use stock icon */
ic = g_themed_icon_new ("system-component-addon");
+ /* Check for a background image in the standard location. */
+ background_filename = gs_utils_get_upgrade_background (NULL);
+
+ if (background_filename != NULL)
+ css = g_strconcat ("background: url('file://", background_filename, "');"
+ "background-size: 100% 100%;", NULL);
+
/* create the OS upgrade */
app = gs_app_new ("com.endlessm.EOS.upgrade");
gs_app_add_icon (app, ic);
@@ -598,9 +607,7 @@ proxy_new_cb (GObject *source_object,
gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
gs_app_add_quirk (app, GS_APP_QUIRK_NOT_REVIEWABLE);
gs_app_set_management_plugin (app, GS_PLUGIN (self));
- gs_app_set_metadata (app, "GnomeSoftware::UpgradeBanner-css",
- "background: url('file://" DATADIR "/gnome-software/upgrade-bg.png');"
- "background-size: 100% 100%;");
+ gs_app_set_metadata (app, "GnomeSoftware::UpgradeBanner-css", css);
self->os_upgrade = g_steal_pointer (&app);
diff --git a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
index 20053f4d5..1aabe0186 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -275,6 +275,8 @@ static gchar *
_get_upgrade_css_background (guint version)
{
g_autoptr(GSettings) settings = NULL;
+ g_autofree gchar *version_str = g_strdup_printf ("%u", version);
+ g_autofree gchar *filename0 = NULL;
g_autofree gchar *filename1 = NULL;
g_autofree gchar *filename2 = NULL;
g_autofree gchar *uri = NULL;
@@ -308,6 +310,12 @@ _get_upgrade_css_background (guint version)
}
}
+ /* Check the standard location. */
+ filename0 = gs_utils_get_upgrade_background (version_str);
+ if (filename0 != NULL)
+ return g_strdup_printf ("url('file://%s')", filename0);
+
+ /* Fedora-specific locations. Deprecated. */
filename1 = g_strdup_printf ("/usr/share/backgrounds/f%u/default/standard/f%u.png", version, version);
if (g_file_test (filename1, G_FILE_TEST_EXISTS))
return g_strdup_printf ("url('file://%s')", filename1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]