-
26 Jul 2009 2:37 AM #1
Programmatically minimizing to tray
Programmatically minimizing to tray
Trying to work out how to programatically minimize my AIR application to the system tray.
I've tried:
But that just minimizes and doesn't go to the system tray as it does when I click the minimize button... surely I'm just overlooking something here?Code:window.nativewindow.minimize();
-
27 Jul 2009 8:05 AM #2
hey Greg,
To minimize air applications to the system tray, you have to create a tray icon. Here is a quick example:
Above code works for Windows machines. Make sure to create one for Macs as well! More details can be found on the Adobe AIR documentation site:Code:// Check if we can create a System Tray Icon if (air.NativeApplication.supportsSystemTrayIcon) { // By default, there is no icon for the system tray, so let's load one! var iconLoad = new air.Loader(); iconLoad.contentLoaderInfo.addEventListener(air.Event.COMPLETE,function(evt){ air.NativeApplication.nativeApplication.icon.bitmaps = [evt.target.content.bitmapData]; }); iconLoad.load(new air.URLRequest("/resources/icons/MyAppIcon_16x16.png")); // Assign tooltip to icon air.NativeApplication.nativeApplication.icon.tooltip = "My App"; // Create a tray menu var trayMenu = new air.NativeMenu(); var tmOpen = new air.NativeMenuItem("Show My App"); tmOpen.addEventListener(air.Event.SELECT,function() { Ext.air.NativeWindowManager.get('mainWin').activate(); }); var tmSeperator= new air.NativeMenuItem("-", true); var tmExit = new air.NativeMenuItem("Exit"); tmExit.addEventListener(air.Event.SELECT,applicationExit); trayMenu.addItem(tmOpen); trayMenu.addItem(tmSeperator); trayMenu.addItem(tmExit); // Assign the menu to the icon air.NativeApplication.nativeApplication.icon.menu = trayMenu; } function applicationExit(){ var exitingEvent = new air.Event(air.Event.EXITING, false, true); air.NativeApplication.nativeApplication.dispatchEvent(exitingEvent); if (!exitingEvent.isDefaultPrevented()) air.NativeApplication.nativeApplication.exit(); };
(AIR 1.5) http://help.adobe.com/en_US/AIR/1.5/...de46-7dcc.html
(AIR 1.1) http://help.adobe.com/en_US/AIR/1.1/...de46-7dcc.html
-
29 Jul 2009 4:29 AM #3
Hi,
I guess we cannot minimize the window into tray but we can simulate it by using the below code
We can just sayCode:window.nativeWindow.minimize(); window.nativeWindow.visible = false;
but when minimized os take care of freeing up memory, for me a 45mb application becoame 15mb.Code:window.nativeWindow.visible = false;
In the above code there is a small addition just after setting the tooltip
hope this help! if anyone find a better way of doing it let me knowCode:air.NativeApplication.nativeApplication.icon.addEventListener("click", function(){ if (!window.nativeWindow.visible) { window.nativeWindow.restore(); window.nativeWindow.visible = true; } window.nativeWindow.alwaysInFront = true; window.nativeWindow.alwaysInFront = false; air.NativeApplication.nativeApplication.activate(window.nativeWindow); });


Reply With Quote
