设置了一个使用电子预建的普通Hello World应用程序。
我通过npm start
命令运行它。
窗口正常显示正常情况。然而,经过一段时间后它会自行关闭。
在命令提示符下,它会在窗口关闭之前抛出以下警告:
WARNING:raw_channel_win.cc(473)] WriteFile: The pipe is being closed. (0xE8)
WARNING:channel.cc(549)] Failed to send message to ack remove remote endpoint (local ID 1, remote ID 1)
WARNING:channel.cc(315)] RawChannel write error
导致此问题的原因是什么?
npm版本是1.4.10& node(via io.js)版本为0.11.13(Windows 7 x64)
答案 0 :(得分:6)
正如@Oztaco所说,在QuickStart Guide中它有以下代码示例:
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
// other code ommited
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});