Any one know snap service (with root permission) have capability to do below jobs?
- send notification to user
- use GTK library for UI
It seems that we need to use user service (refer to : https://snapcraft.io/docs/system-usernames).
But it’s still fail, and there is no any idea so far…
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 …
Many thanks for your feedback.
Is there any example or information about a user session service (autostart app)?
The autostart documentation
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:
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/
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
I just found seems that we could add desktop file in /etc/xdg/autostart/ for all user, I will try it later and keep posted.
it has to be run as part of the snap’s
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?
Is possible to copy *.desktop to $SNAP_USER_DATA/.config/autostart/ (not root user) automatically when user install snap package?
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.
May I create plug to access /etc folder, and then add user systemd service to /etc/systemd/user/default.target.wants/hello-world.service ?
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.