feat: 新增启动程序的同时启动额外资源目录中的jar

仅测试了window和mac系统

1. ee 框架ready后,通过命令启动jar(优先试用配置的端口,被占用时则随机端口)
2. did-finish-load 事件通知 fronend 存储java程序的访问地址
3. 程序退出时,通过命令行kill掉程序
4. 提供前端调用 java 接口的示例
This commit is contained in:
zuihou
2022-12-12 23:05:52 +08:00
parent 86cb5f5ab4
commit d872713d71
11 changed files with 548 additions and 6 deletions

39
main.js
View File

@@ -1,4 +1,6 @@
const Appliaction = require('ee-core').Appliaction;
const getPort = require('get-port');
const { app } = require('electron');
class Main extends Appliaction {
@@ -12,6 +14,26 @@ class Main extends Appliaction {
*/
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");
}
/**
@@ -34,6 +56,16 @@ class Main extends Appliaction {
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();
});
}
/**
@@ -43,6 +75,13 @@ class Main extends Appliaction {
// do some things
}
async killJava() {
if (this.config.javaServer.enable) {
const javaServer = require("./public/lib/javaServer");
await javaServer.kill(this);
}
}
}
new Main();