|
@@ -6,15 +6,32 @@ import installExtension, { VUEJS3_DEVTOOLS } from "electron-devtools-installer";
|
|
import { exec } from "child_process";
|
|
import { exec } from "child_process";
|
|
import process from "process";
|
|
import process from "process";
|
|
import IniParser from "ini-parser";
|
|
import IniParser from "ini-parser";
|
|
|
|
+import logger from "./logger";
|
|
|
|
|
|
const isDev = process.env.NODE_ENV === "development";
|
|
const isDev = process.env.NODE_ENV === "development";
|
|
let win: BrowserWindow | null = null;
|
|
let win: BrowserWindow | null = null;
|
|
let loadWin: any = null;
|
|
let loadWin: any = null;
|
|
const additionalData = { lockKey: "scanAdmin" };
|
|
const additionalData = { lockKey: "scanAdmin" };
|
|
const gotTheLock = app.requestSingleInstanceLock(additionalData);
|
|
const gotTheLock = app.requestSingleInstanceLock(additionalData);
|
|
-console.log("gotTheLock", gotTheLock);
|
|
|
|
|
|
+logger.info(`gotTheLock:${gotTheLock}`);
|
|
if (!gotTheLock) {
|
|
if (!gotTheLock) {
|
|
|
|
+ logger.info(`app quit => gotTheLock:${gotTheLock}`);
|
|
app.quit();
|
|
app.quit();
|
|
|
|
+} else {
|
|
|
|
+ app.on("ready", async () => {
|
|
|
|
+ if (isDev) {
|
|
|
|
+ try {
|
|
|
|
+ await installExtension(VUEJS3_DEVTOOLS);
|
|
|
|
+ } catch (e: any) {
|
|
|
|
+ console.error("Vue Devtools failed to install:", e.toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ logger.info(`app ready`);
|
|
|
|
+ registEvent();
|
|
|
|
+
|
|
|
|
+ createWin();
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
function createWin() {
|
|
function createWin() {
|
|
@@ -97,24 +114,6 @@ function createLoadWin() {
|
|
// createLoadWin();
|
|
// createLoadWin();
|
|
// });
|
|
// });
|
|
|
|
|
|
-ipcMain.on("change-win-size", (event, args: string) => {
|
|
|
|
- // const { width, height } = screen.getPrimaryDisplay().workAreaSize;
|
|
|
|
- if (!win) return;
|
|
|
|
- const windowBounds = win.getBounds();
|
|
|
|
- const { width, height } =
|
|
|
|
- screen.getDisplayMatching(windowBounds).workAreaSize;
|
|
|
|
-
|
|
|
|
- let w = args === "big" ? width : 840;
|
|
|
|
- let h = args === "big" ? height : 500;
|
|
|
|
- if (args === "small") {
|
|
|
|
- win.setMinimumSize(w, h);
|
|
|
|
- }
|
|
|
|
- win.setSize(w, h);
|
|
|
|
- win.center();
|
|
|
|
-});
|
|
|
|
-ipcMain.on("window-min", () => {
|
|
|
|
- win?.minimize();
|
|
|
|
-});
|
|
|
|
const isRunning = (query: string, cb: Function) => {
|
|
const isRunning = (query: string, cb: Function) => {
|
|
exec(
|
|
exec(
|
|
"cmd /c chcp 65001>nul && tasklist /FO CSV",
|
|
"cmd /c chcp 65001>nul && tasklist /FO CSV",
|
|
@@ -127,6 +126,8 @@ const isRunning = (query: string, cb: Function) => {
|
|
function watchClientIsRunning(times = 10) {
|
|
function watchClientIsRunning(times = 10) {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
isRunning("client.exe", (status: boolean) => {
|
|
isRunning("client.exe", (status: boolean) => {
|
|
|
|
+ logger.info(`watchClientIsRunning times:${times},status:${status}`);
|
|
|
|
+
|
|
if (status) {
|
|
if (status) {
|
|
if (times > 0) {
|
|
if (times > 0) {
|
|
watchClientIsRunning(times--);
|
|
watchClientIsRunning(times--);
|
|
@@ -139,7 +140,7 @@ function watchClientIsRunning(times = 10) {
|
|
}
|
|
}
|
|
|
|
|
|
function startExe(exePath: string) {
|
|
function startExe(exePath: string) {
|
|
- console.log("主进程接收到的exe路径:", exePath);
|
|
|
|
|
|
+ logger.info("主进程接收到的exe路径:", exePath);
|
|
let checkPath = exePath.includes(".exe ")
|
|
let checkPath = exePath.includes(".exe ")
|
|
? exePath.split(".exe ")[0] + ".exe"
|
|
? exePath.split(".exe ")[0] + ".exe"
|
|
: exePath;
|
|
: exePath;
|
|
@@ -150,6 +151,12 @@ function startExe(exePath: string) {
|
|
// win?.show();
|
|
// win?.show();
|
|
// });
|
|
// });
|
|
exec(exePath, (error, stdout, stderr) => {
|
|
exec(exePath, (error, stdout, stderr) => {
|
|
|
|
+ if (error) {
|
|
|
|
+ logger.error(`client error:${error.toString()}`);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ logger.info(`client closed stdout:${stdout.toString()}`);
|
|
|
|
+ logger.info(`client closed stderr:${stderr.toString()}`);
|
|
console.log("子进程关闭了!");
|
|
console.log("子进程关闭了!");
|
|
watchClientIsRunning();
|
|
watchClientIsRunning();
|
|
});
|
|
});
|
|
@@ -158,31 +165,41 @@ function startExe(exePath: string) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-ipcMain.on("startExe", (event, args: string) => {
|
|
|
|
- startExe(args);
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
-ipcMain.on("hide-app", () => {
|
|
|
|
- win?.hide();
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
-ipcMain.on("get-page-size-ini", (event: any) => {
|
|
|
|
- const appPath = isDev ? process.cwd() : path.dirname(app.getPath("exe"));
|
|
|
|
- const iniFilePath = path.resolve(appPath, "page_size.ini");
|
|
|
|
- fs.readFile(iniFilePath, "utf8", (err: any, data: any) => {
|
|
|
|
- if (err) dialog.showErrorBox("tip", `page_size.ini文件不存在!`);
|
|
|
|
- const content = IniParser.parse(data);
|
|
|
|
- event.sender.send("got-page-size-ini", content);
|
|
|
|
|
|
+function registEvent() {
|
|
|
|
+ ipcMain.on("change-win-size", (event, args: string) => {
|
|
|
|
+ // const { width, height } = screen.getPrimaryDisplay().workAreaSize;
|
|
|
|
+ if (!win) return;
|
|
|
|
+ const windowBounds = win.getBounds();
|
|
|
|
+ const { width, height } =
|
|
|
|
+ screen.getDisplayMatching(windowBounds).workAreaSize;
|
|
|
|
+
|
|
|
|
+ let w = args === "big" ? width : 840;
|
|
|
|
+ let h = args === "big" ? height : 500;
|
|
|
|
+ if (args === "small") {
|
|
|
|
+ win.setMinimumSize(w, h);
|
|
|
|
+ }
|
|
|
|
+ win.setSize(w, h);
|
|
|
|
+ win.center();
|
|
|
|
+ });
|
|
|
|
+ ipcMain.on("window-min", () => {
|
|
|
|
+ win?.minimize();
|
|
});
|
|
});
|
|
-});
|
|
|
|
|
|
|
|
-app.on("ready", async () => {
|
|
|
|
- if (isDev) {
|
|
|
|
- try {
|
|
|
|
- await installExtension(VUEJS3_DEVTOOLS);
|
|
|
|
- } catch (e: any) {
|
|
|
|
- console.error("Vue Devtools failed to install:", e.toString());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- createWin();
|
|
|
|
-});
|
|
|
|
|
|
+ ipcMain.on("startExe", (event, args: string) => {
|
|
|
|
+ startExe(args);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ ipcMain.on("hide-app", () => {
|
|
|
|
+ win?.hide();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ ipcMain.on("get-page-size-ini", (event: any) => {
|
|
|
|
+ const appPath = isDev ? process.cwd() : path.dirname(app.getPath("exe"));
|
|
|
|
+ const iniFilePath = path.resolve(appPath, "page_size.ini");
|
|
|
|
+ fs.readFile(iniFilePath, "utf8", (err: any, data: any) => {
|
|
|
|
+ if (err) dialog.showErrorBox("tip", `page_size.ini文件不存在!`);
|
|
|
|
+ const content = IniParser.parse(data);
|
|
|
|
+ event.sender.send("got-page-size-ini", content);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+}
|