{"id":13798072,"url":"https://github.com/kilian/electron-create-menu","last_synced_at":"2025-03-25T03:30:57.500Z","repository":{"id":57221588,"uuid":"164450725","full_name":"Kilian/electron-create-menu","owner":"Kilian","description":"a default menu for your electron applications, with convenience functions for multiplatform use and i18n.","archived":false,"fork":false,"pushed_at":"2019-12-20T15:48:38.000Z","size":243,"stargazers_count":35,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-19T07:33:31.377Z","etag":null,"topics":["cross-platform","electron","i18n","javascript","menu","node"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kilian.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-07T15:15:12.000Z","updated_at":"2024-10-10T10:58:07.000Z","dependencies_parsed_at":"2022-08-29T02:12:48.004Z","dependency_job_id":null,"html_url":"https://github.com/Kilian/electron-create-menu","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilian%2Felectron-create-menu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilian%2Felectron-create-menu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilian%2Felectron-create-menu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilian%2Felectron-create-menu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kilian","download_url":"https://codeload.github.com/Kilian/electron-create-menu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245394521,"owners_count":20608115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cross-platform","electron","i18n","javascript","menu","node"],"created_at":"2024-08-04T00:00:38.587Z","updated_at":"2025-03-25T03:30:57.137Z","avatar_url":"https://github.com/Kilian.png","language":"JavaScript","readme":"### Made by [@kilianvalkhof](https://twitter.com/kilianvalkhof)\n\n#### Other projects:\n\n- 💻 [Polypane](https://polypane.app) - Develop responsive websites and apps twice as fast on multiple screens at once\n- 🖌️ [Superposition](https://superposition.design) - Kickstart your design system by extracting design tokens from your website\n- 🗒️ [FromScratch](https://fromscratch.rocks) - A smart but simple autosaving scratchpad\n\n---\n\n# 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)\n\nprovides a default menu for your electron applications, with convenience functions for multiplatform use and i18n.\n\n\u003cimg src=\"example.png\"\u003e\n\n## Installation\n\nInstall using `npm install electron-create-menu`.\n\n## Usage\n\nInstead of importing Menu from `electron`, import it from `electron-create-menu`:\n\n```js\nimport Menu from \"electron-create-menu\";\n// or\nconst Menu = require(\"electron-create-menu\");\n```\n\nTo get a default menu with platform-appropriate menu items and submenus, call Menu like so:\n\n```\nMenu();\n```\n\n_Note:_ This API has to be called after the `ready` event of `app` module.\n\nMenu 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.\n\n### Optional arguments\n\nMenu has two optional functions you can pass it\n\n- The first argument is the `callback` function, where you can further edit (or replace) the generated menu.\n- The second argument is the `i18n` function where you can supply a function to use for translating the menu items.\n\n```js\nMenu(callback, i18n);\n```\n\n### The callback function\n\n`callback` receives two arguments:\n\n- The generated menu\n- A function that returns `{type: 'separator'}` for convenience.\n\nIt expects you to return a menu-like object, either the edited default menu or a new menu.\n\n#### Callback example\n\nTo append a menu item to the menu, push an object onto menu and return it:\n\n```js\nMenu((defaultMenu, separator) =\u003e {\n  defaultMenu.push({\n    label: \"My custom menu!\",\n    submenu: [\n      { label: \"my first item\" },\n      separator(),\n      { label: \"my second item\" }\n    ]\n  });\n\n  return defaultMenu;\n});\n```\n\n### The i18n function\n\nThe i18n function is applied to the labels of the default menu. There are two things worth mentioning:\n\n- Most items in the default menu are specified by a _role_, so the OS will supply the translation.\n- Labels added in the callback function are not translated by this function.\n\n#### Example using i18next\n\n```js\nconst i18next = require('i18next');\n\ni18next.init({\n  /* assumed setup of i18next here */\n}).then(function(t) {\n\n  Menu(\n    menu =\u003e {\n      menu.push({\n        label: i18next.t('My custom menu!'),\n        submenu: [\n          {label: i18next.t('my first item')},\n          {label: i18next.t('my second item')},\n        ],\n      }),\n\n      return menu;\n    },\n\n    // This function is used to translate the default labels\n    i18next.t\n  );\n\n});\n```\n\n## Multiplatform use\n\nEach 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'.\n\n```js\n// this shows the menu item only on macOs\n{\n  showOn: \"darwin\";\n}\n\n// this hides the menu item on windows and macOs\n{\n  hideOn: [\"win32\", \"darwin\"];\n}\n```\n\nWith these, you can adapt your menu to multiple platforms without having to maintain multiple menu templates. See the [default template](https://github.com/Kilian/electron-create-menu/blob/master/index.js#L7) for an example of a consolidated template.\n\nYou 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`.\n\n#### Example\n\n```js\nMenu((defaultMenu, separator) =\u003e {\n\n  defaultMenu.push({\n    label: \"My custom menu!\",\n    submenu: [\n      {\n        label: 'This is only shown on macOs',\n        showOn: 'darwin',\n      },\n      separator('darwin'), // this is shown only macOs\n      {label:\n        'This is hidden on windows'\n        hideOn: ['win32']\n      },\n    ],\n  });\n\n  return defaultMenu;\n});\n```\n\n## License\n\nElectron-create-menu is ISC licensed.\n\n[![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)\n","funding_links":[],"categories":["Library","Tools"],"sub_categories":["UI","For Electron"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilian%2Felectron-create-menu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkilian%2Felectron-create-menu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilian%2Felectron-create-menu/lists"}