Created
October 8, 2020 15:23
-
-
Save adityapatnaik/21b9dd6dcbae19e8b36e002d4d1ef805 to your computer and use it in GitHub Desktop.
How to build a custom Menu in Electron?:setApplicationMenu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const electron = window.require('electron'); | |
const remote = electron.remote | |
const {Menu,BrowserWindow} = remote | |
const App = ()=>{ | |
return( | |
<div> | |
<h1>Look at the Menu!</h1> | |
<button onClick={()=>{ | |
const template = [ | |
{ | |
label:'Open Google', | |
click: function(){ | |
let win = new BrowserWindow({width:600,height:800}) | |
win.loadURL('https://www.google.com') | |
} | |
} | |
] | |
const menu = Menu.buildFromTemplate(template) | |
Menu.setApplicationMenu(menu) | |
}}>Change Menu</button> | |
</div> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment