[Need help]: Dbus activation for project hamster snap

Hi! Guys, I’m trying to build project hamster in snap, since it’s the best time tracking software I’ve erver used , and the sad truth is that there have been no deb packages since 18.04.

I’m able to launch it, but I’m not very experience in snap and dbus. I’m seeking for advice on how to make ergonomics better.

Here’s the snap

name: hamster-snap # you probably want to 'snapcraft register <name>'
base: core18 # the base snap is the execution environment for this snap
version: "0.1" # just for humans, typically '1.2+git' or '1.3.2'
summary: snap for project hamster # 79 char long summary
description: |
  First attempt for creating a snap for project hamster.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

slots:
  dbus-hamster:
    interface: dbus
    bus: session
    name: org.gnome.Hamster

plugs:
  gnome-3-28-1804:
    interface: content
    target: $SNAP/gnome-platform
    default-provider: gnome-3-28-1804
  gtk-3-themes:
    interface: content
    target: $SNAP/data-dir/themes
    default-provider: gtk-common-themes
  icon-themes:
    interface: content
    target: $SNAP/data-dir/icons
    default-provider: gtk-common-themes
  sound-themes:
    interface: content
    target: $SNAP/data-dir/sounds
    default-provider: gtk-common-themes

apps:
  hamster-service:
    command: desktop-launch ${SNAP}/usr/lib/hamster-time-tracker/hamster-service
    plugs:
      - desktop
      - desktop-legacy
      - gsettings
      - home
    environment:
      PYTHONPATH: $SNAP/usr/lib/python2.7/dist-packages
  hamster-windows-service:
    command: desktop-launch ${SNAP}/usr/lib/hamster-time-tracker/hamster-windows-service
    plugs:
      - desktop
      - desktop-legacy
      - gsettings
      - home
    environment:
      PYTHONPATH: $SNAP/usr/lib/python2.7/dist-packages
  hamster:
    command: desktop-launch ${SNAP}/usr/bin/hamster
    desktop: usr/share/applications/hamster-time-tracker.desktop
    plugs:
      - desktop
      - desktop-legacy
      - gsettings
      - home
      - unity7
    environment:
      PYTHONPATH: $SNAP/usr/lib/python2.7/dist-packages
      LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/share/hamster-time-tracker

parts:
  desktop-gnome-platform:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: gtk
    plugin: make
    make-parameters: ["FLAVOR=gtk3"]
    build-packages:
      - build-essential
      - libgtk-3-dev
    override-build: |
      snapcraftctl build
      mkdir -pv $SNAPCRAFT_PART_INSTALL/gnome-platform
  hamster:
    # See 'snapcraft plugins'
    after: [desktop-gnome-platform]
    build-packages:
      - gettext
      - intltool
      - python-gconf
      - gconf2
    stage-packages:
      - gir1.2-gconf-2.0
      - python3-gi-cairo
      - python3-dbus
      - python3-gi
      - python3-xdg
    source: snap/src
    plugin: waf
    configflags:
      - --prefix=/usr

My biggest problem is that, in order to launch the GUI desktop file, one have to start the two process that would register on the specific dbus name.

I believe there are ways for automatic waking up service using dbus. But I’m not able to achieve this via snaps.

So currently I have to start the two service using desktop-launch(since it won’t find gtk related files if I just launch it with python)

Is there anyway I can bind a dbus slot and invoke the service anytime the name is called? Thx, any help would be welcomed.

Update:

I tried putting the dbus-1/services under /usr/share /usr/local and ~/.lcoal/share, apps still crashes…

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Hamster.WindowServer was not provided by any .service files

DBus activation is not currently supported but is something that the desktop team is working on (cc @jamesh).

Autostart of desktop files is supported though (see ‘Autostart desktop files’ in The snap format for details). I’m not sure if this fits with your application, but it might be workable until such time that activation is completed.

As an aside> I like hamster myself and am looking at this with interest :slight_smile:

Thx for your reply, though this is not my app, just tryna snapit.

Another question about auto-starting though, is there anyway I can decide the order if I want to auto-start multiple commands?

Since the main program relied on two other command being started and registered at the dbus address, I have to make sure the main program is always started after the other two.

I don’t think there is any ability to enforce ordering for autostart desktop files: it is generally intended for e.g. an instant messenger service providing an option to start on login rather than for configuring D-Bus services.

As @jdstrand said, I have a number of PRs in the pipeline to add support for D-Bus activation. It has taken a bit longer to sort out than I’d like in part due to concerns that there was no way to deal with long running desktop services during snap upgrades/removals. We’re close to a solution for that though.

Knowing that d-bus activation will come sounds awesome.
I think I can tryl run the two relying command on daemon for now.

The existing daemon support in snapd is unlikely to help you. Based on what you posted, you want a user session daemon. In contrast daemon: simple will give you a system daemon running as root, which won’t be able to communicate with the user’s session bus.

We’ll most likely have user session systemd daemons as part of the larger D-Bus activation work (one of my currently blocked PRs even provides an implementation). It is blocked on the session agent work, so we have some way to ensure they are restarted over upgrades/stopped on removal.

Got it, I’ll try manual starting it for the time being.