|
@@ -1,4 +1,5 @@
|
|
|
import { createLog } from "@/utils/logger";
|
|
|
+import { xor } from "lodash";
|
|
|
|
|
|
export default function checkRemote(exeName, cb) {
|
|
|
if (typeof nodeRequire == "undefined") {
|
|
@@ -15,54 +16,47 @@ export default function checkRemote(exeName, cb) {
|
|
|
throw new Error("不在Electron中,调用 " + exeName + " 失败");
|
|
|
}
|
|
|
return new Promise((resolve) => {
|
|
|
- window.nodeRequire("node-cmd").get(exeName, async (err, data, stderr) => {
|
|
|
- let stderrConverted;
|
|
|
- try {
|
|
|
- const iconv = require("iconv-lite");
|
|
|
- stderrConverted = iconv.decode(stderr, "cp936");
|
|
|
- } catch (error) {
|
|
|
- console.log("convert failed", error);
|
|
|
- stderrConverted = "convert failed";
|
|
|
- }
|
|
|
- console.log(exeName, err, data, stderrConverted); // 未免过多日志,此处后续可以关闭
|
|
|
- createLog({
|
|
|
- page: window.location.pathname,
|
|
|
- exeName,
|
|
|
- error: JSON.stringify(err),
|
|
|
- data,
|
|
|
- stderr: JSON.stringify(stderr),
|
|
|
- stderrConverted: JSON.stringify(stderrConverted),
|
|
|
- absPath: exeName.includes(":"),
|
|
|
- });
|
|
|
- // 如果相对路径没找到,则通过绝对路径来执行
|
|
|
- if (!exeName.includes(":") && err) {
|
|
|
- const fs = window.nodeRequire("electron").remote.require("fs");
|
|
|
+ window
|
|
|
+ .nodeRequire("node-cmd")
|
|
|
+ .get("cmd /c chcp 65001>nul && " + exeName, async (err, data, stderr) => {
|
|
|
+ console.log(exeName, err, data); // 未免过多日志,此处后续可以关闭
|
|
|
+ createLog({
|
|
|
+ page: window.location.pathname,
|
|
|
+ exeName,
|
|
|
+ error: JSON.stringify(err),
|
|
|
+ data,
|
|
|
+ stderr: JSON.stringify(stderr),
|
|
|
+ absPath: exeName.includes(":"),
|
|
|
+ });
|
|
|
+ // 如果相对路径没找到,则通过绝对路径来执行
|
|
|
+ if (!exeName.includes(":") && err) {
|
|
|
+ const fs = window.nodeRequire("electron").remote.require("fs");
|
|
|
|
|
|
- const path = window.nodeRequire("electron").remote.require("path");
|
|
|
+ const path = window.nodeRequire("electron").remote.require("path");
|
|
|
|
|
|
- const [exePath, exeParams] = exeName.split(" ");
|
|
|
- const absPath = path.join(
|
|
|
- window.nodeRequire("electron").remote.app.getAppPath(),
|
|
|
- "../../",
|
|
|
- exePath
|
|
|
- );
|
|
|
- if (fs.existsSync(absPath)) {
|
|
|
- try {
|
|
|
- await checkRemote([absPath, exeParams].join(" ").trim(), cb);
|
|
|
- } catch (error) {
|
|
|
- console.log("second try error", absPath);
|
|
|
+ const [exePath, exeParams] = exeName.split(" ");
|
|
|
+ const absPath = path.join(
|
|
|
+ window.nodeRequire("electron").remote.app.getAppPath(),
|
|
|
+ "../../",
|
|
|
+ exePath
|
|
|
+ );
|
|
|
+ if (fs.existsSync(absPath)) {
|
|
|
+ try {
|
|
|
+ await checkRemote([absPath, exeParams].join(" ").trim(), cb);
|
|
|
+ } catch (error) {
|
|
|
+ console.log("second try error", absPath);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- await new Promise((resolve2) => setTimeout(() => resolve2(), 1000));
|
|
|
- try {
|
|
|
- await cb();
|
|
|
- } catch (e) {
|
|
|
- console.log("call cb failed", e);
|
|
|
- } finally {
|
|
|
- resolve();
|
|
|
- }
|
|
|
- });
|
|
|
+ await new Promise((resolve2) => setTimeout(() => resolve2(), 1000));
|
|
|
+ try {
|
|
|
+ await cb();
|
|
|
+ } catch (e) {
|
|
|
+ console.log("call cb failed", e);
|
|
|
+ } finally {
|
|
|
+ resolve();
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -103,3 +97,28 @@ export function nodeCheckRemoteDesktop() {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+let previousAppList = [];
|
|
|
+export function nodeCheckProcess() {
|
|
|
+ try {
|
|
|
+ let appList = window
|
|
|
+ .nodeRequire("child_process")
|
|
|
+ .execSync("cmd /c chcp 65001>nul && tasklist /FO CSV")
|
|
|
+ .toString();
|
|
|
+ console.log(appList);
|
|
|
+ appList = appList.split("\r\n");
|
|
|
+ appList.shift();
|
|
|
+ appList = appList.map((v) => v.split(",")[0]);
|
|
|
+ const xorRes = xor(previousAppList, appList);
|
|
|
+ if (xorRes && xorRes.length > 0) {
|
|
|
+ createLog({
|
|
|
+ page: window.location.pathname,
|
|
|
+ action: "nodeCheckProcess",
|
|
|
+ xorRes,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ previousAppList = appList;
|
|
|
+ } catch (error) {
|
|
|
+ console.log("nodeCheckProcess exec error: ", error);
|
|
|
+ }
|
|
|
+}
|