In this other thread, @jdstrand suggested to use a zenity dialog to inform users of a snap’s deprecation (in favour of another snap).
I finally got around to implementing this, and since this was less straightforward than I had hoped, I thought I’d share my notes here for others to use in similar use cases.
I had initially hoped to stage zenity
and invoke it, but it turns out it’s not relocatable, it looks for its UI definition file in /usr/share/zenity/zenity.ui
and there’s no way to prepend $SNAP
to that location that doesn’t involve rebuilding zenity.
Here is a custom zenity
part:
zenity:
source: https://gitlab.gnome.org/GNOME/zenity.git
source-tag: 3.28.1
plugin: autotools
configflags:
- --disable-libnotify
- --disable-webkitgtk
build-packages:
- gnome-pkg-tools
- gnome-common
- yelp-tools
- gettext
- libglib2.0-dev
- libgtk-3-dev
override-build: |
set -eux
patch -d . -p1 < ../../../snap/zenity-ui-snap-aware.patch
snapcraftctl build
It uses a patch to make zenity snap-aware:
diff --git a/src/util.c b/src/util.c
index 0c10186..86c24a6 100644
--- a/src/util.c
+++ b/src/util.c
@@ -58,6 +58,8 @@ zenity_util_load_ui_file (const gchar *root_widget, ...) {
GError *error = NULL;
gchar **objects;
guint result = 0;
+ const gchar *env_var = NULL;
+ const gchar *zenity_ui_file_fullpath = NULL;
gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
@@ -86,9 +88,16 @@ zenity_util_load_ui_file (const gchar *root_widget, ...) {
builder, ZENITY_UI_FILE_RELATIVEPATH, objects, NULL);
}
- if (result == 0)
+ if (result == 0) {
+ env_var = g_getenv ("SNAP");
+ if (env_var)
+ zenity_ui_file_fullpath = g_strconcat (env_var, ZENITY_UI_FILE_FULLPATH, NULL);
+ else
+ zenity_ui_file_fullpath = g_strdup (ZENITY_UI_FILE_FULLPATH);
result = gtk_builder_add_objects_from_file (
- builder, ZENITY_UI_FILE_FULLPATH, objects, &error);
+ builder, zenity_ui_file_fullpath, objects, &error);
+ g_free (zenity_ui_file_fullpath);
+ }
g_strfreev (objects);
Don’t forget to use the desktop-gtk3
remote part to pull in all required dependencies and run zenity
through the desktop-launch
script.
And here is a complete example of all the pieces put together.