1
votes

I am using NW.js to create a standalone application for Mac OS X. The application launches fine, but the application menu (just to the right of the Apple menu) contains no items. I had understood that a default set of menus and menu items would be created, as shown in this screenshot, taken from Arvind Ravulavaru' tutorial.

Here are my bare-bones files:

index.html

<!DOCTYPE html>
<html>
<head>
  <title>Hello World</title>
</head>
<body>
  <h1>Hello World</h1>
</body>
</html>

package.json

{
  "name": "Hello World"
, "version": "0.0.1"
, "description": "Barebones NW.js app"
, "main": "index.html"
, "window": {
    "toolbar": false
  , "width": 800
  , "height": 600
  }
, "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  }
, "author": ""
, "license": "MIT"
}

Here are my steps:

  1. Select index.html and package.json and use Finder's File > Compress 2 items to create a ZIP file from them.
  2. Rename this ZIP file app.nw
  3. Download the 64-bit build of NW.js for Mac OS X
  4. Unzip the downloaded file, to create a folder contain nwjs.app
  5. Right-click on the nwjs.app and choose Show Package Contents from the contextual menu
  6. Navigate to nwjs.app/Content/Resources
  7. Place the app.nw file inside this Resources folder Zipping the index.html and package.json files, renaming the zipped file app.nw and placing it in the nwjs.app/Content/Resources/ folder
  8. Modify the file at nwjs.app/Content/Info.plist so that <key>CFBundleName</key> is associated with <string>Hello World</string>. (This defines the name of the application menu.)
  9. Rename the nwjs.app as HelloWorld.app
  10. Right-click on the HelloWorld.app and select Open from the contextual menu
  11. Enter an admin username and password to allow the app to open
  12. Click the Hello World application menu — nothing happens apart from a highlight

enter image description here

What do I need to do to get a functional application menu, with a Quit item to close the app?

1

1 Answers

1
votes

A Google search for nwjs default menu mac led me to Dickson Tam's nwjs-osx-menu npm package.

My additional steps were:

  1. In a Terminal window, cd to the folder containing the main index.html file
  2. Run npm install nwjs-osx-menu. This adds (a node-modules folder containing) a folder named nwjs-osx-menu.
  3. In a text editor, open the file nwjs-osx-menu/index.js
  4. Change the line mb.createMacBuiltin('My App'); to mb.createMacBuiltin('Hello World');
  5. Create a new ZIP, including the new nwjs-osx-menu folder
  6. Rename the zip file as app.nw
  7. Replace the existing file at HelloWorld.app/Content/Resources/app.nw with the new one
  8. Launch the HelloWorld.app

Hello World application with default menus on Mac OS X