Push notification API to a librem 5

Hi all, back when I used a iphone as my phone before the librem 5 , my go-to method of sending any kind of notification to my phone was prowl as you could define what app sent the notification and anything that could send a curl / email / cron etc could end up as a fast / free alert without employing sms. With all that said I am looking for a lightweight, and flexible way to get alerts on my librem5 that don’t have to use sms . I am wondering if anyone is doing anything similar that I have not stumbled across thought of…

Net Nut

2 Likes

The Arch wiki has a whole page on sending notifications. The most accessible solution appears to be the notify-send program, which you can script.

Edit: The notify-send program may not be supported on the Librem 5’s architecture but I can’t check myself.

An example usage would look like:

$ notify-send "this is a summary" "and this is the body"

1 Like

right I have used that… but it doesn’t quite lend to going across the web like say prowl or simular

1 Like

I think this may do what you want? https://ntfy.sh/
You may have to do a little scripting to bridge to the notify-send tool mentioned before.

1 Like

Thank you so much,
this looks hopeful… I installed the arm64 package on the phone…

purism@librem5:~$ /usr/bin/ntfy --help
NAME:
ntfy - Simple pub-sub notification service

USAGE:
ntfy [OPTION…]

COMMANDS:
help, h Shows a list of commands or help for one command
Client commands:
publish, pub, send, trigger Send message via a ntfy server
subscribe, sub Subscribe to one or more topics on a ntfy server
Server commands:
access Grant/revoke access to a topic, or show access
serve Run the ntfy server
user Manage/show users

GLOBAL OPTIONS:
–debug, -d enable debug logging (default: false) [$NTFY_DEBUG]
–help, -h show help (default: false)
–log-level value, --log_level value set log level (default: “INFO”) [$NTFY_LOG_LEVEL]
–no-log-dates, --no_log_dates disable the date/time prefix (default: false) [$NTFY_NO_LOG_DATES]
–trace enable tracing (very verbose, be careful) (default: false) [$NTFY_TRACE]

Try ‘ntfy COMMAND --help’ or https://ntfy.sh/docs/ for more information.

