UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Send notification locally from QT/C++/QML App.

    Scheduled Pinned Locked Moved App Development
    21 Posts 3 Posters 819 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • pparentP Offline
        pparent @Fuseteam
        last edited by pparent

        @Fuseteam said in Send notification locally from QT/C++/QML App.:

        Another example of local notifications is dekko

        Indeed this seems interesting, apparently they have developed a QML component for notifications. Though I'm not sure if it sends notifications to UT system, or displays it within the app itself. I will test when I have time.

        Notify
        Notify is a simple component for displaying in app notifications on Ubuntu devices.
        

        https://gitlab.com/dekkan/dekko/-/tree/master/notify?ref_type=heads

        Edit: this also seems intersting but seems completly identical to what I do: https://gitlab.com/dekkan/dekko/-/blob/master/plugins/ubuntu-notification-plugin/service/pushclient.cpp?ref_type=heads

        1 Reply Last reply Reply Quote 0
        • pparentP Offline
          pparent
          last edited by pparent

          I have included in my code pushclient.cpp and pushclient.h from dekko ( https://gitlab.com/dekkan/dekko/-/blob/master/plugins/ubuntu-notification-plugin/service/pushclient.cpp?ref_type=heads ) . I've commited the code to my github repo.

          Seems very interesting but nothing happens in the notification pannel whatever I do.... And furthermore Dbus calls seem prohibited inside apparmor...

          phablet@ubuntu-phablet:~$  /opt/click.ubuntu.com/alefnode.whatsweb/current/bin/whatsweb
          [COUNT] >> Updating launcher count
          [PATH] >>  "/com/lomiri/Postal/alefnode_2ewhatsweb"
          [COUNT] >> Updated.
          [PATH] >>  "/com/lomiri/Postal/alefnode_2ewhatsweb"
          [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 SUCCESS] >> Message posted.
          [COUNT] >> Updating launcher count
          [PATH] >>  "/com/lomiri/Postal/alefnode_2ewhatsweb"
          [COUNT] >> Updated.
          [QPA] QMirClientClientIntegration: connection to Mir server failed.
          
          Mir returned: "Failed to connect: not accepted by server"
          phablet@ubuntu-phablet:~$ aa-exec -p alefnode.whatsweb_whatsweb_0.2.8   -- /opt/click.ubuntu.com/alefnode.whatsweb/current/bin/whatsweb %U
          [COUNT] >> Updating launcher count
          [PATH] >>  "/com/lomiri/Postal/alefnode_2ewhatsweb"
          [COUNT] >> Updated.
          [PATH] >>  "/com/lomiri/Postal/alefnode_2ewhatsweb"
          [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\")"
          Failed to show notification: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.484" (uid=32011 pid=27477 comm="/opt/click.ubuntu.com/alefnode.whatsweb/current/bi" label="alefnode.whatsweb_whatsweb_0.2.8 (enforce)") interface="org.freedesktop.Notifications" member="GetServerInformation" error name="(unset)" requested_reply="0" destination=":1.51" (uid=32011 pid=2818 comm="lomiri --mode=full-greeter " label="unconfined")
          [QPA] QMirClientClientIntegration: connection to Mir server failed.
          
          Mir returned: "Failed to connect: not accepted by server"
          
          1 Reply Last reply Reply Quote 0
          • pparentP Offline
            pparent
            last edited by pparent

            Important Note: If I Compile the app with an "Unconfined" apparmor profile I can get notification with libnotify (and not with com.lomiri.Postal), but, it does no make its way to the notification panel in the system tray, and does not trigger any sound or vibration or status LED. It might actually be a temporary solution.

            1 Reply Last reply Reply Quote 0
            • lduboeufL Offline
              lduboeuf
              last edited by

              I'm not sure if you can use the indocator message without being unconfined or without using the Postal, or app armor tuning
              Maybe one way to make sure is monitoring dbus (dbus-monitor --session) when a persistant message hppen, it could be a calendar event remnder and see what is happening, which method is called.

              lduboeufL pparentP 2 Replies Last reply Reply Quote 0
              • lduboeufL Offline
                lduboeuf @lduboeuf
                last edited by lduboeuf

                i'm not sure also how it works for calendar app ( which is confined app) but there is some push-notification configs there: https://gitlab.com/ubports/development/apps/lomiri-calendar-app
                But the notificzation is not done by the app itself but from the datetime indicator iirc
                https://github.com/AyatanaIndicators/ayatana-indicator-datetime/blob/main/src/notifications.cpp

                1 Reply Last reply Reply Quote 0
                • pparentP Offline
                  pparent @lduboeuf
                  last edited by

                  @lduboeuf

                  Thank you but what I don't understand, is the even being unconfined I cannot get it to work by calling Postal via dbus, even when copying dekko code. It only kind of works with libnotify, but does not make its way into the system tray.

                  I honestly think the notification system should be way easier for app developers, it's a basic feature.

                  lduboeufL 1 Reply Last reply Reply Quote 0
                  • lduboeufL Offline
                    lduboeuf @pparent
                    last edited by lduboeuf

                    @pparent said in Send notification locally from QT/C++/QML App.:

                    @lduboeuf

                    Thank you but what I don't understand, is the even being unconfined I cannot get it to work by calling Postal via dbus, even when copying dekko code. It only kind of works with libnotify, but does not make its way into the system tray.

                    I honestly think the notification system should be way easier for app developers, it's a basic feature.

                    Yes indeed, but popup notification is not the same than indicator messge. the former is based on the freedesktop spec the other is a custom recipe.

                    I don't know why it would not work by being unconfined, maybe something to do with the appid ?
                    This CLI method seems to do the job

                    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}}}"'

                    I guess that to work, app need some configs via files like in dekko

                    lduboeufL 1 Reply Last reply Reply Quote 0
                    • lduboeufL Offline
                      lduboeuf @lduboeuf
                      last edited by

                      Also Teleport App use Postal too:
                      https://gitlab.com/ubports/development/apps/teleports/

                      lduboeufL 1 Reply Last reply Reply Quote 0
                      • lduboeufL Offline
                        lduboeuf @lduboeuf
                        last edited by

                        I've quickly looked at your repo, you are missing all the config files needed, even if the example is in QML, it shows the config needed https://docs.ubports.com/en/latest/appdev/guides/pushnotifications.html

                        pparentP 1 Reply Last reply Reply Quote 0
                        • pparentP Offline
                          pparent @lduboeuf
                          last edited by pparent

                          @lduboeuf

                          Thank's

                          I've added all the required files:

                          https://github.com/pparent76/whatsweb/commit/4be3c40fa6e692b2c6331dff771f169a829634f2

                          It does not work any better.....

                          Really I don't understand how this can get so insanely complex for something as basic as send a notification... It sure will not help app development on the platform.

                          lduboeufL 2 Replies Last reply Reply Quote 0
                          • lduboeufL Offline
                            lduboeuf @pparent
                            last edited by lduboeuf

                            @pparent said in Send notification locally from QT/C++/QML App.:

                            @lduboeuf

                            Thank's

                            I've added all the required files:

                            https://github.com/pparent76/whatsweb/commit/4be3c40fa6e692b2c6331dff771f169a829634f2

                            It does not work any better.....

                            Really I don't understand how this can get so insanely complex for something as basic as send a notification... It sure will not help app development on the platform.

                            Maybe you will write a HowTo and find that was not so complex later ๐Ÿ˜‰
                            The hard part is gathering informations, find the good doc and examples.

                            pparentP 1 Reply Last reply Reply Quote 0
                            • lduboeufL Offline
                              lduboeuf @pparent
                              last edited by

                              @pparent
                              Maybe you will need a version bump in your manifest.

                              pparentP 1 Reply Last reply Reply Quote 0
                              • pparentP Offline
                                pparent @lduboeuf
                                last edited by pparent

                                @lduboeuf

                                No but I mean even with good documentation I don't see any reason why you need to create/edit 10 files, with many possibilities to make a mistake, to send a notification.

                                To my mind it should be as simple as something [NOT WORKING EXAMPLES]

                                import Lomiri.Notifications 1.0
                                
                                .....
                                LomiriNotify("title","body");
                                

                                or

                                #include <Lomiri/notifications>
                                
                                .....
                                LomiriNotify("title","body");
                                

                                Possibly changing the apparmor profile, to add a notification profile, but nothing more.

                                lduboeufL 1 Reply Last reply Reply Quote 0
                                • lduboeufL Offline
                                  lduboeuf @pparent
                                  last edited by

                                  @pparent said in Send notification locally from QT/C++/QML App.:

                                  @lduboeuf

                                  No but I mean even with good documentation I don't see any reason why you need to create/edit 10 files, with many possibilities to make a mistake, to send a notification.

                                  To my mind it should be as simple as something [NOT WORKING EXAMPLES]

                                  import Lomiri.Notifications 1.0
                                  
                                  .....
                                  LomiriNotify("title","body");
                                  

                                  or

                                  #include <Lomiri/notifications>
                                  
                                  .....
                                  LomiriNotify("title","body");
                                  

                                  Possibly changing the apparmor profile, to add a notification profile, but nothing more.

                                  Yes, just someone who need to do that ^ ^, but we have also the confinement model which makes it more difficult. Hope you will find something that fit our needs.
                                  Now Qt have made a wrapper for notification, but this doesn't work on our platform yet: https://doc.qt.io/QtApplicationManager/qml-qtapplicationmanager-notification.html#details

                                  I don't understand well also all that stuff, especially https://gitlab.com/ubports/development/core/lomiri-push-service/-/blob/main/docs/highlevel.txt#L51 , why an app would need to receive a notification? We just want as you said to send a notification
                                  https://gitlab.com/ubports/development/core/lomiri-push-service/-/blob/main/docs/lowlevel.txt

                                  pparentP 1 Reply Last reply Reply Quote 0
                                  • pparentP Offline
                                    pparent @lduboeuf
                                    last edited by pparent

                                    @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.

                                    1 Reply Last reply Reply Quote 0
                                    • pparentP Offline
                                      pparent @lduboeuf
                                      last edited by pparent

                                      @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.

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post