Snapcraft daemon are not able to send notifications in Ubuntu

I prepared a tiny application for Ubuntu based on the Golang. This application checks memory usage every N seconds, and if memory usage highest of M%, try to send a notification every K seconds.
This is a pretty straightforward implementation, but when I install that snap - notifications do not appear. When I run that command manually - it’s works awesome.
That application uses the notify-send CLI tool to send the notification.

That my snapcraft.yaml:

    name: low-ram-detector
    base: core18
    version: '0.1'
    summary: Monitoring of RAM and swap
    description: |
      That app monitor RAW and swap, and send notifications if RAM or swap too low.

    grade: stable
    confinement: strict

    parts:
      low-ram-detector:
        plugin: go
        go-importpath: bitbucket.org/espinpro/go-engine
        source: .
        build-packages:
          - build-essential
        stage-packages:
          - gcc
          - clang
          - libnotify-bin
        build-environment:
          - CGO_ENABLED: "1"

    apps:
      low-ram-detector:
        environment:
          LOW_RAM_DETECTOR_VERBOSE: "true"
          LOW_RAM_DETECTOR_SWAPPERCENT: "80"
          LOW_RAM_DETECTOR_PERCENT: "90"
        command: bin/low_ram_detector
        daemon: simple
        plugs:
          - desktop

Does anyone know how to fix it?

daemons are not permitted to send desktop notifications to your user session. This is not something that an interface is able to fix. You’ll need to run the app in your user session for it to be able to send you notifications.

I believe they could use the user daemon feature for this, no? I can’t seem to find the example from @jamesh for how this is enabled/used.

1 Like

If user daemons are supported now, then yes, that will work. I hadn’t seen that they’ve arrived yet so I guess I’m behind the times ;-p

Yes. A user daemon would be able to handle this. Support for user daemons is still gated behind a feature flag at the moment though. I detailed how you can test the feature out in this thread:

1 Like