import { app, BrowserWindow } from "electron";
import * as Path from "path";
import { initConfig } from "./config";
const createWindow = (): void => {
/**
* 创建浏览器窗口
*/
let win: BrowserWindow = new BrowserWindow(initConfig);
win.loadFile(Path.resolve(‘.‘, ‘view/index.html‘));
// win.webContents.openDevTools(); //是否打开调试工具
};
// Electron会在初始化完成并且准备好创建浏览器窗口时调用这个方法
// 部分 API 在 ready 事件触发后才能使用。
app.whenReady().then(createWindow)
//也查以调用以下的方法进行实现ready后的事件触发
// app.on("ready", () => createWindow());
// app.on("ready", createWindow);
/**
* 所有窗口关闭的事件
*/
app.on(‘window-all-closed‘, () => {
if (process.platform !== ‘darwin‘) {
app.quit()
}
})
/**
* 窗口激活后的事件
*/
app.on(‘activate‘, () => {
// On macOS 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 (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
export const initConfig = { width: 800, height: 600, }
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>myElectron</title> </head> <body> <div>today is good day!</div> </body> </html>
原文:https://www.cnblogs.com/rickyctbu/p/13670230.html