From 723d4d861f22358fb12ac0f0ab8db7362b3cb129 Mon Sep 17 00:00:00 2001
From: he wei <858544502@qq.com>
Date: 星期一, 16 三月 2026 11:21:18 +0800
Subject: [PATCH] Merge branch 'master' of http://118.89.139.230:10101/r/~whychw/electron-fg2

---
 main.js |  112 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 99 insertions(+), 13 deletions(-)

diff --git a/main.js b/main.js
index 6570807..f270526 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,53 @@
   //     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);
+      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);
+      });
+    }
+  );
+  
 };
-async function createWindow(wait) {
+async function createWindow(wait, cb) {
   // Create the browser window.
   win = new BrowserWindow({
     show: !wait,
@@ -84,12 +154,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 +168,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 +179,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 +191,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