Example GTK3 app¶
This how-to guide covers the steps, decisions, and implementation details that are unique when crafting a snap of an app built using GTK3 and GNOME. We’ll work through the aspects unique to GTK3-based apps by examining an existing recipe.
Example foliate recipe¶
The following code comprises the recipe of a GTK3 project, foliate. This project is an e-book reader.
foliate recipe
name: foliate
grade: stable
adopt-info: foliate
license: GPL-3.0+
base: core20
confinement: strict
apps:
foliate:
command: usr/bin/com.github.johnfactotum.Foliate
extensions: [gnome-3-38]
plugs:
- home
slots:
- dbus-daemon
common-id: com.github.johnfactotum.Foliate
parts:
foliate:
plugin: meson
source: https://github.com/johnfactotum/foliate.git
source-branch: 1.x
meson-parameters: [--prefix=/snap/foliate/current/usr]
override-pull: |
snapcraftctl pull
sed -i -e 's|@GJS@|/usr/bin/gjs|g' src/com.github.johnfactotum.Foliate.in
build-packages:
- libgjs-dev
- gettext
stage-packages:
- gjs
organize:
snap/foliate/current/usr: usr
parse-info: [usr/share/metainfo/com.github.johnfactotum.Foliate.appdata.xml]
slots:
dbus-daemon:
interface: dbus
bus: session
name: com.github.johnfactotum.Foliate
layout:
/usr/bin/gjs:
symlink: $SNAP/usr/bin/gjs
Add an app that uses GNOME¶
apps:
foliate:
command: usr/bin/com.github.johnfactotum.Foliate
extensions: [gnome-3-38]
plugs:
- home
slots:
- dbus-daemon
common-id: com.github.johnfactotum.Foliate
Apps that use GTK3 and GNOME as runtime libraries require the gnome-3-38
extension. The extension
configures the runtime environment of the app so that all desktop functionality
is correctly initialised. As desktop environment apps, they also need special
configuration for AppStream and .desktop
file compatibility.
To add a GTK4 app:
Declare the general app keys, such as
command
,plugs
,after
, and so on.For
extensions
, addgnome-3-38
.Set
common-id
to the app’s unique AppStream ID. Doing so links the app to the.desktop
launcher specified in the AppStream file.If the app requires access to D-Bus, for
slots
, adddbus-daemon
.
Add a part written for GTK3¶
parts:
foliate:
plugin: meson
source: https://github.com/johnfactotum/foliate.git
source-branch: 1.x
meson-parameters: [--prefix=/snap/foliate/current/usr]
override-pull: |
snapcraftctl pull
sed -i -e 's|@GJS@|/usr/bin/gjs|g' src/com.github.johnfactotum.Foliate.in
build-packages:
- libgjs-dev
- gettext
stage-packages:
- gjs
organize:
snap/foliate/current/usr: usr
parse-info: [usr/share/metainfo/com.github.johnfactotum.Foliate.appdata.xml]
GTK3 parts are built with the Meson plugin.
To add a GTK4 part:
Declare the general part keys, such as
source
,override-build
,build-packages
, and so on.Set
plugin: meson
.So that the app has access to its AppStream metadata, for
parse-info
add a path to the AppStream.xml
file on the host system. Since we setadopt-info: foliate
at the start of the recipe, the AppStream file of thefoliate
part will be used to fill in thesummary
,description
andicon
of this snap and copy the AppStream file. See Using AppStream metadata for technical details about how this works.
Add required slots¶
slots:
dbus-daemon:
interface: dbus
bus: session
name: com.github.johnfactotum.Foliate
Many GTK3 apps require access to DBus in order to run correctly. If your app does, you need to explicitly grant it access as a slot:
Declare the slot key.
Set
interface: dbus
andbus: session
.Set
name
to the app’s AppStream ID.