From 29b048064ae92d5d8d9737477f4375f724deeb08 Mon Sep 17 00:00:00 2001
From: whychw <858544502@qq.com>
Date: 星期六, 21 三月 2026 14:40:02 +0800
Subject: [PATCH] U 安装脚本修改
---
main.js | 184 ++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 171 insertions(+), 13 deletions(-)
diff --git a/main.js b/main.js
index 6570807..deefe8a 100644
--- a/main.js
+++ b/main.js
@@ -1,6 +1,10 @@
-const { app, BrowserWindow, Menu } = require("electron");
+const { app, BrowserWindow, Menu, ipcMain } = require("electron");
const path = require("path");
const { readConfigFile } = require('./getConfig');
+const child_process = require("child_process");
+// import log from "electron-log";
+// 涓嶆敮鎸� import
+const log = require("electron-log");
// 鑾峰彇閰嶇疆鏂囦欢
const config = readConfigFile();
@@ -32,6 +36,27 @@
});
}
+const appUrl = remoteUrl + 'server/getCookie';
+
+const requestPromise = require("minimal-request-promise");
+
+const checkService = function (cb) {
+ requestPromise.get(appUrl).then(
+ function (response) {
+ log.info(response);
+ log.info("Server started!");
+ cb();
+ },
+ function (response) {
+ log.warn(response);
+ log.info("Waiting for the server start...");
+ setTimeout(function () {
+ checkService(cb);
+ }, 500);
+ }
+ );
+};
+
// Scheme must be registered before the app is ready
// protocol.registerSchemesAsPrivileged([
// { scheme: "app", privileges: { secure: true, standard: true, stream: true } },
@@ -47,7 +72,7 @@
// ? path.join(__dirname, "./loading.html")
// : `file://${__dirname}/loading.html`;
const loadingURL = `file://${__dirname}/loading.html`;
-const showLoading = (cb) => {
+const showLoading = (cb, argFn) => {
loadingWin = new BrowserWindow({
// show: false,
frame: false,
@@ -55,15 +80,15 @@
height: 260,
resizable: false,
transparent: true,
- // webPreferences: {
- // preload: path.join(__dirname, "./preload.js"),
- // },
+ webPreferences: {
+ preload: path.join(__dirname, "./preload.js"),
+ },
});
// loadingWin.webContents.openDevTools();
loadingWin.loadURL(loadingURL);
loadingWin.setSkipTaskbar(true);
// loadingWin.show();
- cb(true);
+ cb(true, argFn);
// 鍚姩java绋嬪簭
// if (platform === 'win32') {
// ipcMain.once('renderer-ready', (event, data) => {
@@ -71,8 +96,125 @@
// serverProcess = require('child_process').execFile(dir + '/app_x64.exe');
// });
// }
+ requestPromise.get(appUrl).then(
+ function () {
+ log.info("绐楀彛鍒濆鍖� 鏈嶅姟姝e父");
+ // ipcRenderer.send('java-ready');
+ loadingWin.webContents.send("java-ready");
+ },
+ function () {
+ log.info("绐楀彛鍒濆鍖� 鎺ュ彛涓嶉��");
+ log.info("姝e湪缁堟java杩涚▼锛岀劧鍚庨噸鍚湇鍔�");
+ // update(win.webContents, true);
+ // 濡傛灉鏄痺in骞冲彴
+ if (process.platform == 'darwin' || process.platform == 'win32') {
+ stopForWin();
+ } else if (process.platform == 'linux') {
+ stopForLinux();
+ }
+ }
+ );
+
};
-async function createWindow(wait) {
+
+// 缁堟java杩涚▼ 骞堕噸鍚湇鍔� win骞冲彴
+function stopForWin() {
+ let stop = child_process.spawn("cmd.exe", ["/c", `${process.cwd()}\\stop.bat`]);
+ log.info(`${process.cwd()}\\stop.bat`);
+
+ stop.on("exit", function (code) {
+ if (code > 0) {
+ log.info('鎵цstop.bat娌℃湁姝g‘exit, 閿欒鐮�' + code);
+ // return false;
+ }
+ log.info("java杩涚▼琚粓姝紝鍑嗗閲嶅惎鏈嶅姟");
+ child_process.exec(
+ `"${process.cwd()}\\fgv2.exe" restart`,
+ (err) => {
+ if (err) {
+ log.info("閲嶅惎鏈嶅姟鍑洪敊浜唖tderr: " + JSON.stringify(err));
+ // 閲嶆柊杩愯setup鎵瑰鐞� 灏濊瘯閲嶆柊娉ㄥ唽鏈嶅姟
+ child_process.spawn("cmd.exe", ["/c", "setup_service.bat"]);
+ log.info("鏈嶅姟寮傚父 姝e湪灏濊瘯閲嶆柊娉ㄥ唽鏈嶅姟");
+ } else {
+ log.info("鏈嶅姟閲嶅惎鎴愬姛锛岃繛鎺ヤ腑");
+ }
+ // 绛夊埌鏈嶅姟灏辩华鍐嶉噸鍚�
+ checkService(() => {
+ loadingWin.webContents.send("java-ready");
+ });
+ }
+ );
+ });
+ stop.on('error', (code, data) => {
+ log.info('stop.bat 鎵ц error');
+ log.info(code);
+ log.info(data);
+ });
+}
+
+// 缁堟java杩涚▼ 骞堕噸鍚湇鍔� linux骞冲彴
+function stopForLinux() {
+ // 鑾峰彇搴旂敤鐨勭湡瀹炴牴鐩綍锛圓SAR 鍖呭鐨勮矾寰勶級
+ const appPath = app.getAppPath();
+ log.info(`appPath: ====${appPath}====`);
+ let dir = path.join(appPath, '../../stop.sh');
+ let stop = child_process.spawn('bash', [dir]);
+
+ // 鐩戝惉鑴氭湰鎵ц
+ stop.stdout.on('data', (data) => {
+ log.info(`stdout: ${data}`);
+ });
+
+ stop.stderr.on('data', (data) => {
+ log.info(`stderr: ${data}`);
+ });
+
+ stop.on('close', (code) => {
+ log.info(`瀛愯繘绋嬮��鍑猴紝 閫�鍑虹爜锛�${code}`);
+
+ log.info("java杩涚▼琚粓姝紝鍑嗗閲嶅惎鏈嶅姟");
+ child_process.exec(`systemctl --user restart fgv2.service`, (err, out, stde) => {
+ log.info('==========');
+ log.info(err);
+ log.info(out);
+ log.info(stde);
+ if (err) {
+ log.error('閲嶅惎鏈嶅姟澶辫触锛�' + err);
+ let dir = path.join(appPath, '../../setup_service.sh');
+ child_process.exec(`bash "${dir}"`, (error, stdout, stderr) => {
+ if (error) {
+ log.error('鎵ц澶辫触锛�' + error);
+ }
+ log.info(`鑴氭湰杈撳嚭锛� ${stdout}`);
+ log.error(`鑴氭湰閿欒锛� ${stderr}`);
+ });
+ }
+ if (out) {
+ log.info(`閲嶅惎鏈嶅姟杈撳嚭锛� ${out}`);
+ }
+ if (stde) {
+ log.error(`閲嶅惎鏈嶅姟閿欒锛� ${stde}`);
+ let dir = path.join(appPath, '../../setup_service.sh');
+ child_process.exec(`bash "${dir}"`, (error, stdout, stderr) => {
+ // log.info('0000000');
+ if (error) {
+ log.error('鎵ц澶辫触锛�' + error);
+ }
+ log.info(`鑴氭湰杈撳嚭锛� ${stdout}`);
+ log.error(`鑴氭湰閿欒锛� ${stderr}`);
+ });
+ }
+ // 绛夊埌鏈嶅姟灏辩华鍐嶉噸鍚�
+ checkService(() => {
+ loadingWin.webContents.send("java-ready");
+ });
+ });
+ });
+
+}
+
+async function createWindow(wait, cb) {
// Create the browser window.
win = new BrowserWindow({
show: !wait,
@@ -84,12 +226,13 @@
// nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
// contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION
nodeIntegration: false,
+ // nodeIntegration: true,
webSecurity: true,
allowEval: false,
allowRunningInsecureContent: false,
contextIsolation: true,
enableRemoteModule: false,
- // preload: path.join(__dirname, "preload.js"),
+ preload: path.join(__dirname, "preload.js"),
},
});
@@ -97,6 +240,8 @@
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL);
+ // DEBUG
+ // win.webContents.openDevTools();
if (!process.env.IS_TEST) win.webContents.openDevTools();
} else {
// createProtocol("app");
@@ -106,7 +251,10 @@
// win.loadURL("http://118.89.139.230:8919/fg/");
// win.loadURL('http://192.168.10.79:8919/fg/');
// win.loadURL('http://192.168.10.80:8919/fg/');
- win.loadURL(remoteUrl);
+ // 杩滅▼鏂囦欢 涓嶈兘鎻愬墠鍔犺浇
+ // win.loadURL(remoteUrl + 'index.html');
+ // DEBUG
+ // win.webContents.openDevTools();
}
if (wait) {
@@ -115,10 +263,20 @@
// loadingWin.close();
// win.show();
// }, 6000);
- win.once("ready-to-show", () => {
- loadingWin.hide();
- loadingWin.close();
- win.show();
+ // win.once("ready-to-show", () => {
+ // loadingWin.hide();
+ // loadingWin.close();
+ // win.show();
+ // });
+
+ ipcMain.on("java-ready", () => {
+ log.info("java-ready!");
+ win.loadURL(remoteUrl + 'index.html');
+ win.once("ready-to-show", () => {
+ loadingWin.hide();
+ loadingWin.close();
+ win.show();
+ });
});
}
}
--
Gitblit v1.9.1