All Projects → Kilian → Electron Create Menu

Kilian / Electron Create Menu

Licence: isc
a default menu for your electron applications, with convenience functions for multiplatform use and i18n.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Electron Create Menu

V Selectmenu
SelectMenu for Vuejs, A simple, easier and highly customized menu solution
Stars: ✭ 169 (+382.86%)
Mutual labels:  i18n, menu
Python Packaging Tutorial
Tutorial on python packaging
Stars: ✭ 34 (-2.86%)
Mutual labels:  cross-platform
Zeus
A high performance, cross-platform Internet Communication Engine. Developed with native socket API. Aim at handling millions of concurrent connections.
Stars: ✭ 30 (-14.29%)
Mutual labels:  cross-platform
Parrot
Self-hosted Localization Management Platform built with Go and Angular
Stars: ✭ 967 (+2662.86%)
Mutual labels:  i18n
Corpus Christi
Church management suite, open source, fully internationalized
Stars: ✭ 29 (-17.14%)
Mutual labels:  i18n
Pushclient
A cross-platform method of using Firebase Cloud Messaging (FCM) to receive push notifications
Stars: ✭ 33 (-5.71%)
Mutual labels:  cross-platform
Dotfeather
A closs-platform generic gameengine built on C#/.NET Standard 2.1
Stars: ✭ 28 (-20%)
Mutual labels:  cross-platform
Revery
⚡ Native, high-performance, cross-platform desktop apps - built with Reason!
Stars: ✭ 7,812 (+22220%)
Mutual labels:  cross-platform
Expo Stack
🎮🧱 stack game clone made in expo (ios, android, web), three.js, react native
Stars: ✭ 34 (-2.86%)
Mutual labels:  cross-platform
Tomanocupacero
Uma CLI cross-platform que reproduz um áudio do Mc Poze em loop. "toma no cu pacero to chei de ódio"
Stars: ✭ 33 (-5.71%)
Mutual labels:  cross-platform
Fepopupmenucontroller
A simple, elegant pop-up menu view
Stars: ✭ 32 (-8.57%)
Mutual labels:  menu
Sandpolis
Experimental remote monitoring and management
Stars: ✭ 30 (-14.29%)
Mutual labels:  cross-platform
Parse Decimal Number
🏧 Parse a decimal number with i18n format support (localized decimal points and comma separators)
Stars: ✭ 33 (-5.71%)
Mutual labels:  i18n
Timeline
Awesome UI: Timeline with images in Xamarin.Forms.
Stars: ✭ 29 (-17.14%)
Mutual labels:  cross-platform
Mvvmlight
The main purpose of the toolkit is to accelerate the creation and development of MVVM applications in Xamarin.Android, Xamarin.iOS, Xamarin.Forms, Windows 10 UWP, Windows Presentation Foundation (WPF), Silverlight, Windows Phone.
Stars: ✭ 973 (+2680%)
Mutual labels:  cross-platform
Flowingmenu
Interactive view transition to display menus with flowing and bouncing effects in Swift
Stars: ✭ 946 (+2602.86%)
Mutual labels:  menu
I18n.cr
Internationalization API ( i18n )
Stars: ✭ 31 (-11.43%)
Mutual labels:  i18n
Keyvast
KeyVast - A key value store
Stars: ✭ 33 (-5.71%)
Mutual labels:  cross-platform
Ununiga
[은는이가] 한글 조사(助詞) 대응 I18n engine extension
Stars: ✭ 34 (-2.86%)
Mutual labels:  i18n
Monogame
One framework for creating powerful cross-platform games.
Stars: ✭ 8,014 (+22797.14%)
Mutual labels:  cross-platform

Made by @kilianvalkhof

Other projects:

  • 💻 Polypane - Develop responsive websites and apps twice as fast on multiple screens at once
  • 🖌️ Superposition - Kickstart your design system by extracting design tokens from your website
  • 🗒️ FromScratch - A smart but simple autosaving scratchpad

Electron-create-menu npm npm-downloads FOSSA Status

provides a default menu for your electron applications, with convenience functions for multiplatform use and i18n.

Installation

Install using npm install electron-create-menu.

Usage

Instead of importing Menu from electron, import it from electron-create-menu:

import Menu from "electron-create-menu";
// or
const Menu = require("electron-create-menu");

To get a default menu with platform-appropriate menu items and submenus, call Menu like so:

Menu();

Note: This API has to be called after the ready event of app module.

Menu always returns the menu object that Menu.buildFromTemplate creates, so you can access 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.
Menu(callback, i18n);

The callback function

callback receives two arguments:

  • 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:

Menu((defaultMenu, separator) => {
  defaultMenu.push({
    label: "My custom menu!",
    submenu: [
      { label: "my first item" },
      separator(),
      { label: "my second item" }
    ]
  });

  return defaultMenu;
});

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.

Example using i18next

const i18next = require('i18next');

i18next.init({
  /* assumed setup of i18next here */
}).then(function(t) {

  Menu(
    menu => {
      menu.push({
        label: i18next.t('My custom menu!'),
        submenu: [
          {label: i18next.t('my first item')},
          {label: i18next.t('my second item')},
        ],
      }),

      return menu;
    },

    // This function is used to translate the default labels
    i18next.t
  );

});

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'.

// this shows the menu item only on macOs
{
  showOn: "darwin";
}

// this hides the menu item on windows and macOs
{
  hideOn: ["win32", "darwin"];
}

With these, you can adapt your menu to multiple platforms without having to maintain multiple menu templates. See the default template for an example of a consolidated template.

You can also add a string or an array of strings as an argument to the separator function: separator('darwin'). The given value is interpreted as the value for showOn.

Example

Menu((defaultMenu, separator) => {

  defaultMenu.push({
    label: "My custom menu!",
    submenu: [
      {
        label: 'This is only shown on macOs',
        showOn: 'darwin',
      },
      separator('darwin'), // this is shown only macOs
      {label:
        'This is hidden on windows'
        hideOn: ['win32']
      },
    ],
  });

  return defaultMenu;
});

License

Electron-create-menu is ISC licensed.

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].