you need to split your app into two, then you can have a system wide daemon and a user session service (autostart app) and have them communicate via dbus or some (network)socket …
system-usernames wont help here since this is just for dropping privs of system daemons but it will not allow other users access …
Thanks for your help. Now I put desktop file in meta/gui/ folder in snap package, and app icon is also exist in app menu. App could run up from app menu, but autostart is not working.
About following description, it should copy desktop file manually by my application?
An application may put a desktop file under $SNAP_USER_DATA/.config/autostart
in order to be automatically started with the user’s desktop session. The file is
matched with a corresponding application based on the autostart property of an
app inside meta/snap.yaml. For example:
use a command chain script to copy it in place like:
#! /bin/sh
if [ ! -e $SNAP_USER_DATA/.config/autostart/myapp-service.desktop ]; then
mkdir -p $SNAP_USER_DATA/.config/autostart
cp -a $SNAP/meta/gui/*.desktop $SNAP_USER_DATA/.config/autostart/
fi
exec $@
indeed the user still needs to run the app once to make this happen…
Is it possible to run this script automatically when user login after install snap package? Or user should run this script by themself? I cannot find any way to do it…Many thanks for your kind help
Once the snap does that on calling the app, then the user must execute the snapped app manually the first time and thereafter it’ll autostart unless the .desktop file is removed.
After applying your code, app user service could run successfully after click app icon in app menu manually. But, is it possible the app user service is launched automatically after user install snap package , and don’t need to click app icon?
There is an experimental snapd feature to let snaps install “user daemons”: basically the same as regular daemons, but running under the user instance of systemd instead of the systemd one. There are still some bugs to iron out before it can be enabled by default though.
Until that point, you’ll need to use the autostart feature which relies on the user running your app at least once.
It is incredibly unlikely that you’d be able to publish a snap with that plug. It would effectively be a sandbox escape vulnerability. It also doesn’t solve any of the issues remaining that have blocked the user daemons feature from being enabled by default.