To report a bug, open an issue on GitHub: https://github.com/binwiederhier/ntfy/issues.
If you want to chat, simply join the Discord server (https://discord.gg/cT7ECsZj9w), or
the Matrix room (https://matrix.to/#/#ntfy:matrix.org).

ntfy 1.27.2 (69d6cdd), runtime go1.18.3, built at 2022-06-23T19:19:20Z
Copyright © 2022 Philipp C. Heckel, licensed under Apache License 2.0 & GPLv2

purism@librem5:~$

I guess maybe I can have the phone subscribe to a server… I will report back what I find… but thank you much for your input

so the weird part about this on the librem5 is it does not pop up a dialiag box via notify-send (like a normal workstation would) but if I make it play an alert via padsp and a sound file in addition to notify-send that will be the only way to know the moment libnoitify receives… it’s not a libnotify problem but a notify-send issue on the librem5 . Technically you can scroll up and see it but it’s not a great on screen alert LOL. anyone else use notify-send on the librem5 ? I wonder if it’s because of phosh.

I’m in the same boat. I wrote a small Go program that connects to my self-hosted ntfy server and is supposed to show a notification anytime the server pushes one. However, I can see the notification if I pull the settings panel from the top of the screen in the notification drawer, but indeed, as @netnut404 commented, there is no notification on screen when it comes in. I really hope I don’t have to write an entire Flatpak app to achieve this :grimacing:

Anyone know of a solution/workaround?

2 Likes

I’ve read https://valadoc.org/gio-2.0/GLib.Notification.html which mentions creating a .desktop file. If you add X-GNOME-UsesNotifications=true to that file, the app will show up in the GNOME Control Center under Notifications. That will allow you to enable and disable notifications. Turning them off, resulted in a sporadic (like 1/40) pop-up notification showing. I have no idea why.

I have another avenue of exploring. Every time I call notification.Show(), I see the notification in the notification tray (no sound, no pop-up), but I do get a GLib.Error without content (meaning message is empty) in my Go program. That might have something to do with it. That’s not specific to the L5, BTW, I also get that same error on my Arch desktop (where both the Go application and notify-send work absolutely fine with both sound and pop-up notifications).

I’ll keep you posted.

2 Likes

I’ve double checked that I can create a Vala app that can create pop-up notifications (see example Notify.Notification – libnotify).

Using a more recently written Go library (golibnotify) instead of the antique go-notify (which came recommended in the Arch Wiki), I was also able to create pop-up notifications that appear consistently. That must mean notify-send is broken on PureOS/Wayland/ARM/… in some way.

I still do not get a notification sound, which is the next step. I would be sad if I would have to play a sound myself.

Edit

(Apparently, you can’t reply to a post more than 3 times without somebody else also replying in between. So that’s why an edit.)

Flare creates pop-up notifications using feedbackd. feedbackd was written by Purism as a way “to provide haptic, visual and audio feedback”. Even better than what I looked for.

Working example:

  1. First apt install libfeedback-dev libnotify-dev.
  2. Create a simple application in file notify.vala (that skips error checking for simplicity):
public static int main(string[] args) {
    string summary = "The title";
    string body = "A long description";
    string icon = "dialog-information";
    Notify.init("My test app");
    new Notify.Notification(summary, body, icon).show();
    
    Lfb.init("My test app");
    var event = new Lfb.Event("message-new-sms");
    event.trigger_feedback();
    GLib.Thread.usleep(2000000);

    return 0;
}

Build with:

$ valac -C --pkg libfeedback-0.0 --pkg libnotify notify.vala
$ sed -i '0,/^$/s//#define LIBFEEDBACK_USE_UNSTABLE_API/' notify.c
$ valac --pkg libfeedback-0.0 --pkg libnotify notify.c
$ ./notify

As you can see, we cannot build the final executable with a single invocation. That is because libfeedback requires to set the LIBFEEDBACK_USE_UNSTABLE_API macro. vala does not allow to set #define MACRO macros in source code directly, so we have to resort to a 2-stage build. Sigh.

The Thread#usleep is necessary to keep the app alive long enough so it won’t prematurely disconnect from DBus. feedbackd stops the feedback when that happens, resulting in no feedback noticeable at all.

Anyway. On my L5, this shows both a pop-up notification and plays the “SMS received” sound.

Next step is to create a Go library that delegates to this libfeedback C library, so I can finally create a pop-up notification with sound in Go as well.

(Also, I found this thread on these forums that talk about not being able to get sound with a notification. So for reference.)

5 Likes

I am just replying so that you don’t have to edit the posts for updates. I have no inputs, but it is great that you are figuring this out and sharing. It might be relevant for me, or someone else, later :+1:

2 Likes

OK, I learned how to write Go bindings for a C library using Cgo. You can find (basic) bindings for libfeedback in my go-feedback repo at SourceHut.

A basic Go app with feedback (without error checking) looks like:

package main

import (
	"time"

	feedback "git.sr.ht/~neftas/go-feedback"
	"github.com/codegoalie/golibnotify"
)

func main() {
	notifier := golibnotify.NewSimpleNotifier("my.app.id")
	notifier.Show(
		"A summary", "Some body text", "dialog-information")

	feedbacker, _ := feedback.NewFeedbacker("my.app.id")
	event, _ := feedbacker.NewEvent("message-new-instant")
	event.TriggerFeedback()

	time.Sleep(2 * time.Second)
}

On my Librem 5, this shows me a pop-up notification, makes the phone vibrate, plays the “new message” sound and flashes the LED very slowly. I’m pretty happy.

Using valgrind, I’ve noticed that the github.com/codegoalie/golibnotify library is leaking memory though, so the next step is to make I’ve made a MR to that repo that contains a bunch of frees and see if that fixes it. (Also, the internet tells me valgrind is not a tool to check a Go binary for memory leaks, but in this case, I’m pretty sure it’s correct.)

6 Likes