1
votes

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.

1
how did you managed to create a a new custom menu ? I can't seem to be able to create either a custom one :S Do you have any code example ? - barbasa
I posted my solution below - Alex Haines

1 Answers

2
votes

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;