mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-06-10 03:07:32 +08:00
仅测试了window和mac系统 1. ee 框架ready后,通过命令启动jar(优先试用配置的端口,被占用时则随机端口) 2. did-finish-load 事件通知 fronend 存储java程序的访问地址 3. 程序退出时,通过命令行kill掉程序 4. 提供前端调用 java 接口的示例
89 lines
1.8 KiB
JavaScript
89 lines
1.8 KiB
JavaScript
const Appliaction = require('ee-core').Appliaction;
|
|
const getPort = require('get-port');
|
|
const { app } = require('electron');
|
|
|
|
class Main extends Appliaction {
|
|
|
|
constructor() {
|
|
super();
|
|
// this === eeApp;
|
|
}
|
|
|
|
/**
|
|
* core app have been loaded
|
|
*/
|
|
async ready () {
|
|
// do some things
|
|
|
|
await this.createJavaPorts();
|
|
await this.startJava();
|
|
}
|
|
|
|
async createJavaPorts() {
|
|
if (this.config.javaServer.enable) {
|
|
const javaPort = await getPort({ port: this.config.javaServer.port });
|
|
process.env.EE_JAVA_PORT = javaPort;
|
|
this.config.javaServer.port = javaPort;
|
|
}
|
|
// 更新config配置
|
|
this.getCoreDB().setItem("config", this.config);
|
|
}
|
|
|
|
async startJava() {
|
|
this.logger.info("[main] startJava start");
|
|
const javaServer = require("./public/lib/javaServer");
|
|
javaServer.start(this);
|
|
this.logger.info("[main] startJava end");
|
|
}
|
|
|
|
/**
|
|
* electron app ready
|
|
*/
|
|
async electronAppReady () {
|
|
// do some things
|
|
}
|
|
|
|
/**
|
|
* main window have been loaded
|
|
*/
|
|
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();
|
|
})
|
|
}
|
|
|
|
const self = this;
|
|
this.electron.mainWindow.webContents.on("did-finish-load", () => {
|
|
const updateFrontend = require('./public/lib/updateFrontend');
|
|
updateFrontend.install(self);
|
|
});
|
|
|
|
app.on("before-quit", async () => {
|
|
await this.killJava();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* before app close
|
|
*/
|
|
async beforeClose () {
|
|
// do some things
|
|
|
|
}
|
|
|
|
async killJava() {
|
|
if (this.config.javaServer.enable) {
|
|
const javaServer = require("./public/lib/javaServer");
|
|
await javaServer.kill(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
new Main();
|
|
|