|
@@ -3,7 +3,7 @@ import fs from "fs";
|
|
import { app, BrowserWindow, Menu, screen, dialog, ipcMain } from "electron";
|
|
import { app, BrowserWindow, Menu, screen, dialog, ipcMain } from "electron";
|
|
import installExtension, { VUEJS3_DEVTOOLS } from "electron-devtools-installer";
|
|
import installExtension, { VUEJS3_DEVTOOLS } from "electron-devtools-installer";
|
|
|
|
|
|
-import child_process from "child_process";
|
|
|
|
|
|
+import { exec } from "child_process";
|
|
import process from "process";
|
|
import process from "process";
|
|
|
|
|
|
const isDev = process.env.NODE_ENV === "development";
|
|
const isDev = process.env.NODE_ENV === "development";
|
|
@@ -32,37 +32,6 @@ function createWin() {
|
|
win.loadURL(`http://localhost:8090`);
|
|
win.loadURL(`http://localhost:8090`);
|
|
} else {
|
|
} else {
|
|
win.loadFile(path.resolve(__dirname, "index.html"));
|
|
win.loadFile(path.resolve(__dirname, "index.html"));
|
|
- //现场环境可能需要配置config.json来获取web页面地址
|
|
|
|
- // const filePath = path.join(
|
|
|
|
- // process.env.PORTABLE_EXECUTABLE_DIR as string,
|
|
|
|
- // "config.json"
|
|
|
|
- // );
|
|
|
|
- // if (!fs.existsSync(filePath)) {
|
|
|
|
- // dialog.showErrorBox("找不到配置文件", "config.json文件不存在!");
|
|
|
|
- // app.quit();
|
|
|
|
- // } else {
|
|
|
|
- // fs.readFile(filePath, "utf-8", function (err, data) {
|
|
|
|
- // if (!err) {
|
|
|
|
- // let da: { url?: string } = {};
|
|
|
|
- // try {
|
|
|
|
- // da = JSON.parse(data);
|
|
|
|
- // } catch (error) {
|
|
|
|
- // dialog.showErrorBox(
|
|
|
|
- // "错误",
|
|
|
|
- // "您的config.json文件内容格式可能不正确,请检查!"
|
|
|
|
- // );
|
|
|
|
- // app.quit();
|
|
|
|
- // }
|
|
|
|
- // const url = da.url || "";
|
|
|
|
- // if (!!url) {
|
|
|
|
- // win.loadURL(url);
|
|
|
|
- // }
|
|
|
|
- // } else {
|
|
|
|
- // dialog.showErrorBox("错误", JSON.stringify(err));
|
|
|
|
- // app.quit();
|
|
|
|
- // }
|
|
|
|
- // });
|
|
|
|
- // }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
win.webContents.once("dom-ready", () => {
|
|
win.webContents.once("dom-ready", () => {
|
|
@@ -134,61 +103,21 @@ ipcMain.on("window-min", () => {
|
|
});
|
|
});
|
|
|
|
|
|
function startExe(exePath: string) {
|
|
function startExe(exePath: string) {
|
|
- const childProcess = child_process.spawn(exePath);
|
|
|
|
-
|
|
|
|
- childProcess.on("close", (code: any) => {
|
|
|
|
- console.log("close---- code:", code);
|
|
|
|
- });
|
|
|
|
|
|
+ console.log("主进程接收到的exe路径:", exePath);
|
|
|
|
+ let checkPath = exePath.includes(".exe ")
|
|
|
|
+ ? exePath.split(".exe ")[0] + ".exe"
|
|
|
|
+ : exePath;
|
|
|
|
+ const fileExists = fs.existsSync(checkPath);
|
|
|
|
+ if (fileExists) {
|
|
|
|
+ exec(exePath);
|
|
|
|
+ } else {
|
|
|
|
+ dialog.showErrorBox("tip", `${checkPath}不存在!`);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-// ipcMain.on("startExe", (event, args: string) => {
|
|
|
|
-// startExe(args);
|
|
|
|
-// });
|
|
|
|
-
|
|
|
|
-// ipcMain.handle("checkProcessExist", async (event, processName) => {
|
|
|
|
-// try {
|
|
|
|
-// const processExists = await checkProcessExist(processName);
|
|
|
|
-// if (processExists) {
|
|
|
|
-// dialog.showErrorBox("tip", `${processName}已启动`);
|
|
|
|
-// } else {
|
|
|
|
-// const exePath = path.join(
|
|
|
|
-// process.env.PORTABLE_EXECUTABLE_DIR as string,
|
|
|
|
-// "text.exe"
|
|
|
|
-// );
|
|
|
|
-// const fileExists = fs.existsSync(exePath);
|
|
|
|
-// if (fileExists) {
|
|
|
|
-// startExe(exePath);
|
|
|
|
-// } else {
|
|
|
|
-// dialog.showErrorBox("tip", ".exe not exist!");
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// return processExists;
|
|
|
|
-// } catch (error) {
|
|
|
|
-// console.error(error);
|
|
|
|
-// return false;
|
|
|
|
-// }
|
|
|
|
-// });
|
|
|
|
-
|
|
|
|
-// function checkProcessExist(processName: string) {
|
|
|
|
-// return new Promise((resolve, reject) => {
|
|
|
|
-// const command = process.platform === "win32" ? "tasklist" : "ps aux";
|
|
|
|
-// const childProcess = child_process.spawn(command);
|
|
|
|
-
|
|
|
|
-// childProcess.stdout.on("data", (data: any) => {
|
|
|
|
-// if (data.toString().indexOf(processName) !== -1) {
|
|
|
|
-// resolve(true);
|
|
|
|
-// }
|
|
|
|
-// });
|
|
|
|
-
|
|
|
|
-// childProcess.stderr.on("data", (data: any) => {
|
|
|
|
-// reject(data.toString());
|
|
|
|
-// });
|
|
|
|
-
|
|
|
|
-// childProcess.on("close", (code: any) => {
|
|
|
|
-// resolve(false);
|
|
|
|
-// });
|
|
|
|
-// });
|
|
|
|
-// }
|
|
|
|
|
|
+ipcMain.on("startExe", (event, args: string) => {
|
|
|
|
+ startExe(args);
|
|
|
|
+});
|
|
|
|
|
|
app.on("ready", async () => {
|
|
app.on("ready", async () => {
|
|
if (isDev) {
|
|
if (isDev) {
|