简体   繁体   中英

Mac Node-webkit menu

I am trying to create a menu for a mac node-webkit app. I am trying to append a preferences menu item to the first/root menu(app name > about, preferences, etc). I have not been able to figure out how to access the menus that the .createMacBuiltin(); function creates. I have only been able to create a new custom menu. Has anyone figured out how to do this. See Slack's mac app for an example. Here is my code so far.

var gui = require('nw.gui');

// Create menu container
var Menu = new gui.Menu({
    type:   'menubar'
});

Menu.createMacBuiltin("Example App");

Menu.append(
    new gui.MenuItem({
        label: 'Preferences',
        click : function () {
          $('#preferences').modal('toggle');
        }
    })
);

gui.Window.get().menu = Menu;

Thanks for the help.

I solved this with the following code. It was just a matter of rooting around and finding the right menu to append or insert to. I used the menu to open a modal that has user preferences in it.

var gui = require('nw.gui');

// Create menu container
var Menu = new gui.Menu({
    type:   'menubar'
});

//initialize default mac menu
Menu.createMacBuiltin("MyApp");

// Get the root menu from the default mac menu
var rootMenu = Menu.items[0].submenu;

// Append new item to root menu
rootMenu.insert(
    new gui.MenuItem({
        label: 'Preferences',
        click : function () {
          $('#preferences').modal('toggle');
        }
    })
);

// Append Menu to Window
gui.Window.get().menu = Menu;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM