electron-create-menu
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -9,3 +9,3 @@ const { app, Menu } = require("electron"); | ||
{ | ||
label: app.getName(), | ||
label: app.name, | ||
showOn: ["darwin"], | ||
@@ -12,0 +12,0 @@ submenu: [ |
{ | ||
"name": "electron-create-menu", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "provides a default menu for your electron applications, with convenience functions for multiplatform use and i18n.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,11 @@ | ||
### Made by [@kilianvalkhof](https://twitter.com/kilianvalkhof) | ||
#### Other projects: | ||
- 💻 [Polypane](https://polypane.app) - Develop responsive websites and apps twice as fast on multiple screens at once | ||
- 🖌️ [Superposition](https://superposition.design) - Kickstart your design system by extracting design tokens from your website | ||
- 🗒️ [FromScratch](https://fromscratch.rocks) - A smart but simple autosaving scratchpad | ||
--- | ||
# Electron-create-menu [![npm](https://img.shields.io/npm/v/electron-create-menu.svg)](https://www.npmjs.com/package/electron-create-menu) [![npm-downloads](https://img.shields.io/npm/dm/electron-create-menu.svg)](https://www.npmjs.com/package/electron-create-menu) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FKilian%2Felectron-create-menu.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FKilian%2Felectron-create-menu?ref=badge_shield) | ||
@@ -15,9 +25,10 @@ | ||
``` js | ||
import Menu from 'electron-create-menu'; | ||
```js | ||
import Menu from "electron-create-menu"; | ||
// or | ||
const Menu = require('electron-create-menu'); | ||
const Menu = require("electron-create-menu"); | ||
``` | ||
To get a default menu with platform-appropriate menu items and submenus, call Menu like so: | ||
``` | ||
@@ -27,3 +38,3 @@ Menu(); | ||
*Note:* This API has to be called after the `ready` event of `app` module. | ||
_Note:_ This API has to be called after the `ready` event of `app` module. | ||
@@ -33,6 +44,7 @@ Menu always returns the menu object that `Menu.buildFromTemplate` creates, so you can access [instance methods](https://electronjs.org/docs/api/menu#instance-methods) on it. | ||
### Optional arguments | ||
Menu has two optional functions you can pass it | ||
* The first argument is the `callback` function, where you can further edit (or replace) the generated menu. | ||
* The second argument is the `i18n` function where you can supply a function to use for translating the menu items. | ||
- The first argument is the `callback` function, where you can further edit (or replace) the generated menu. | ||
- The second argument is the `i18n` function where you can supply a function to use for translating the menu items. | ||
@@ -44,20 +56,23 @@ ```js | ||
### The callback function | ||
`callback` receives two arguments: | ||
* The generated menu | ||
* A function that returns `{type: 'separator'}` for convenience. | ||
- The generated menu | ||
- A function that returns `{type: 'separator'}` for convenience. | ||
It expects you to return a menu-like object, either the edited default menu or a new menu. | ||
#### Callback example | ||
To append a menu item to the menu, push an object onto menu and return it: | ||
```js | ||
Menu((defaultMenu, separator) => { | ||
defaultMenu.push({ | ||
label: 'My custom menu!', | ||
label: "My custom menu!", | ||
submenu: [ | ||
{label: 'my first item'}, | ||
{ label: "my first item" }, | ||
separator(), | ||
{label: 'my second item'}, | ||
], | ||
{ label: "my second item" } | ||
] | ||
}); | ||
@@ -70,8 +85,10 @@ | ||
### The i18n function | ||
The i18n function is applied to the labels of the default menu. There are two things worth mentioning: | ||
* Most items in the default menu are specified by a _role_, so the OS will supply the translation. | ||
* Labels added in the callback function are not translated by this function. | ||
- Most items in the default menu are specified by a _role_, so the OS will supply the translation. | ||
- Labels added in the callback function are not translated by this function. | ||
#### Example using i18next | ||
```js | ||
@@ -105,10 +122,15 @@ const i18next = require('i18next'); | ||
## Multiplatform use | ||
Each item in your menu can have two new properties, `showOn` and `hideOn`. These accept a string or an array of strings that correspond to `process.platform` values such as 'darwin' or 'win32'. | ||
```js | ||
// this shows the menu item only on macOs | ||
{ showOn: 'darwin' } | ||
// this shows the menu item only on macOs | ||
{ | ||
showOn: "darwin"; | ||
} | ||
// this hides the menu item on windows and macOs | ||
{ hideOn: ['win32', 'darwin'] } | ||
// this hides the menu item on windows and macOs | ||
{ | ||
hideOn: ["win32", "darwin"]; | ||
} | ||
``` | ||
@@ -121,2 +143,3 @@ | ||
#### Example | ||
```js | ||
@@ -143,6 +166,7 @@ Menu((defaultMenu, separator) => { | ||
``` | ||
## License | ||
Electron-create-menu is ISC licensed. | ||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FKilian%2Felectron-create-menu.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FKilian%2Felectron-create-menu?ref=badge_large) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9423
165