gemercheung 3 år sedan
förälder
incheckning
bcd27ed0cd
4 ändrade filer med 37 tillägg och 13 borttagningar
  1. 2 1
      package.json
  2. 10 2
      packages/main/src/mainWindow.ts
  3. 13 10
      packages/renderer/src/App.vue
  4. 12 0
      yarn.lock

+ 2 - 1
package.json

@@ -65,6 +65,7 @@
     "socket.io-msgpack-parser": "^3.0.1",
     "vue": "3.2.37",
     "xterm": "^4.19.0",
-    "xterm-addon-fit": "^0.5.0"
+    "xterm-addon-fit": "^0.5.0",
+    "node": "^18.4.0"
   }
 }

+ 10 - 2
packages/main/src/mainWindow.ts

@@ -1,11 +1,13 @@
-import { BrowserWindow, ipcMain } from 'electron';
+import { BrowserWindow, ipcMain, app } from 'electron';
 import { join } from 'path';
 import { URL } from 'url';
 import * as pty from 'node-pty';
 import * as os from 'os';
 
+console.log('getAppPath', app.getAppPath());
 
 const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
+// const nodePath = os.platform() === 'win32' ? '.\\node_modules\\node\\bin\\node.exe' : './node_modules/node/bin/node';
 
 interface ProcessEnv { [key: string]: string; }
 
@@ -55,8 +57,14 @@ async function createWindow() {
           }
         }
       } else {
+
         const BenmarkFilePath = join(__dirname, '../../main/command/test.mjs');
-        ptyProcess = pty.spawn(shell, [`node ${BenmarkFilePath}`, `${url}`, `${count}`], {
+
+        const nodePathProduction = join(process.resourcesPath, 'app/node_modules/node/bin/node.exe');
+        const nodePath =  app.isPackaged ? nodePathProduction :'node';
+
+        // browserWindow.webContents.send('terminal.resourcesPath', app.isPackaged);
+        ptyProcess = pty.spawn(shell, [`${nodePath} ${BenmarkFilePath}`, `${url}`, `${count}`], {
           name: 'xterm-color',
           cols: 80,
           rows: 30,

+ 13 - 10
packages/renderer/src/App.vue

@@ -30,6 +30,9 @@ onMounted(() => {
       if (terminal) terminal.write(data);
     });
   }
+  ipc.on('terminal.resourcesPath', (_, data) => {
+    window.alert('resourcesPath: ' + JSON.stringify(data));
+  });
 });
 
 // var shell = os.platform() === "win32" ? "powershell.exe" : "bash";
@@ -67,19 +70,19 @@ function stop() {
   </fieldset>
 
   <div class="btns">
-    <button
-      v-show="!config.isStart"
-      class="start"
-      @click="start"
+    <button
+      v-show="!config.isStart"
+      class="start"
+      @click="start"
     >
       开始测试
     </button>
-    <button
-      v-show="config.isStart"
-      class="end"
-      @click="stop"
-    >
-      停止测试
+    <button
+      v-show="config.isStart"
+      class="end"
+      @click="stop"
+    >
+      停止测试
     </button>
   </div>
   <div id="terminal" />

+ 12 - 0
yarn.lock

@@ -3765,6 +3765,11 @@ node-api-version@^0.1.4:
   dependencies:
     semver "^7.3.5"
 
+node-bin-setup@^1.0.0:
+  version "1.1.0"
+  resolved "http://192.168.0.47:4873/node-bin-setup/-/node-bin-setup-1.1.0.tgz#9df94c41335a8f41958a639b2736f860582a209c"
+  integrity sha512-pTeU6NgUrexiLNtd+AKwvg6cngHMvj5FZ5e2bbv2ogBSIc9yhkXSSaTScfSRZnwHIh5YFmYSYlemLWkiKD7rog==
+
 node-fetch@^2.x.x:
   version "2.6.7"
   resolved "http://192.168.0.47:4873/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
@@ -3805,6 +3810,13 @@ node-releases@^2.0.6:
   resolved "http://192.168.0.47:4873/node-releases/-/node-releases-2.0.6.tgz#8a7088c63a55e493845683ebf3c828d8c51c5503"
   integrity sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==
 
+node@^18.4.0:
+  version "18.5.0"
+  resolved "http://192.168.0.47:4873/node/-/node-18.5.0.tgz#8a89fa3b0a801de4888155e7ce3b7d3c60dc15c4"
+  integrity sha512-o0o7TfrD92IRQrwbvbExjl+i1ZXAyXdYS3vAMYn/1Oez6hKVnIp+bWxXBnh3USCpYK65zTW9VLAIBrCiyfhUuA==
+  dependencies:
+    node-bin-setup "^1.0.0"
+
 nopt@^5.0.0:
   version "5.0.0"
   resolved "http://192.168.0.47:4873/nopt/-/nopt-5.0.0.tgz#530942bb58a512fccafe53fe210f13a25355dc88"