3 Replies Latest reply on May 1, 2015 2:37 PM by Tom Ruark

    Photoshop CC 2014 Extension - CEP Event callback is triggered multiple times per single event

    Joonass Level 1

      Trying to make my extensions listen for bunch of events and it's turning out to be a real pain in the ***.

      I'm hoping there's someone here who has a bit more experience playing around with these.

       

      I used the example code from here ( Page 43 ): http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/creativesuite/pdfs/CC14_Extension_S DK.pdf

       

      I've modified the code just a little. I removed some unnecessary things from it. I also added a counter, to try to visualize the issue.

       

      Every time I pasted the code here, the global variable seemed to duplicate. So, eeeeh...  the example code can be found here.

       

      The problem is:

      I close one document to trigger the event, but for some reason the callback seems to run multiple times.

      Even better, it doesn't seem to be super consistent about it. Sometimes it repeats only couple of times and sometimes it repeats 160 times.

      It seems like every time the extension panel is reopened, it comes up with a new number.

       

      Currently, if I close a document, it seems to trigger the callback 15 times

       

      Since this is screenshot, you'll have to take my word for it. I only closed a single document and the code ran 15 times.

      Screen Shot 2015-04-18 at 21.21.28.png

       

      Am I doing something wrong by any chance?

       

      edit:

      I believe I just found out the reason and a way to recreate the issue.

      I've occasionally tested the extension by closing and opening the panel, which seems to have caused the issue.

      It looks like every time I close and then open the panel, it... adds one more run time to the stack.

      - Refreshing the panel from chrome doesn't seem to affect it.

       

      When I restart photoshop, it resets. So after the very first opening of the panel, the event triggers the callback only once.

       

      -------

       

      I forgot to mention that the host application events work just fine without these issues.

      In fact, I tried to use documentAfterActivate before, but as far as I could find, there is no way to kind of filter out specific events within host application events.
      For instance, I can't specify something different to happen when a new document is opened.

       

       

      As very much a side note:

      documentAfterActivate has its own side effect due to the way photoshop works.

       

      It is triggered when you:

      • Create a new document
      • Open a new document
      • Switch to an open document

      It's the "Switch to an open document" part that makes this event listener also trigger when you close a document.

      Because when you close a document, photoshop switches back to the previous document and that in turn triggers the event listener when it shouldn't, I suppose.

      Of course it doesn't trigger the event when you close the last document as there is no document to switch to at that point.

       

      ...but this is beyond the scope of the original question.

        • 1. Re: Photoshop CC 2014 Extension - CEP Event callback is triggered multiple times per single event
          cbuliarca Level 3

          I had this problem also with flash panels, but I've noticed that this only happend if the panel was persistent, I've solve it by unregistering the events when the panel was closed.

          • 2. Re: Photoshop CC 2014 Extension - CEP Event callback is triggered multiple times per single event
            Joonass Level 1

            I was so tired last night that when I found out the cause of it, I never even thought about unregistering...

             

            I decided to unregister it when the panel is opened instead.
            This does indeed get rid of the issue.

             

            Thanks, cbuliarca.

             

            (function () {
            
              var csInterface = new CSInterface();
            
              function init() {
            
                   themeManager.init();
            
                   function registerPhotoshopEvent(in_eventId, register) {
                        // Added the next line
                        var register = register === "clear" ? "UnRegisterEvent" : "RegisterEvent";
                        // Modified the next line
                        var event = new CSEvent("com.adobe.Photoshop" + register, "APPLICATION");
                        event.extensionId = csInterface.getExtensionID();
                        event.appId = csInterface.getApplicationID();
                        event.data = in_eventId
                        csInterface.dispatchEvent(event);
                   }
            
                   var number = 0;
                   csInterface.addEventListener("PhotoshopCallback" , function(event) {
            
                        number = number + 1;
            
                        console.log( number );
            
                   });
            
            
                   var closeEventid = "1131180832"
                   // Added the next line
                   registerPhotoshopEvent(closeEventid, "clear");
                   registerPhotoshopEvent(closeEventid);
            
            
              }
            
              init();
            
            }());
            
            
            • 3. Re: Photoshop CC 2014 Extension - CEP Event callback is triggered multiple times per single event
              Tom Ruark Adobe Employee

              I have a fix for this for a future version of Photoshop. Please send me a private message if you want to help test out my solution and give me some information about what you are working.