Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么mainWindow.minimize()不';t函数_Javascript_Node.js_Electron - Fatal编程技术网

Javascript 为什么mainWindow.minimize()不';t函数

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">&#10005;</div> </div> 这是我的main.js const ip

我想最小化electron应用程序屏幕,我有:

这是用于创建按钮的HTML:

<div class="close-container">
   <div class="minimize-button"></div>
   <div class="close-button">&#10005;</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()
}