mainWindow.on('closed', function () { mainWindow = null; });
}
app.on('ready', createWindow);
// Quit when all windows are closed. app.on('window-all-closed', function () { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit(); } });
app.on('activate', function () { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (mainWindow === null) { createWindow(); } });
新建index.html文件
1 2 3 4 5 6 7 8 9 10 11 12
<!DOCTYPE html> <htmllang="en"> <head> <metacharset="UTF-8"> <metaname="viewport"content="width=device-width, initial-scale=1.0"> <metahttp-equiv="X-UA-Compatible"content="ie=edge"> <title>Document</title> </head> <body> hello! This is an electron project. </body> </html>
运行项目
cnpm install npm start
添加应用图标文件logo.png 修改main.js文件
1 2 3 4 5 6 7 8 9 10 11
functioncreateWindow() { var ico = path.join(__dirname, 'img', 'logo-28.png'); // Create the browser window. mainWindow = new BrowserWindow({ width: 1024, height: 640, transparent: false, frame: true, icon: ico, resizable: true//固定大小 });