Skip to content

Commit

Permalink
Fix menu API [darwin]
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislas Polu committed Oct 24, 2014
1 parent 5bf9f0c commit 7e5e645
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
25 changes: 22 additions & 3 deletions lib/api.menu.js
Expand Up @@ -12,6 +12,8 @@

var common = require('./common.js');

var os = require('os');

// ## menu
//
// API `menu` object reprensetation.
Expand All @@ -28,7 +30,8 @@ var menu = function(spec, my) {
//
// #### _public_
//
var attach; /* attach(window, cb_); */
var attach; /* attach(window, cb_); */
var set_application_menu; /* set_application_menu(cb_); */

var add_item; /* add_item(command_id, label, cb_); */
var add_check_item; /* add_check_item(command_id, label, cb_); */
Expand Down Expand Up @@ -63,7 +66,7 @@ var menu = function(spec, my) {
/****************************************************************************/
// ### attach
//
// Attaches the menu to the window passed as argument
// Attaches the menu to the window passed as argument on Linux
// ```
// @window {object} the window to attach to
// @cb_ {function(err)}
Expand All @@ -77,6 +80,17 @@ var menu = function(spec, my) {
});
};

// ### set_application_menu
//
// Sets the global application menu on OSX
// ```
// @cb_ {function(err)}
// ```
set_application_menu = function(cb_) {
that.call('set_application_menu', {}, cb_);
};


// ### add_item
//
// Adds an item with the provided `command_id` to the menu
Expand Down Expand Up @@ -199,7 +213,12 @@ var menu = function(spec, my) {
}, cb_);
};

common.method(that, 'attach', attach, _super);
if(os.platform() === 'linux') {
common.method(that, 'attach', attach, _super);
}
if(os.platform() === 'darwin') {
common.method(that, 'set_application_menu', set_application_menu, _super);
}

common.method(that, 'add_item', add_item, _super);
common.method(that, 'add_check_item', add_check_item, _super);
Expand Down
14 changes: 12 additions & 2 deletions test/menu_attach.js → test/menu.js
@@ -1,6 +1,8 @@
var async = require('async');
var common = require('../lib/common.js');

var async = require('async');
var os = require('os');

var _api = null;
var _window = null;
var _menu = null;
Expand Down Expand Up @@ -51,7 +53,15 @@ async.series([
_menu.add_submenu(6, "Test", _file, cb_);
},
function(cb_) {
_menu.attach(_window, cb_);
if(os.platform() === 'linux') {
_menu.attach(_window, cb_);
}
else if(os.platform() === 'darwin') {
_menu.set_application_menu(cb_);
}
else {
return cb_();
}
},
function(cb_) {
_window.show(cb_);
Expand Down

0 comments on commit 7e5e645

Please sign in to comment.