GNOME Bugzilla – Bug 627923
GtkApplication could help with enabling application autostart
Last modified: 2018-05-24 12:42:04 UTC
It would be good if GtkApplication could provide an easy means to enable/disable the starting of an application at login. Quite a few apps include logic similar to [1][2] that copies the desktop file from /usr/share/applications to ~/.config/autostart/ Does GtkApplication have knowledge of the desktop file (or GDesktopAppInfo) that belongs to it so it could install itself into the autostart dir (at least on Unix?) [1] http://git.gnome.org/browse/conduit/tree/conduit/utils/AutostartManager.py
Moving .desktop files around is the wrong way to do this, because the user/sysadmin/distro might add the application's .desktop file to one of the system autostart directories, in which case the application *would* be autostarted, but it would believe that it *wasn't* being autostarted (because it wouldn't see a .desktop file in ~/.config/autostart), and it would offer a broken "enable/disable autostart" checkbox that had no effect. The right way to do this is for the application to always install a .desktop file into /etc/xdg/autostart, containing: OnlyShowIn=GNOME AutostartCondition=GNOME /path/to/gconf/key and then have the "enable/disable autostart" checkbox be keyed to that GConf key. gnome-session will then autostart the app if and only if that key is set true. (So set its default value in the schema to false if you want the app to not be autostarted by default. And then if the sysadmin/distro wants to change the app to be autostarted by default, they just override the schema, but that will be visible to the app.)
(In reply to comment #1) > Moving .desktop files around is the wrong way to do this, because the > user/sysadmin/distro might add the application's .desktop file to one of the > system autostart directories, in which case the application *would* be > autostarted, but it would believe that it *wasn't* being autostarted (because > it wouldn't see a .desktop file in ~/.config/autostart), and it would offer a > broken "enable/disable autostart" checkbox that had no effect. > > The right way to do this is for the application to always install a .desktop > file into /etc/xdg/autostart, containing: > > OnlyShowIn=GNOME > AutostartCondition=GNOME /path/to/gconf/key If applications wishing to autostart must *always* install such a desktop file in addition to their main desktop file, isn't that redundant? Why not skip requiring the AutostartCondition=GNOME foo line, and get gnome session look in /path/to/gsettings-list-of-apps/desktopfilename by default? If desktopfilename exists, start it... Anyway, I'm just surprised that it doesn't seem easy to autostart and app on a per user basis without admin rights (or requiring apps to install two desktop files). Thanks for the advice though. Perhaps a recipe for this should be written down somewhere, google codesearch reveals quite a few apps implementing the desktop file copying approach.
(In reply to comment #2) > If applications wishing to autostart must *always* install such a desktop file > in addition to their main desktop file, isn't that redundant? Yes, but that's how the freedesktop autostart spec says to do it, and this was originally supposed to have been a cross-desktop feature (http://lists.freedesktop.org/archives/xdg/2007-January/007436.html). Of course, that didn't pan out, so we could just change it. Shrug.
Moving this to GApplication
The latest version of the logic for managing this lives here (python, in gnome-tweak-tool) http://git.gnome.org/browse/gnome-tweak-tool/tree/gtweak/utils.py#n62 It accepts the application desktop file, and the application autostart desktop file (if different). The class currently * creates an autostart file in ~/.local if needed. This is typically a copy of the application desktop file with the exec argument (optionally modified) * doesnt fight with those autostart files that have AutostartCondition stanzas * plays well with gnome-session-properties (which writes X-GNOME-Autostart-enabled=false to the ~/.local autostart file if manually disabled
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/337.