Javascript 为什么mainWindow.minimize()不';t函数
我想最小化electron应用程序屏幕,我有: 这是用于创建按钮的HTML:Javascript 为什么mainWindow.minimize()不';t函数,javascript,node.js,electron,Javascript,Node.js,Electron,我想最小化electron应用程序屏幕,我有: 这是用于创建按钮的HTML: <div class="close-container"> <div class="minimize-button"></div> <div class="close-button">✕</div> </div> 这是我的main.js const ip
<div class="close-container">
<div class="minimize-button"></div>
<div class="close-button">✕</div>
</div>
这是我的main.js
const ipcMain = require('electron').ipcMain;
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
// width: 1536,
// height: 864,
fullscreen: true,
frame: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js')
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html');
ipcMain.on('minimize', () => {
console.log('reached here');
mainWindow.minimize();
});
ipcMain.on('close', () => {
mainWindow.close();
});
// Open the DevTools.
mainWindow.webContents.openDevTools()
}
除了mainWindow.minimize()之外,所有代码都可以正常工作(我可以看到控制台日志('reach here')
);这不是它的工作,最小化屏幕
因此.minimize()方法无法正常运行
我错过了什么?如何解决这个问题?当您设置
全屏:false
时,问题仍然存在吗?正如您所知,JavaScript永远不会成为一种编程语言,它有很多bug。。。我通过使用200毫秒的超时来解决这个问题。。。。然后就可以了…你在哪里加的超时?在最小化事件处理程序或渲染器中?似乎这可能是electron的问题。setTimeout(()=>mainWindow.minimize(),200)代码>
const ipcMain = require('electron').ipcMain;
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
// width: 1536,
// height: 864,
fullscreen: true,
frame: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js')
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html');
ipcMain.on('minimize', () => {
console.log('reached here');
mainWindow.minimize();
});
ipcMain.on('close', () => {
mainWindow.close();
});
// Open the DevTools.
mainWindow.webContents.openDevTools()
}