Skip to content

Commit

Permalink
Add a preferences item to the OSX menu bar
Browse files Browse the repository at this point in the history
Resolve #245
  • Loading branch information
bastimeyer committed May 5, 2016
1 parent 29b155b commit 182e329
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/initializers/nwjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ define([
settings.removeObserver( "content", settings, settingsObserver );

// do all the NWjs stuff
menubar.createNativeMenuBar();
menubar.createNativeMenuBar( controller );
shortcut.createStartmenuShortcut( settings );
tray.createTrayIcon( settings );
integrations.setupIntegrations( settings );
Expand Down
26 changes: 22 additions & 4 deletions src/app/nwjs/setup/menubar.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
define([
"nwjs/nwGui",
"nwjs/nwWindow",
"nwjs/menu",
"utils/node/platform",
"json!root/metadata"
], function(
nwGui,
nwWindow,
Menu,
platform,
metadata
) {

var MenuItem = nwGui.MenuItem;
var isDarwin = platform.isDarwin;

var displayName = metadata.package.config[ "display-name" ];

function createNativeMenuBarDarwin() {

function createNativeMenuBarDarwin( controller ) {
var menubar = Menu.create({ type: "menubar" });
menubar.createMacBuiltin( displayName );
return menubar.menu;
menubar = menubar.menu;

// Add a preferences menu item to the main menubar submenu
var mainMenu = menubar.items[ 0 ].submenu;
mainMenu.insert( new MenuItem({ type: "separator" }), 1 );
var preferences = new MenuItem({
type: "normal",
label: "Preferences",
key: ",",
modifier: "cmd"
});
preferences.click = controller.send.bind( controller, "goto", "settings" );
mainMenu.insert( preferences, 2 );

return menubar;
}


return {
createNativeMenuBar: function() {
createNativeMenuBar: function( controller ) {
if ( !isDarwin ) { return; }

nwWindow.menu = createNativeMenuBarDarwin();
nwWindow.menu = createNativeMenuBarDarwin( controller );
}
};

Expand Down

0 comments on commit 182e329

Please sign in to comment.