0
votes

I'm working on an Air app (JavaScript, not Flex) and I cannot make system tray (dock on Mac) menu handlers to work. I can see my custom menu when I right-click on system tray (dock) icon, but when I click on the menu items, nothing happens, callback code is not executed. Am I using a wrong event type? I could not find more information besides an article on Adobe Developer Connection and they use Event.SELECT there, but it doesn't seem to work.

var menu = new air.NativeMenu();
addMenuHandler(menu, 'Exit App', function (event) {
    air.trace("It's not even getting here when the menu item is clicked.");
});
addMenuHandler(menu, 'Log Out', function (event) {
    // TODO
});
air.NativeApplication.nativeApplication.icon.menu = menu;

// Tray/Dock Menu
if (menu && air.NativeApplication.supportsSystemTrayIcon) { // Windows
    var iconLoader = new runtime.flash.display.Loader();
    iconLoader.load(new air.URLRequest('/src/icons/app_16.png'));
    iconLoader.contentLoaderInfo.addEventListener(air.Event.COMPLETE, function (event) {
        air.NativeApplication.nativeApplication.icon.bitmaps = new Array(event.target.content.bitmapData);
        air.NativeApplication.nativeApplication.icon.tooltip = 'App';

        loadMainWindow();
    });
} else if (menu && air.NativeApplication.supportsDockIcon) { // Mac
    loadMainWindow();
}

function loadMainWindow () {
    location.href = '/main.html';
}

function addMenuHandler (menu, caption, callback) {
    var menuItem = new air.NativeMenuItem(caption);
    menuItem.addEventListener(air.Event.SELECT, callback);
    menu.addItem(menuItem);
}
2

2 Answers

1
votes
0
votes

Maybe try using more verbose approach instead of using aliases: 'window.runtime.flash.events.Event' instead of 'air.Event'?