Send notification locally from QT/C++/QML App.
-
@lduboeuf said in Send notification locally from QT/C++/QML App.:
why an app would need to receive a notification? We just want as you said to send a notification
I guess this is push notifications, I.e the remote server sends a push notifications to an app that is suspended, to wake it up, and have it execute some code, because a new event happened server-side.
But in practice, as UT is not a widely spread plateform, I guess very few app devellopers have their Own servers, that can send a push notification, like Facebook, Whatsapp, Signal, Instagram, ect... would do. So it seems to me this thing is a good potential tool, that is not so useful in practice for now, at least not as usefull as sending a basic local notification to the notification panel from the app.
-
@lduboeuf said in Send notification locally from QT/C++/QML App.:
@pparent
Maybe you will need a version bump in your manifest.Done: does not have any effect
https://github.com/pparent76/whatsweb/commit/4c959e0ef8fb8b5e8ca6793d7c116531bd5ea497
Anyway I think I will stay with LibNotify notifications, and see if I can trigger independently some vibration (Haptic). I will need to see how to connect it to Desktop notifications of the whatsapp webview. But now I will make a pause, because I'm tired of this.
-
I actually got it working in a satisfying way form me.
1°) I've been able to have the libNotify notification stay indefinitely (even though not in the system panel), and add haptic feedback (Vibration)
2°) I've been able to detect new messages in whatsapp, by detecting a change in the WebView Title, and detecting audio playback. (For now whatsapp does not seem to send desktop notification I don't know why, because I can catch them on other pages without problem. Well even on desktop, desktop notifications from whatsapp seem eratic and unpredictable )
I will test it these days in real world use, there probably will be a few tweaks.
I've comited everything on my repo:
https://github.com/pparent76/whatsweb/tree/masterBut: If one day we have a way to send UT notifications, that go to the UT panel and does not require to be unconfined it would be ideal.
-
For anyone interested I made a small qml module, allowing desktop notifications with haptic feedback (vibration). Once again this is not optimal as the notification does not make its way to the ubuntu touch panel itself, and requires the app to be unconfined, but it is still very usable and usefull.
-
Adding dbus authorisation to "org.freedesktop.Notifications" and "com.lomiri.hfd" would solve the confinement problem. Also
Also the filtering in this file for Postal is probably buggy as I get
[POST] >> QDBusMessage(type=MethodCall, service="com.lomiri.Postal", path="/com/lomiri/Postal/alefnode_2ewhatsweb", interface="com.lomiri.Postal", member="Post", signature="", contents=("alefnode.whatsweb_whatsweb", "{"notification":{"card":{"actions":["appid://alefnode.whatsweb/whatsweb/current-user-version"],"icon":"/opt/click.ubuntu.com/.click/users/@all/alefnode.whatsweb/icon.png","persist":true,"popup":true,"summary":"Whatsapp test"},"sound":true,"vibrate":true}}") ) [POST ERROR] "An AppArmor policy prevents this sender from sending this message to this recipient; type=\"method_call\", sender=\":1.483\" (uid=32011 pid=27477 comm=\"/opt/click.ubuntu.com/alefnode.whatsweb/current/bi\" label=\"alefnode.whatsweb_whatsweb_0.2.8 (enforce)\") interface=\"com.lomiri.Postal\" member=\"Post\" error name=\"(unset)\" requested_reply=\"0\" destination=\"com.lomiri.Postal\" (uid=32011 pid=3117 comm=\"/usr/lib/lomiri-push-service/lomiri-push-service \" label=\"unconfined\")"
But anyway even unconfined postal does not work for me.
-
By the way in this push notifications profile the argument "@{APP_PKGNAME_DBUS}" used to filter Postal service is only used in this profile, and in app prushase (obviously a deprecated one). This is very suspicious.
All the other profile use variable @{APP_ID_DBUS}
This is probably a sign that this push-notification has been left abandoned for a while.
-
@pparent Not sure if this is relevant here, but notifications won't show if the app is the currently active one, i.e., shown in the foreground with unlocked screen. This is on purpose: https://gitlab.com/ubports/development/core/lomiri-push-service/-/commit/0c8983a359e9834cad4015512d57b5a29ca06937
-
@lk108 said in Send notification locally from QT/C++/QML App.:
@pparent Not sure if this is relevant here, but notifications won't show if the app is the currently active one, i.e., shown in the foreground with unlocked screen. This is on purpose: https://gitlab.com/ubports/development/core/lomiri-push-service/-/commit/0c8983a359e9834cad4015512d57b5a29ca06937
Thank's for the message, but I'm not sure to see what you mean by "notifications won't show if the app is the currently active one, i.e., shown in the foreground with unlocked screen."
In any case I would like yet to see a simple example where this notification system through POSTAL actually does work. The only example I've seen is dekko, but they have so many "notification plugins" modules in their code that it's very hard to follow what makes it work + they are running unconfined.
If someone knows how this systems works, and wants to write a minimal "Hello world" through notification example app, I think it could help many potential developers.
-
By the way intersting thing to note, having teleports and dekko installed
This does not do anything (but does not throw any error)
gdbus call --session --dest com.lomiri.Postal --object-path /com/lomiri/Postal/teleports_2eubports --method com.lomiri.Postal.Post teleports.ubports_teleports '{"message": "foobar", "notification":{"card": {"summary": "yes", "body": "hello", "popup": true, "persist": true}}}'
This triggers a notification
gdbus call --session --dest com.lomiri.Postal --object-path /com/lomiri/Postal/dekko2_2edekkoproject --method com.lomiri.Postal.Post dekko2.dekkoproject_dekko '{"message": "foobar", "notification":{"card": {"summary": "yes", "body": "hello", "popup": true, "persist": true}}}'
Why? Can anybody explain this witchcraft?
-
@pparent said in Send notification locally from QT/C++/QML App.:
By the way intersting thing to note, having teleports and dekko installed
This does not do anything (but does not throw any error)
gdbus call --session --dest com.lomiri.Postal --object-path /com/lomiri/Postal/teleports_2eubports --method com.lomiri.Postal.Post teleports.ubports_teleports '{"message": "foobar", "notification":{"card": {"summary": "yes", "body": "hello", "popup": true, "persist": true}}}'
This triggers a notification
gdbus call --session --dest com.lomiri.Postal --object-path /com/lomiri/Postal/dekko2_2edekkoproject --method com.lomiri.Postal.Post dekko2.dekkoproject_dekko '{"message": "foobar", "notification":{"card": {"summary": "yes", "body": "hello", "popup": true, "persist": true}}}'
Why?
dekko is unconfined, teleports not....
-
@lduboeuf said in Send notification locally from QT/C++/QML App.:
dekko is unconfined, teleports not....
Yes but in both case I do the dbus call from unconfined terminal, so this should not even make a difference....
Or else, its Postal itself that when receiving the call, verifies if the app is confined or not, and will only send the notification if unconfined?.... This makes no sense at all....
If we can officially send notifications only from unconfined context then it should be clearly stated, but then it's to be expected that people want to build unconfined apps...
-
@pparent At some place in the code that generates the notification popup and the entry in the notification list, there's a check if the app for which the notification is generated is currently active and shown on the screen to the user. If that's the case, generation of the popup etc. is aborted.
-
@pparent Notifications has nothing to do with the app being confined or not
-
@pparent The DBus call passes the JSON at the end of your command to the so-called push helper. This is a separate executable that is shipped with each app that supports push. Check the manifest, it defines a hook "push" which has an entry "push-helper". This entry again references a JSON with an entry "exec" pointing to the push helper executable.
The push helper is called by the system with an infile containing the JSON passed by the DBus call, and an outfile to which the push helper is expected to write a JSON in a format that is understood by the notification service.
In the case of dekko2, the push helper is just passing the content of the infile to the outfile as it is already fed something in the correct format by dekko's background service. So your command works. In the case of teleports, the push helper is expecting something else entirely, and does not know what to do with the JSON that you fed to it via your DBus call.
-
@pparent For my app, this works: https://codeberg.org/lk108/deltatouch/src/commit/d734cab514c0ee0c465b759d46c05ada322f58ca/src/plugins/DeltaHandler/notificationsLomiriPostal.cpp#L345
(but only if the app is not currently shown to the user)