[英]Can't modify the app menu in Electron app
I know it works, I just did it a few weeks ago but now it say this when i try doing it.我知道它有效,我几周前才这样做,但现在当我尝试这样做时它会这么说。 and also its put in another file named menu.js.
并将其放入另一个名为 menu.js 的文件中。
[LOG] [日志]
Uncaught TypeError: Cannot read property 'isReady' of undefined
at menu.js:36
[line 36] [第 36 行]
app.isReady().then(t => {
const menu = Menu.buildFromTemplate(temp)
Menu.setApplicationMenu(menu);
createWindow();
});
Probably you are missing this import, because your app
is undefined
:可能您缺少此导入,因为您的
app
undefined
:
const { app } = require('electron');
Also isReady
method returns a boolean ( true/false
) not a Promise
. isReady
方法也返回 boolean ( true/false
) 而不是Promise
。 You are looking for app.whenReady()
method, something like this:您正在寻找
app.whenReady()
方法,如下所示:
function createWindow () {
const win = new BrowserWindow(...options...)
// create and load window procedure...
const menu = Menu.buildFromTemplate(temp)
Menu.setApplicationMenu(menu);
}
app.whenReady().then(createWindow)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.