Send notification locally from QT/C++/QML App.
-
@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) -
Ok then let's agree on a minimalist example that should work. Can you see why this minimalist example does NOT work?
https://github.com/pparent76/UT-notify-example
It does not work, when dbus calls are made from the code, but it does not work either with the terminal command (Whether the app is visible or not when the call is made, it does not change anything)
gdbus call --session --dest com.lomiri.Postal --object-path /com/lomiri/Postal/notify_2epparent --method com.lomiri.Postal.Post notify.pparent_notify '{"message": "foobar", "notification":{"card": {"summary": "yes", "body": "hello", "popup": true, "persist": true}}}'
-
@pparent Three things:
- In your manifest, you define a hook "notify-notify", but it should be "push":
[...] "hooks": { "notify": { "apparmor": "notify.apparmor", "desktop": "notify.desktop", "content-hub": "content-hub.json" }, "push": { "apparmor": "notify-push.apparmor", "push-helper": "notify-push-helper.json" } }, [...]
- You need to install the push helper with execution rights in CMakeLists.txt:
install(PROGRAMS pushexec DESTINATION ${CMAKE_INSTALL_PREFIX})
- I was not aware, but there actually seems to be a difference between confined and unconfined apps. The push helper of dekko is allowed to use
cp
, but for your app, it's not. So instead of the simple bash script that just sayscp $1 $2
, use python in yourpushexec
:
#!/usr/bin/python3 import sys f1, f2 = sys.argv[1:3] open(f2, "w").write(open(f1).read())
With this, your gdbus line works.
-
@lk108 said in Send notification locally from QT/C++/QML App.:
install(PROGRAMS pushexec DESTINATION ${CMAKE_INSTALL_PREFIX})
Ok it works!!! Thanks!
I guess this was the missing piece that I had seen nowhere else. ( Having PROGRAM instead of files )
I will make a version of whatsapp app with these notifications next.
Though, I still think this is not normal that it requires so many specific tweaks to do something as simple as sending a notification. At least my repo will possibly serve as a documentation for someone looking for that.
-
@pparent said in Send notification locally from QT/C++/QML App.:
I guess this was the missing piece that I had seen nowhere else. ( Having PROGRAM instead of files )
I found this by checking
journalctl -f
on the device while calling gdbus -
Ok in this version of whatsweb I have the notifications working without being unconfined, and it gets to the system panel! (Provided the app is not suspended in background)
https://github.com/pparent76/whatsweb/tree/778f2302414f75029b22ea42a136fce3440f7a29
-
@pparent said in Send notification locally from QT/C++/QML App.:
Ok in this version of whatsweb I have the notifications working without being unconfined, and it gets to the system panel! (Provided the app is not suspended in background)
https://github.com/pparent76/whatsweb/tree/778f2302414f75029b22ea42a136fce3440f7a29
congrats for your perseverance. Now you are in the perfect situation to update or create a documentation