Browse Source

node检测向日葵

Michael Wang 4 years ago
parent
commit
8805bbdbb2

+ 14 - 1
src/features/Login/Login.vue

@@ -135,7 +135,10 @@ import {
 } from "@/constants/constants";
 import { REMOTE_APP_NAME, VCAM_LIST } from "@/constants/constant-namelist";
 import DevTools from "./DevTools.vue";
-import nativeExe, { fileExists } from "@/utils/nativeExe";
+import nativeExe, {
+  fileExists,
+  nodeCheckRemoteDesktop,
+} from "@/utils/nativeExe";
 import UA, { chromeUA } from "@/utils/ua.js";
 import {
   createLog,
@@ -871,6 +874,16 @@ export default {
           });
           return;
         }
+        if (typeof nodeRequire !== "undefined") {
+          const hasSun = nodeCheckRemoteDesktop();
+          if (hasSun) {
+            if (applicationNames) {
+              applicationNames += ",sunloginclient";
+            } else {
+              applicationNames = "sunloginclient";
+            }
+          }
+        }
         if (applicationNames && applicationNames.trim()) {
           let names = applicationNames
             .replace("qq", "QQ")

+ 11 - 0
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -987,6 +987,17 @@ export default {
           // });
           return;
         }
+        // 为避免考试过程中卡顿,不在考试过程中同步检测远程桌面软件
+        // if (typeof nodeRequire !== "undefined") {
+        //   const hasSun = nodeCheckRemoteDesktop();
+        //   if (hasSun) {
+        //     if (applicationNames) {
+        //       applicationNames += ",sunloginclient";
+        //     } else {
+        //       applicationNames = "sunloginclient";
+        //     }
+        //   }
+        // }
         if (applicationNames && applicationNames.trim()) {
           let names = applicationNames
             .replace("qq", "QQ")

+ 45 - 3
src/utils/nativeExe.js

@@ -1,6 +1,6 @@
 import { createLog } from "@/utils/logger";
 
-export default function async(exeName, cb) {
+export default function checkRemote(exeName, cb) {
   if (typeof nodeRequire == "undefined") {
     console.log("nodeRequire failed");
     window._hmt.push([
@@ -33,9 +33,34 @@ export default function async(exeName, cb) {
         stderr: JSON.stringify(stderr),
         stderrConverted: JSON.stringify(stderrConverted),
       });
+      // 如果相对路径没找到,则通过绝对路径来执行
+      if (!exeName.includes(":") && err) {
+        const fs = window.nodeRequire("electron").remote.require("fs");
+
+        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);
+          }
+        }
+      }
       await new Promise((resolve2) => setTimeout(() => resolve2(), 1000));
-      await cb();
-      resolve();
+      try {
+        await cb();
+      } catch (e) {
+        console.log("call cb failed", e);
+      } finally {
+        resolve();
+      }
     });
   });
 }
@@ -56,3 +81,20 @@ export function fileExists(file) {
   }
   return window.nodeRequire("fs").existsSync(file);
 }
+
+export function nodeCheckRemoteDesktop() {
+  createLog({
+    page: window.location.pathname,
+    action: "nodeCheckRemoteDesktop",
+  });
+
+  const appList = window
+    .nodeRequire("child_process")
+    .execSync("tasklist")
+    .toString();
+  if (appList && appList.match(/sunloginclient/gi).length > 0) {
+    return true;
+  } else {
+    return false;
+  }
+}