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 + " 失败",
    ]);
    throw "不在Electron中，调用 " + exeName + " 失败";
  }
  return new Promise(resolve => {
    window.nodeRequire("node-cmd").get(exeName, async (err, data, stderr) => {
      console.log(err, data, 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 失败",
    ]);
    throw "不在Electron中，调用 fs 失败";
  }
  return window.nodeRequire("fs").existsSync(file);
}
