5 Replies Latest reply on Aug 9, 2010 12:48 AM by Way2Death

    Restoring window

    Way2Death

      Hey,

      I'm having a bit of a problem.
      I have an Air application which can be minimized to system tray.
      But the problem is... how do I restore it?
      I've been searching for days, but can't seem to find anything that might be helpful. I've also checked the developers guide.

      So... the question is,
      How do I restore my application?

        • 1. Re: Restoring window
          thilgen Level 4

          How are you "minimizing" your main UI?

           

          Are you calling NativeWindow.minimize(), setting NativeWindow.visible = false,  or are you destroying the window?

           

          - In the first case restoring the window is as easy as calling NativeWindow.restore().

           

          - In the second, setting NativeWindow.visible = true, should do the trick.

           

          - In the third you will need to manually create the window - lots of details to doing that - which you can read about here: http://livedocs.adobe.com/flex/3/html/help.html?content=WorkingWithWindows_1.html

           

          If you are actually wondering about how to listen for mouse events on the SystemTrayIcon - you can do that by calling SystemTrayIcon.addEventListener(ScreenMouseEvent.MOUSE_DOWN) - or by adding a menu to the SystemTrayIcon and handling menu selections.

           

          You can read more about working with the SystemTrayIcon here: http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7dcc. html

           

          Hope this helps,

           

          Chris Thilgen

          AIR Engineering

          • 2. Re: Restoring window
            Way2Death Level 1

            First of all, thanks a bunch for your reply.

            I'm destroying the window when the user "minimizes" the application to the system tray.

            I've been reading the developers guide (Which is really helpful!) and used the example for system tray stated in there.

             

            Thank you for your reply,

            I will try it out when I'm at work again.

            • 3. Re: Restoring window
              Way2Death Level 1

              I've tried doing this,

              But I've failed doing so.

              The application window is being destroyed..

              I would like to do .visible = false.

               

              I've tried doing it like this:

               

              var app = air.NativeApplication.nativeApplication;
              app.addEventListener(air.Event.EXITING, closeHandler);
              function closeHandler(event)
              {
              event.preventDefault();
              this.visible = false;
              }
              
              

              But after I do this, I can't do this.visible = true again.

              TypeError: Value undefined does not allow function calls.

              Using just alert also fires the same error.

              I'm using HTML and Javascript

               

              It seems like EXITING is fired AFTER the window has been closed..

              • 4. Re: Restoring window
                thilgen Level 4

                That's correct - by the time you get the EXIT event on the NativeApplication all the NativeWindows have been destroyed.

                 

                I am unlcear as to the flow of your application - but I can take a couple of guesses - would something like this work for you?

                 

                <html>

                <head>

                <script src="AIRAliases.js" type="text/javascript"></script>

                <script>

                var t = new air.Timer(3000, 1);

                 

                function appLoad() {
                  window.nativeWindow.addEventListener(air.Event.CLOSING, onMainWindowClosing);

                 

                function onMainWindowClosing(e) {
                  air.trace( "AIR: Caught Window Closing Event: hiding the main window - APP HAS NOT EXITED - create a SystemTrayIcon with mouse handler" );
                  e.preventDefault();
                  e.target.visible = false;
                  t.addEventListener(air.TimerEvent.TIMER, onTimerEvent);
                  t.start(); // re-show the window in 3 seconds, simulating an event from the SystemTrayIcon icon
                }

                 

                function onTimerEvent(e) {
                  t.removeEventListener(air.TimerEvent.TIMER, onTimerEvent);
                  air.trace( "AIR: Timer Fired (or an event on the SystemTrayIcon was caught): showing the main window" );
                  window.nativeWindow.activate();
                }

                function quitApplication() {
                  air.NativeApplication.nativeApplication.exit();
                }

                </script>

                </head>

                <body onLoad="appLoad()">
                <button onclick="quitApplication()">"Quit Application!"</button>
                </body>

                </html>

                 

                Attaching the app desciptor and AIRAliases.js files I used to test this code...

                 

                Chris Thilgen

                AIR Engineering

                1 person found this helpful
                • 5. Re: Restoring window
                  Way2Death Level 1

                  Thanks a lot! This solved my issue.