123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { createLog } from "@/utils/logger";
- export default function async(exeName, cb) {
- if (typeof nodeRequire == "undefined") {
- console.log("nodeRequire failed");
- window._hmt.push([
- "_trackEvent",
- window.location.pathname.replace(/\d+/g, ""),
- "不在Electron中,调用 " + exeName + " 失败",
- ]);
- createLog({
- page: window.location.pathname.replace(/\d+/g, ""),
- action: "不在Electron中,调用 " + exeName + " 失败",
- });
- throw new Error("不在Electron中,调用 " + exeName + " 失败");
- }
- return new Promise(resolve => {
- window.nodeRequire("node-cmd").get(exeName, async (err, data, stderr) => {
- console.log("exe", err, data, stderr); // 未免过多日志,此处后续可以关闭
- createLog({
- page: window.location.pathname.replace(/\d+/g, ""),
- error: JSON.stringify(err),
- data,
- stderr: JSON.stringify(stderr),
- });
- await new Promise(resolve2 => setTimeout(() => resolve2(), 1000));
- await cb();
- resolve();
- });
- });
- }
- export function fileExists(file) {
- if (typeof nodeRequire == "undefined") {
- console.log("nodeRequire failed");
- window._hmt.push([
- "_trackEvent",
- window.location.pathname.replace(/\d+/g, ""),
- "不在Electron中,调用 fs 失败",
- ]);
- createLog({
- page: window.location.pathname.replace(/\d+/g, ""),
- action: "不在Electron中,调用 fs 失败",
- });
- throw new Error("不在Electron中,调用 fs 失败");
- }
- return window.nodeRequire("fs").existsSync(file);
- }
|