Notes on getting autostart working for classic confined GTK app

Last night I finally managed to get a working build of the Snippet Pixie snap that pretty much works as hoped, but there were a couple of things I had to change in order to get autostart working that I thought it might help others to mention here.

There’s a couple of wrinkles due to naming.

The snap is called snippetpixie and uses that in apps:, but the binary and canonical name for the app (as used in meson build etc.) is com.github.bytepixie.snippetpixie, and that’s the app’s “ID” too. It’s a GTK app built with Vala, initially for elementary OS.

This means the .desktop file is usually called com.github.bytepixie.snippetpixie.desktop. So in the app it uses this as the desktop file name when trying to copy and fix it up to create an autostart version, but the DesktopAppInfo class failed to find the file by that name.

Turns out snapd/snapcraft takes that com.github.bytepixie.snippetpixie.desktop file and renames it to snippetpixie_snippetpixie.desktop at some point (I think install time by snapd), making some changes to the Exec line along the way.

This means the DesktopAppInfo class doesn’t recognize com.github.bytepixie.snippetpixie.desktop as valid.

In the end I had to add specific code for running as a snap to change the desktop file name to look for, and also be careful about the way the Exec line is changed for the new autostart version to carefully insert the required --start param in the altered command line instead of blindly changing it to com.github.bytepixie.snippetpixie --start.

You can see some of the altered (not very clever, but it works) code in snippetpixie’s update_autostart function.

Hope this helps someone else having troubles getting autostart to work.