I’ve just pushed a set of patches to gnome-software master that allow people to compile out-of-tree gnome-software plugins.
In general, building things out-of-tree isn’t something that I think is a very good idea; the API and ABI inside gnome-software is still changing and there’s a huge benefit to getting plugins upstream where they can undergo review and be ported as the API adapts. I’m also super keen to provide configurability in GSettings for doing obviously-useful things, the sort of thing Fleet Commander can set for groups of users. However, now we’re shipping gnome-software in enterprise-class distros we might want to allow customers to ship thier own plugins to make various business-specific changes that don’t make sense upstream. This might involve querying a custom LDAP server and changing the suggested apps to reflect what groups the user is in, or might involve showing a whole new class of applications that does not conform to the Linux-specific “application is a desktop-file” paradigm. This is where a plugin makes sense, and something I’d like to support in future updates to RHEL 7.
At this point it probably makes sense to talk a bit about how the architecture of gnome-software works. At its heart it’s just a big plugin loader that has some GTK UI that gets created for various result types. The idea is we have lots of small plugins that each do one thing and then pass the result onto the other plugins. These are ordered by dependencies against each other at runtime and each one can do things like editing an existing application or adding a new application to the result set. This is how we can add support for things like firmware updating, Steam, GNOME Shell web-apps and flatpak bundles without making big changes all over the source tree.
There are broadly 3 types of plugin methods:
- Actions: Do something on a specific GsApp; install gimp.desktop
- Refine: Get details about a specific GsApp; is firefox.desktop installed? or get reviews for inkscape.desktop
- Adopt: Can this plugin handle this GsApp; can fwupd handle com.hughski.ColorHug2.firmware
You only need to define the vfuncs that the plugin needs, and the name is taken automatically from the suffix of the .so
file. So, lets look at a sample plugin one chunk at a time, taking it nice and slow. First the copyright and licence (it only has to be GPLv2+ if it’s headed upstream):
/* * Copyright (C) 2016 Richard Hughes * Licensed under the GNU General Public License Version 2 */
Then, the magic header that sucks in everything that’s exported:
#include <gnome-software.h>
Then we have to define when our plugin is run in reference to other plugins, as we’re such a simple plugin we’re relying on another plugin to run after us to actually make the GsApp “complete”, i.e. adding icons and long descriptions:
void gs_plugin_initialize (GsPlugin *plugin) { gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "appstream"); }
Then we can start to do something useful. In this example I want to show GIMP as a result (from any provider, e.g. flatpak or a distro package) when the user searches exactly for fotoshop
. There is no prefixing or stemming being done for simplicity.
gboolean gs_plugin_add_search (GsPlugin *plugin, gchar **values, GsAppList *list, GCancellable *cancellable, GError **error) { guint i; for (i = 0; values[i] != NULL; i++) { if (g_strcmp0 (values[i], "fotoshop") == 0) { g_autoptr(GsApp) app = gs_app_new ("gimp.desktop"); gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX); gs_app_list_add (list, app); } } return TRUE; }
We can then easily build and install the plugin using:
gcc -shared -o libgs_plugin_example.so gs-plugin-example.c -fPIC \ `pkg-config --libs --cflags gnome-software` \ -DI_KNOW_THE_GNOME_SOFTWARE_API_IS_SUBJECT_TO_CHANGE && sudo cp libgs_plugin_example.so `pkg-config gnome-software --variable=plugindir`
I’m going to be cleaning up the exported API and adding some more developer documentation before I release the next tarball, but if this is useful to you please let me know and I’ll do some more blog posts explaining more how the internal architecture of gnome-software works, and how you can do different things with plugins.