Hello,
Great that we have the ability to minimize the NativeWindow to the system tray. Anyone have a solution how to make the application launch to the system tray immediately?
Cheers,
Timothy Grant Vogelsang
Printable View
Hello,
Great that we have the ability to minimize the NativeWindow to the system tray. Anyone have a solution how to make the application launch to the system tray immediately?
Cheers,
Timothy Grant Vogelsang
Or at least always have the icon in the system tray even when the application window is viewable?
Cheers
I think the best way to do this is have 2 windows
Your main window (as defined in application.xml) is always hidden and minimized to tray
and your second window as your "main" application window.
when the second window is minmized, hide it from the taskbar.
for the main window, have the tray icon have a menu to open the "main" window
The only trouble with what you're suggesting is that the main window can not be minimized to the system tray immediately on start. Also, if I were to take this scenario I would not want the main window to open when the icon is clicked in the system tray.
Cheers,
Timothy
well you do not actually "minimize" the window, you want to set the visibility in application.xml to false
This is possible, and its actually done in a few AIR apps I use (like Pandora Desktop) and an app I am working on. :) Unfortunately, my Aptana at work is acting up today and I cannot get it to compile/build right now, but here is some code i quickly wrote up that should give you an idea of what I mean (i cannot actually test if this works... may have some errors, apologies in advance. I'll try to test tonight when i get home)
Fixed the code i had above (there were typos and such :P)
Most of this particular coding was taken from the Adobe AIR 1.5 documentation, and as you see, I didn't use any Ext functions, although you can if you want :)
Code:// Create new window properties
var winProperties = new air.NativeWindowInitOptions();
winProperties.maximizable = true;
winProperties.minimizable = true;
// Define the size and position of the new window
var winSize = new air.Rectangle(200,200,640,480); // X position, Y Position, Width, Height
// Create the new window loader
var winLoader = air.HTMLLoader.createRootWindow(true, winProperties, true, winSize);
var mainWin = winLoader.stage.nativeWindow;
// Check if we can create a System Tray Icon
if (air.NativeApplication.supportsSystemTrayIcon) {
// Add Event Listener to the new window for display state change
mainWin.addEventListener(air.NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, function(evt) {
if (evt.afterDisplayState == air.NativeWindowDisplayState.MINIMIZED) {
// If minimized, hide the window (ie, not listed in taskbar)
mainWin.visible = false;
}
});
// By default, there is no icon for the system tray, so 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("icons/AIRApp_16.png"));
// Assign tooltip to icon
air.NativeApplication.nativeApplication.icon.tooltip = "MinToTray Example";
// Exit Function
function exitRoutine() {
air.NativeApplication.nativeApplication.exit();
};
// Create a tray menu
var trayMenu = new air.NativeMenu();
// Menu Option: Open
var winMenuOpen = trayMenu.addItem(new air.NativeMenuItem("Open"));
winMenuOpen.addEventListener(air.Event.SELECT,function() {
mainWin.visible = true; // Make visible again
mainWin.restore(); // Restore it, since it is minimized!
mainWin.orderToFront(); // Bring to front (optional)
mainWin.activate(); // Make it the active/selected window (optional)
});
// Menu Option: Exit
var winMenuExit = trayMenu.addItem(new air.NativeMenuItem("Exit"));
winMenuExit.addEventListener(air.Event.SELECT,exitRoutine);
// Assign the menu to the icon
air.NativeApplication.nativeApplication.icon.menu = trayMenu;
}
// Create and load the new window
winLoader.load(new air.URLRequest('mainwindow.html'));
// Define the "opener" window (ie THIS window, minimizetotray.html)
winLoader.window.opener = window;
Good suggestion, sorry for the late reply I'll give the above a go ;)
Cheers,
Timothy
Hello,
I had been looking all over the web for something like this explained.
Great job, and thank you for the CODE!
When I close the second window and goto tray icon then select open the code crashes...
Seems if the window was closed the code will not simply reopen it...
Would this be some soft of IF command checking to see if the window is open or closed before restoring it to the screen?
Thank you in advance.
FlinxSYS