生命周期
介绍
项目入口文件以及生命周期
bash
根目录的main.js
入口 main.js
该文件只做实例化操作,启动 ElectronEgg
js
const { ElectronEgg } = require("ee-core");
new ElectronEgg();
生命周期
new ElectronEgg()
实例化会触发 ./electron/index.js
模块,core 功能加载顺序如下:
js
// 引入基础 Application 类
const { Application } = require("ee-core");
class Index extends Application {
constructor() {
super();
}
/**
* core app have been loaded
* 加载
* config -> service -> controller -> socket -> ready()
*/
async ready() {
// do some things
}
/**
* electron app ready
* 加载以下事件
* app.on('second-instance')
* app.whenReady().then() 该事件会创建 mainWindow
* app.on('window-all-closed')
* app.on('before-quit')
* 然后触发
* -> electronAppReady()
*/
async electronAppReady() {
// do some things
}
/**
* main window have been loaded
* mainWindow 被创建后,加载
* windowReady() -> addon -> preload
*/
async windowReady() {
// do some things
// 延迟加载,无白屏
const winOpt = this.config.windowsOption;
if (winOpt.show == false) {
const win = this.electron.mainWindow;
win.once("ready-to-show", () => {
win.show();
});
}
}
/**
* before app close
*/
async beforeClose() {
// do some things
}
}
Index.toString = () => "[class Index]";
module.exports = Index;