After quite a lot of positive feedback from my last post I’ll write some more about custom plugins. Next up is returning custom applications into the installed list. The use case here is a proprietary software distribution method that installs custom files into your home directory, but you can use your imagination for how this could be useful.
The example here is all hardcoded, and a true plugin would have to derive the details about the GsApp, for example reading in an XML file or YAML config file somewhere. So, code:
gs_plugin_initialize (GsPlugin *plugin)
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "icons");
gs_plugin_add_installed (GsPlugin *plugin,
g_autofree gchar *fn = NULL;
g_autoptr(GsApp) app = NULL;
g_autoptr(AsIcon) icon = NULL;
/* check if the app exists */
fn = g_build_filename (g_get_home_dir (), "chiron", NULL);
if (!g_file_test (fn, G_FILE_TEST_EXISTS))
/* the trigger exists, so create a fake app */
app = gs_app_new ("example:chiron.desktop");
gs_app_set_management_plugin (app, "example");
gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
gs_app_set_state (app, AS_APP_STATE_INSTALLED);
gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
gs_app_set_summary (app, GS_APP_QUALITY_NORMAL,
"A teaching application");
gs_app_set_description (app, GS_APP_QUALITY_NORMAL,
"Chiron is the name of an application.\n\n"
"It can be used to demo some of our features");
/* these are all optional */
gs_app_set_version (app, "1.2.3");
gs_app_set_size_installed (app, 2 * 1024 * 1024);
gs_app_set_size_download (app, 3 * 1024 * 1024);
gs_app_set_origin_ui (app, "The example plugin");
gs_app_add_category (app, "Game");
gs_app_add_category (app, "ActionGame");
gs_app_add_kudo (app, GS_APP_KUDO_INSTALLS_USER_DOCS);
gs_app_set_license (app, GS_APP_QUALITY_NORMAL,
"GPL-2.0+ and LGPL-2.1+");
/* create a stock icon (loaded by the 'icons' plugin) */
icon = as_icon_new ();
as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
as_icon_set_name (icon, "input-gaming");
gs_app_set_icon (app, icon);
/* return new app */
gs_app_list_add (list, app);
This shows a lot of the plugin architecture in action. Some notable points:
- The application ID (
example:chiron.desktop) has a prefix of
example which means we can co-exist with any package or flatpak version of the Chiron application, not setting the prefix would make the UI confused if more than one
chiron.desktop got added.
- Setting the management plugin means we can check for this string when working out if we can handle the install or remove action.
- Most applications want a kind of
AS_APP_KIND_DESKTOP to be visible as an application.
- The origin is where the application originated from — usually this will be something like Fedora Updates.
GS_APP_KUDO_INSTALLS_USER_DOCS means we get the blue “Documentation” award in the details page; there are many kudos to award to deserving apps.
- Setting the license means we don’t get the non-free warning — removing the 3rd party warning can be done using
icons plugin will take the stock icon and convert it to a pixbuf of the correct size.
To show this fake application just compile and install the plugin,
touch ~/chiron and then restart gnome-software.
By filling in the optional details (which can also be filled in using
gs_plugin_refine_app() (to be covered in a future blog post) you can also make the details page a much more exciting place. Adding a set of screenshots is left as an exercise to the reader.
For anyone interested, I’m also slowly writing up these blog posts into proper docbook and uploading them with the gtk-doc files here. I think this documentation would have been really useful for the Endless and Ubuntu people a few weeks ago, so if anyone sees any typos or missing details please let me know.