3 Replies Latest reply on Aug 11, 2009 3:40 PM by theRealEvanFlash

    Non-standard OS X behavior

    BB_Cool
      I have an app for OS X that has a main application window using standard chrome. It also has a dock icon. I am running into a dilemma trying to get the app to behave like a normal Mac app - namely, like Mac Mail, when I close the main app window, the app doesn't exit, the window goes away yet the dock icon remains.

      The base of my app is mx:WindowedApplication. I want the following behavior:
      1. when clicked on the window close button (i.e., the red bubble), the window disappears, the app continues to run;
      2. when left-clicked on the dock icon, the main window re-appears;
      3. when right-clicked on the dock icon and choose Quit, the entire app exits.

      I tried a couple of approaches and found a problem with each approach:
      Approach 1: set WindowedApplication autoExit="false". This way, I get both behaviors 1 and 3, yet I can't get 2 to happen since once 1 happens, the NativeWindow is considered closed subject to garbage collection. I don't see a way to reconstruct it or reactivate it.
      Approach 2: listen to the "closing" event on WindowedApplication, and call preventDefault() in the event handling routine. This way, I get behaviors 1 and 2. However, when I try 3 the window disappears, but the app continues to run (i.e., behave like 1). The entire app should exit in this case.

      Essentially my dilemma is that I can't seem to be able to have all three behaviors, but have to choose between two. Yet to me, having all three is the standard OS X app behavior. Any suggestions?
        • 1. Re: Non-standard OS X behavior
          tzeng Adobe Employee
          When you click the doc icon, your app. will receive an invoke event.

          You can take a look at this sample app.:
          http://www.adobe.com/devnet/air/flash/quickstart/stopwatch_dock_system_tray.html

          The sample app. behaves the way you want.

          -ted
          • 2. Re: Non-standard OS X behavior
            BB_Cool Level 1
            No, the sample stopwatch app is not the same because it doesn't use standard chrome (i.e., systemChrome=none). So, it *hides* the window when docked and shows it again when the dock icon is clicked. I can do that too. :)

            The problem comes when the CLOSE button (i.e., red bubble) in the standard OS X title bar is clicked. If I allow the event to go all the way through, then I end up with a closed nativeWindow that I can't reuse/show again. If I disallow the event (i.e., use preventDefault), and hide the window instead, I get mostly what I wants, except when one right-clicks on the dock icon and select Quit. On OS X, apparently Quit does the same as CLOSE button in the title bar. However, I don't want them to be the same. When Quit is selected, instead of hiding the window like the Close button, I want to exit the app entirely.
            • 3. Re: Non-standard OS X behavior
              theRealEvanFlash

              I think the key to what you're trying to accomplish (if you still care 8 months later :-)) is for the base of your app to be an mx:Application instead of a WindowedApplication. Your main Application instance (which need not have a corresponding visual window) could then create all your ui windows as mx.core.Window instances and control their visibility by setting the Window.visible property. This would allow you to handle the Event.CLOSING event for every window separately. It would also isolate the case in which the user quits through the dock icon.

              Hope this helps. I've used this arrangement in an app that's been in the wild for over a year now and it's served me well.