5 Replies Latest reply on May 29, 2018 11:33 AM by johnrellis

    Notification system

    martinl90743871 Level 1

      Hi all,


      I'd like to add a notification system in my plugin. Currently, I send email to photographers when something happens.
      But I'd like to allow them to choose either email or notification and show popup instead of emails.


      I was thinking to add a task to send a request to my server every hour or so (with an infinite loop and sleep). But I'm not sure that it's nice and efficient.


      Any ideas? Or perhaps that Lightroom sdk provide something?


      Thank you

        • 1. Re: Notification system
          johnrellis Most Valuable Participant

          Your plugin can open a dialog at any point with LrDialogs.presentModalDialog() or .message(), even if the plugin is running in background. 


          If you want to use the operating system's notification mechanism, your plugin could invoke a command-line program.  A quick Google suggests:


          Mac: macos - Send notification from command line - Ask Different

          Windows: Plastic SCM blog: How to send Windows Toast notifications from Console apps

          • 2. Re: Notification system
            martinl68902366 Level 1

            Yes, that is true.
            My problem was more about how to do it from my server to Lightroom.


            We could do polling : every X minutes send a REST request to my server to see if I need to show notification
            But it means that I send tons of request to my server. Not very efficient.


            Any clue on this?

            • 3. Re: Notification system
              johnrellis Most Valuable Participant

              More often than not, the actual fraction of network bandwidth and CPU consumed by the polling would be negligible.  Trying to avoid polling is understandable, but properly designed polling usually doesn't have a practical impact.


              To avoid polling, your plugin could open a long-running HTTP request to the server, and the server only replies when it has something to say.

              • 4. Re: Notification system
                martinl68902366 Level 1

                Thank you John for your reply.


                Do you have any example to get a properly designed polling?

                Or for a long-running HTTP?


                Thank you so much for your help,

                • 5. Re: Notification system
                  johnrellis Most Valuable Participant

                  Re polling, I haven't implemented anything in the LR context with HTTP.  But as a thought experiment, suppose your plugin sent a request once a minute to your server, and usually the response was "Nothing available".  For a single client, the increase in CPU on client and server and bandwidth wouldn't be measurable, I think. But as you increase the number of clients, it might turn into a real cost on the server.  But a modern Web server can handle ten small requests/second without blinking an eye. 


                  Re a long-running HTTP request, HTTP 1.1 connections are by default persistent, but they time-out after inactivity (based on default settings of most Web servers, I think).   So you'd either have to change the default setting on your Web server or have the plugin send application-level keep-alive messages when there's no activity.  Sending keep-alive messages would still be less expensive in CPU and bandwidth than polling HTTP requests, since you wouldn't have the overhead of the three-way handshake of opening and then closing TCP connections.