Skip to content

Instantly share code, notes, and snippets.

@mikecao
Last active July 15, 2016 03:07
Show Gist options
  • Save mikecao/201a1936dcbb9d6c82fc1b00177088b5 to your computer and use it in GitHub Desktop.
Save mikecao/201a1936dcbb9d6c82fc1b00177088b5 to your computer and use it in GitHub Desktop.
Electron menu item delay
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Electron - Test</title>
<style>
#box {
width: 100px;
height: 100px;
margin: 100px;
background-color: red;
}
</style>
</head>
<body>
<div id="box"></div>
<input type="button" onclick="clickFunc();" value="Change Color" />
</body>
<script>
const {remote} = require('electron');
const {Menu, MenuItem} = remote;
let color = 'red';
const clickFunc = () => {
color = (color == 'red') ? 'blue' : 'red';
document.getElementById('box').style.backgroundColor = color;
}
const template = [
{
label: 'Menu',
submenu: [
{
label: 'Change Color',
click: clickFunc,
accelerator: 'CmdOrCtrl+C'
}
]
}
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment