Notifier-Apps: Client/Server HTTP-based desktop notifications
There are the following components:
The client
- GitHub Repository - contains version control and other resources.
- App-Notifier-Client on MetaCPAN - download, documentation, browsing and information.
A command line client written in Perl 5 that sends a message using HTTP and JSON to a URL hosting the server. E.g:
notifier notify --msg "Finished building the software project"
This can be used in shells using an idiom like:
make ; notifier notify --msg "Finished building the software project"
The server
- GitHub Repository - contains version control and other resources.
- App-Notifier-Service on MetaCPAN - download, documentation, browsing and information.
An HTTP service, implemented using Mojolicious that listens for notifier events and invokes an event hook (such as a program displaying a video along with the notified message).
One should run it on the local desktop where one wishes to be notified of the events.
The event handler
The server can be configured to invoke any arbitrary command as an event handler for when a notification arrives. Previously I used to invoke kdialog or xmessage along with mpv but it was less than ideal.
As a result, I wrote a custom event handler using python-vlc and PySide2 / PyQt5 (largely derived from an example in the python-vlc repository) that can be invoked by the server. (I guess it is the ship of Theseus all over again.)
A forwarding service
As sometimes one sets up a client to connect to a port on a remote machine, and wishes to forward the request to the locally-running service, I decided to write a simple HTTP request forwarder. Several versions of it (written in Flask / Python, Node.js and Mojolicious / Perl 5 but otherwise equivalent in their functionality) can be found in the repository.
Protocol Spec
The client should make a GET request to the /notify
endpoint of the service with the following query parameters:
cmd_id
- an optional key whose value is a UTF-8 string.text_params
- A JSON key/value object encoded as UTF-8 and then GET encoding. Recognized keys aremsg
whose value is a text to display (instead of the default one).
Example using curl:
curl 'http://localhost:6300/notify?text_params=\{"msg":"Replacement%20Message"\}'
This assumes the service is at http://localhost:6300/ .