7 Replies Latest reply on Jul 27, 2012 3:11 PM by robblau

    Extensions without (visible) UI?

    RorohikoKris Level 2

      Hi all,


      Question: is it possible to have extensions without a UI, or with an optional UI? I've managed to come close to getting this to work, but it seems to remain just beyond my grasp. This is using InDesign.


      What I want to achieve:I want the extension to run at all times so it can listen for documentAfterSave events even when the panel is not showing, and I want to have the 'panel visible' state persist across user sessions.


      The first thing was to get the extension to load on app startup.


      In the Lifecycle panel in the manifest editor, I unchecked 'AutoVisible' (not sure whether that was important)

      Then I added the applicationActivate event to the list of 'StartOn' events.


      That makes my extension shows up when the app starts. Cool.


      But I want to be in control of the panel visibility - i.e. if the user had the panel hidden when he last used the app, I want the extension to be hidden when the user launches the app at a later time.


      I.e. I want to save the 'visible' state for the extension panel between user sessions. I tried saving and restoring the visible state via the CSXSInterface.instance.whatchamacallit stuff, and I tried listening for state change events for WINDOW_SHOW and WINDOW_HIDE, so I could keep track and safeguard the panel's visibility state, but it looks like those events don't really work (see Harb's bug list elsewhere on this forum). I also tried moving the panel off-screen to simulate being hidden (old trick, didn't work).


      Before I give up and try a different approach (without extension builder), does anyone know whether this can be made to work?


      Another lingering doubt: suppose I got it to work, how good is the documentAfterSave event? For example, when the user closes an unsaved document, and then agrees to save the document when alerted ('Do you want to save...' dialog).


      Will the event fire early enough so I can still extract information from the document before InDesign starts tearing down the document data structures? Or will I end up in the twilight zone, where merely accessing the half-disassembled document object can cause crashes? Or will I find the document has already been closed from before the event fired?





        • 1. Re: Extensions without (visible) UI?
          Harbs. Level 6

          To make an offscreen extension, make your extension type modeless and do something like this:


                         private function preinit():void{

                              var geo:WindowGeometry = new WindowGeometry();

                              geo.topleftx = -500;

                              CSXSInterface.getInstance().requestStateChange(StateChangeEvent.WINDOW _MOVE,geo);



          You'll get a quick flash of the dialog before it moves offscreen, but it's better than nothing...


          As far as documentAfterSave goes, I'd guess that you should be okay, but I'd test to be sure...



          1 person found this helpful
          • 2. Re: Extensions without (visible) UI?
            zak.nelson Level 3

            Hi Kris,



            AutoVisible=false means that when this extension is loaded its UI is not made visible, leaving that up to the extension. Generally, panels should have AutoVisible=true so that when a user selects the panel from the menu they can be assured that it will be made visible immediately, it also ensures correct behavior when the panel is docked or closed.



            So the question is how to fix your problem?



            I would suggest breaking this into two extensions, one extension that is a vanilla panel and another modeless extension which is hidden and sits waiting for events. The hidden one should start on applicationActivate, have AutoVisible=false, and not have a <Menu> element in its manifest (so it doesn't show up in Window > Extensions). This hidden extension can then respond to the save event, it can also activate your panel on first launch.



            Does that work for your use case?

            • 3. Re: Extensions without (visible) UI?
              Harbs. Level 6

              Thanks Zak,


              Useful stuff to know. I just tried AutoVisible=false on a modaless extension and it worked like a charm!


              Hope this is useful to Kris too...



              • 4. Re: Extensions without (visible) UI?
                RorohikoKris Level 2

                Great stuff! Zak, that sounds like a viable solution; I've already got a clean separation of responsibilities in my code, with well-defined interfaces and event-driven data exchange, so I have good hope I can separate things out fairly easily. As far as I think I can handle it, I'll put the 'datamodel' in the background extension, the 'view' in the foreground extension, and a 'controller' in both to take care of the communication between the two. The two controllers would exchange stuff via CSXSEvents.


                Harbs, thanks for the little trick - that'll come in handy too at some point in tim, I am sure.


                Great stuff, thanks so much!

                • 5. Re: Extensions without (visible) UI?
                  Harbs. Level 6

                  RorohikoKris wrote:

                  The two controllers would exchange stuff via CSXSEvents.


                  You probably don't need CSXSEvents. All you need is a reference to the other extension and you can call public methods directly.




                  1 person found this helpful
                  • 6. Re: Extensions without (visible) UI?
                    RorohikoKris Level 2

                    Cool! That would make it even easier. I'll probably need some CSXSEvents (the whole project is asynchronous and event driven by nature, and the 'background' controller would need to be able to report asynchronous things happening to the 'foreground' controller), but having the foreground controller directly call public methods in the background controller in the other extension makes things easier. Great stuff. Thanks so much!

                    • 7. Re: Extensions without (visible) UI?

                      A couple questions on how to have an invisible ui.  Are there any update for getting this to work in 3.0?


                      It seems like AutoVisible=false doesn't work when using a CSExtension, but does when using mx.core.Application.  Everything else seems to work find with mx:Application, except for being able to clean up.  I have a server socket I need to close for Photoshop to exit cleanly, but I can't find any hook that'll let me both have an invisible extension and have a chance to cleanup.


                      I've tried going through PSEventAdapter, and various events on the Application, but haven't found anything yet.


                      Any ideas?