My project initially used the default build setup from the Python template of GNOME Builder and to support a dev/prod split, I just now setup the build process of my project similar to Gnome Secrets. My plan is to activate development mode by adding .Devel to the app ID and adding a -Dprofile=development to the config-opts of the flatpak manifest.
While the general structure of my code still remains similar to the GNOME Builder template with the flatpak manifest at the root level, I now replaced the hard-coded app IDs in the data files by an application_id variable defined in the root meson.build file. The resource files are all template files (suffix: .in or .in.in), analogous to GNOME Secrets and meson.build stores them basically as {application_id}.xml, e.g., org.example.MyApp.Devel.xml.
When I start the application without the .Devel suffix on the app ID, referencing resources in the *.ui files works fine and the style sheet is loaded as well. When I launch the app in development mode, however, these do not show up and the app uses the GTK4 default style. Nevertheless, the following
does show the correct contents of my gresource file. @Gtk.Template also works fine. It’s just the automatic resolving of my custom icons and style sheet that don’t work. I already tried different names for my gresource file, such as
myapp.gresource (initial choice)
org.example.MyApp.gresource
org.example.MyApp.Devel.gresource
But none of them worked.
I really appreciate any help here because at this point, I really don’t know how to go on debugging this issue. The mechanism of loading these icons and style sheet is not transparent to me, it “just happens” automatically. GNOME Secrets apparently also doesn’t explicitly load these resources, i.e., I cannot find any code related to loading style sheets or icons from their gresources file in their code base.
If you don’t do so, Gio Application derives it from the app ID, which likely breaks your resources unless you’re also patching the path in the gresources XML.
Thank you very much for this hint. According to your pointer, I used Gio.Application.get_resource_base_path to check my current resource base path and it indeed matches my resources. Furthermore, I did not find any call to Gio.Application.set_resource_base_path in my reference applications, Gnome Music and Secrets. So, I’m missing something here.
However, in the current state of my application, it crashes with the following error:
Failed to register: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: org.freedesktop.DBus.Error.ServiceUnknown
Ok, thanks. My fault, I searched for get_resource_base_path and not resource_base_path. In fact, both set the resource base path explicitly, so I should do it as well.
For some unknown reason, the DBus error arises when I call the gresources file {application_id}.Devel.gresource. When I remove the .Devel postfix from both the meson.build file and the gresource_path in main, it disappears. At this point, I’m not sure what my application has to do with DBus, if someone knows, I would really appreciate an explanation.
After submitting the resource_base_path to my application’s super call, it works: