Search code examples
webkitnode-webkit

Using gui.createMacBuiltin makes windows app now work in node webkit


Just started trying to create a menubar for my node webkit app, and I followed the instructions straight from the master Roger Wang himself...here:

https://github.com/rogerwang/node-webkit/wiki/Window-menu

Here is the code:

var gui = require('nw.gui');
var mb = new gui.Menu({type:"menubar"});
mb.createMacBuiltin("your-app-name");
gui.Window.get().menu = mb;

Works beautifully on mac, but makes the PC app not work. Any ideas now to solve it?

Thanks in advance.


Solution

  • I expect that createMacBuiltin isn't defined when you're running on non-Mac platforms. You should probably protect that code with an os-specific check, like this:

    var gui = require('nw.gui');
    var mb = new gui.Menu({type:"menubar"});
    if (process.platform === "darwin") {  // this should indicate you're on Mac OSX
        mb.createMacBuiltin("your-app-name");
    }
    gui.Window.get().menu = mb;
    

    This is assuming, of course, that the surrounding code is platform independent and you want it to run on all platforms.