💾 Archived View for gmi.bacardi55.io › blog › 2021 › 12 › 11 › pinephone-sxmo-notification-matrix captured on 2023-07-22 at 16:38:06. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Posted on 2021-12-11
As many privacy focused people, one of my goal/dream is to have a fully opensource phone I can trust and run application I like and trust. One big step for me was to buy the pinephone braveheart[1] edition when it got out to start toying with it and see how it could someday become the my main driver.
1: https://wiki.pine64.org/index.php/PinePhone_v1.1_-_Braveheart
I didn't spend much time on it in early 2021, but I've been looking into it a lot more lately as I'd love to be able to remove every blocker for when the Pinephone Pro[2] is fully ready. And the awesome sxmo[3] distribution made me want to use my Pinephone more. If you like minimalist and tiling WM, sxmo might be for you :].
2: https://wiki.pine64.org/wiki/PinePhone_Pro
I'll discuss in a later blog posts all the things I want for it, but I do have specific requirements as I know I'll still have 2 phones in the future. I'll keep my android phone as my "work" phone for which I do need proprietary software like the google suite. But having a personal phone I can use the rest of the time.
I'll explain more about the exact workflow later, but one of the point is the ability to share notifications between phones so I don't miss calls/texts or others while I have only one of the phones with me.
To do this, the basic idea was to have my a private matrix room with end to end encryption where a I could send notifications from either phone and read it on my laptop. I may talk about the matrix setup adventure later on but I really enjoy it so far.
The goal of this post is really around sending notifications from the Pinephone runing sxmo[4] on the matrix room.
I won't explain how to setup a matrix server or create matrix room in this post, so I assume you already have:
The goals are simple:
First we need to install matrix-commander[5], a CLI-based Matrix client. To do so, ssh to your phone and install required libraries and clone the git repo:
5: https://github.com/8go/matrix-commander
sudo apk add libolm libolm-dev libffi-dev zlib-dev jpeg-dev python3-dev py3-pip git clone https://github.com/8go/matrix-commander.git; cd matrix-commander
I didn't need the notification dependency (dbus-python and notify2), so I created a local copy of the requirements.txt file:
cp requirements.txt requirements.local
And removed dbus-python and notify2 lines and then install the requirements and make the main file executable:
pip install -r requirements.local.txt chmod +x matrix-commander.py
Nota: I may have forgotten a few dependency, if that's the case, the error message when running the pip install … command should be self explanatory to add the missing libraries.
You should definitely read the matrix-commander README to understand basic usage, but it should be as simple as:
# initial configuration: python3 ./matrix-commander.py
And answer the question, by giving your matrix server url (matrix.homeserver), the phone username (phone@matrix.homeserver) and password, and the room to push message to. The room id can be found in the url and should start with ! (not the display name of your room that start with #).
You'll need to validate the new device to ensure encryption will work. That will be done after sending the first message. You should have another validated client open and connected with your phone account.
If everything worked, you could test sending a message via:
./matrix-commander.py -m "test message"
Then, on your other matrix client, it will ask you to validate the new client. Use the validate by emoji option and use matrix-commander to validate:
./matrix-commander.py --verify
Now all should be good, but to be "cleaner", lets move ./matrix-commander file to a more standard place:
mkdir ~/.local/share/matrix-commander && mv -i store/ ~/.local/share/matrix-commander mkdir ~/.config/matrix-commander/ && mv credentials.json ~/.config/matrix-commander/
You can try another time to send a message to ensure everything still works fine :). If that's the case, let's start working on sxmo scripts.
Sxmo is awesome as it is very configurable with simple bash scripts and hooks <3.
Sxmo has an "notification" hook that allow you to do things when receiving a notification. To do so, create a $XDG_CONFIG_HOME/hooks/notification file (usually $XDG_CONFIG_HOME is ~/.config/sxmo). The latest version of my notification hook can be found here[6].
6: https://gitlab.com/bacardi55/pinephone-sxmo/-/blob/main/hooks/notification
The idea is simple, if the "away mode" is enabled, send the notification via matrix-commander, otherwise vibrate. The away mode is simply a file (in my case $XDG_CONFIG_HOME/away_mode). If the file content is 1, away mode is enabled, if content is 0, it is disabled.
Don't forget to make the file executable (chmod +x hooks/notification) :).
Now all we need is a way to enable/disable the away mode easily. For this, I created a $XDG_CONFIG_HOME/userscripts file. This file allow you to add new lines at the start of the scripts menu. The content is quite simple:
Toggle Away Mode ^ 0 ^ /path/to/awaymode_toggle.sh
Basically, it adds a menu item in the "menu → scripts" menu at the start named Toggle Away Mode that will start the awaymode_toggle.sh script.
The latest version of the script can be found here[7] but the basic idea is that it reads the content of the $XDG_CONFIG_HOME/away_mode file and will change 0 into 1 or 1 into 0.
7: https://gitlab.com/bacardi55/pinephone-sxmo/-/blob/main/scripts55/awaymode_toggle.sh
And that's it! Toggling the away mode will either make your phone behave like default by vibrating when receiving a notification and when activated, will not vibrate but share the notification to a signal room so that you can read it anywhere :).
This is just the start of many scripts I believe, but at least now if I have only my android phone I won't miss anything from the Pinephone. I will now look into android notifications and the other blocker I have with the Pinephone. I'll try to write more about my experiences with it too on this blog soon.