Skip to content

Instantly share code, notes, and snippets.

@Ddorda
Created May 2, 2019 17:27
Show Gist options
  • Save Ddorda/2129f519f2dd71c05c8068824f6bc6cf to your computer and use it in GitHub Desktop.
Save Ddorda/2129f519f2dd71c05c8068824f6bc6cf to your computer and use it in GitHub Desktop.
Electron Menu to Template
// I wanted to have the default electron menu as template for changes and couldn't find anything online. hope it would help someone....
// I'll upload the result as another gist
function MenuItem2object(item) {
if (item == null){ return null;}
if (item.constructor.name == 'MenuItem') {
return {label: item.label, accelerator: item.accelerator, role: item.role, commandId: item.commandId, submenu: MenuItem2object(item.submenu)}
}
else if ( item.constructor.name == 'Menu') {
return item.items.map(item => MenuItem2object(item))
}
return null;
}
template_string = JSON.stringify(MenuItem2object(Menu.getApplicationMenu())).replace(/"([a-zA-Z]+)":(.+?),/g, '$1: $2,').replace(/"submenu":/g, 'submenu: ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment