Snap service access user gui

Hi there,

Any one know snap service (with root permission) have capability to do below jobs?

  1. send notification to user
  2. 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…

Best regard, Paddy

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 …

1 Like

Hi ogra,

Many thanks for your feedback. :slight_smile: Is there any example or information about a user session service (autostart app)?

see:

The autostart documentation

1 Like

Hi Orga,

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. :frowning:

apps:
  myapp-service:
    command: bin/myapp-service
    autostart: myapp-service.desktop
    plugs:
      - desktop
      - desktop-legacy
      - unity7
      - x11
      - home

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…

1 Like

Hi Orga,

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 :slight_smile:

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 command-chain list:

apps:
  my-app-service:
    command: bin/myapp-service
    command-chain:
      - path/to/script/ogra/provided
    autostart: myapp-service.desktop

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.

1 Like

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?

Many thanks :slight_smile:

Hi Orga,

Is possible to copy *.desktop to $SNAP_USER_DATA/.config/autostart/ (not root user) automatically when user install snap package?

thanks

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.

3 Likes

Hi Jamesh,

May I create plug to access /etc folder, and then add user systemd service to /etc/systemd/user/default.target.wants/hello-world.service ?

e.g. plugs

    interface: system-files
    write:
      - /etc/systemd/user/default.target.wants/hello-world.service
    read:
      - /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.

1 Like