示例工程 04-lifecycle-and-windows
04-lifecycle-and-windows/demo-01-event-order/main.ts
import { app, BrowserWindow } from "electron";
const smoke =
process.argv.includes("--smoke") || process.env.DEMO_SMOKE === "1";
const events: string[] = [];
app.on("before-quit", () => events.push("before-quit"));
app.on("will-quit", () => events.push("will-quit"));
app.whenReady().then(async () => {
events.push("ready");
const window = new BrowserWindow({
width: 640,
height: 420,
show: false,
webPreferences: {
contextIsolation: true,
sandbox: true,
nodeIntegration: false,
},
});
window.on("focus", () => events.push("focus"));
window.on("closed", () => events.push("window-closed"));
window.once("ready-to-show", () => window.show());
await window.loadURL("data:text/html,<h1>event order</h1>");
events.push("loaded");
if (smoke) {
console.log(JSON.stringify({ evt: "smoke", ok: true, events }));
app.quit();
}
});
app.on("window-all-closed", () => {
events.push("window-all-closed");
app.quit();
});