Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including electron-menus with all npm packages installed. Try it out:

var electronMenus = require("electron-menus")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

electron-menus v0.1.0

Easily add menus to modules running in Electron.

Electron menus

js-standard-style

Add native menu items to renderer-side projects from the browser-side.

Installation

npm install --save electron-menus

Usage


var menus = require('electron-menus')

menus.set(__dirname + '/index.html')
set menus.set(pathToIndexFile[, menuDefinition][, settings])

Takes a pathToIndexFile, an optional menuDefinition to use, if not provided will default to menus/default.js (see that file and Electron menu documentation for more on what that array should look like) and an optional settings argument with the following defaults:

{
  id: 'ELECTRON-menus' // The id of the script tag to inject the menu definition into,
  replace: false // If a script tag of the above id already exists, should it replace its contents or leave it alones
}

Reasoning

Loading a flat file web app into Electron is quite easy, you would either hardcode those files, or, better yet, include that project as a module and point your window.loadUrl method at it.

The problem is that web app knows nothing about the native desktop context it is now in. And because basic elements like menu items, which enable Copy and Paste, must be defined on the Renderer side, your web app will feel powerless in its new environment.

You might not want to hardcode the required menu JavaScript into your web app, though if, for instance, you're using that code in multiple contexts and don't want to disable certain blocks when running in a browser versus Electron.

This module lets you inject the necessary JavaScript into the web app's index.html file.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free