我正在Mac OS X(10.11)上使用Electron(1.4.13)创建一个时钟应用程序。
当我运行它时,它的托盘图标会在几分钟后出现。 上下文菜单无法正常工作。(应用程序因选择菜单项而崩溃)
在运行几分钟之前,它会毫无问题地工作。
main.js
https://github.com/electron/electron-quick-start/blob/master/main.js
的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample</title>
<script>
const remote = require('electron').remote;
const Menu = remote.Menu;
const MenuItem = remote.MenuItem;
const Tray = remote.Tray;
const NativeImage = remote.nativeImage;
document.addEventListener('DOMContentLoaded', function(){
var contextmenu = new Menu();
contextmenu.append(
new MenuItem({
label: 'Quit',
click: function() {
remote.app.quit();
}
})
);
window.addEventListener('contextmenu', function(ev) {
ev.preventDefault();
try {
contextmenu.popup(ev.x, ev.y);
} catch(e) {
console.log(e);
}
return false;
}, false);
var icon = NativeImage.createFromPath(__dirname + '/icon.png');
var tray = new Tray(icon.resize({
width: 18,
height: 18
}));
tray.setContextMenu(contextmenu);
run();
function run(){
window.requestAnimationFrame(function(){
run();
})
}
});
</script>
</head>
<body>
test
</body>
</html>
我不确定是什么导致了这个问题。 我做错了什么?
我在GitHub上创建了一个回购 https://github.com/studio-nuages/electron-example