|
@@ -4,6 +4,7 @@ import { URL } from 'url';
|
|
import * as pty from 'node-pty';
|
|
import * as pty from 'node-pty';
|
|
import * as os from 'os';
|
|
import * as os from 'os';
|
|
|
|
|
|
|
|
+
|
|
const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
|
|
const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
|
|
|
|
|
|
interface ProcessEnv { [key: string]: string; }
|
|
interface ProcessEnv { [key: string]: string; }
|
|
@@ -11,6 +12,9 @@ interface ProcessEnv { [key: string]: string; }
|
|
async function createWindow() {
|
|
async function createWindow() {
|
|
const browserWindow = new BrowserWindow({
|
|
const browserWindow = new BrowserWindow({
|
|
show: false, // Use 'ready-to-show' event to show window
|
|
show: false, // Use 'ready-to-show' event to show window
|
|
|
|
+ width: 750,
|
|
|
|
+ height: 600,
|
|
|
|
+ resizable: false,
|
|
webPreferences: {
|
|
webPreferences: {
|
|
webviewTag: false, // The webview tag is not recommended. Consider alternatives like iframe or Electron's BrowserView. https://www.electronjs.org/docs/latest/api/webview-tag#warning
|
|
webviewTag: false, // The webview tag is not recommended. Consider alternatives like iframe or Electron's BrowserView. https://www.electronjs.org/docs/latest/api/webview-tag#warning
|
|
preload: join(__dirname, '../../preload/dist/index.cjs'),
|
|
preload: join(__dirname, '../../preload/dist/index.cjs'),
|
|
@@ -25,24 +29,47 @@ async function createWindow() {
|
|
*/
|
|
*/
|
|
browserWindow.on('ready-to-show', () => {
|
|
browserWindow.on('ready-to-show', () => {
|
|
browserWindow?.show();
|
|
browserWindow?.show();
|
|
-
|
|
|
|
|
|
+ let ptyProcess: pty.IPty | undefined;
|
|
if (import.meta.env.DEV) {
|
|
if (import.meta.env.DEV) {
|
|
browserWindow?.webContents.openDevTools();
|
|
browserWindow?.webContents.openDevTools();
|
|
}
|
|
}
|
|
- ipcMain.on('start-Benmark-test', () => {
|
|
|
|
- console.log('hey');
|
|
|
|
|
|
+ ipcMain.on('start-Benmark-test', (_, data) => {
|
|
|
|
+ console.log('hey', data);
|
|
|
|
+ const { url, count, stop } = data;
|
|
|
|
+ if (stop) {
|
|
|
|
+ try {
|
|
|
|
+ if (ptyProcess) {
|
|
|
|
+ browserWindow.webContents.send('terminal.incomingData', 'kill process(0), 压力测试结束!!');
|
|
|
|
+ ptyProcess.kill();
|
|
|
|
+ console.log('kill process');
|
|
|
|
+ }
|
|
|
|
+ } catch (err) {
|
|
|
|
+ try {
|
|
|
|
+ if (ptyProcess) {
|
|
|
|
+ browserWindow.webContents.send('terminal.incomingData', 'ill process(0), 压力测试结束!!!');
|
|
|
|
+ ptyProcess.kill('SIGKILL');
|
|
|
|
+ console.log('kill process');
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {
|
|
|
|
+ // couldn't kill the process
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ const BenmarkFilePath = join(__dirname, '../../main/src/test.mjs');
|
|
|
|
+ ptyProcess = pty.spawn(shell, [`node ${BenmarkFilePath}`, `${url}`, `${count}`], {
|
|
|
|
+ name: 'xterm-color',
|
|
|
|
+ cols: 80,
|
|
|
|
+ rows: 30,
|
|
|
|
+ cwd: process.env.HOME,
|
|
|
|
+ env: process.env as unknown as ProcessEnv,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ ptyProcess.on('data', function (data) {
|
|
|
|
+ // console.log('data', data);
|
|
|
|
+ browserWindow.webContents.send('terminal.incomingData', data);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
// console.log('pty', pty);
|
|
// console.log('pty', pty);
|
|
- const ptyProcess = pty.spawn(shell, [`node ${join(__dirname, '../../main/src/muti-client.mjs')}`], {
|
|
|
|
- name: 'xterm-color',
|
|
|
|
- cols: 80,
|
|
|
|
- rows: 30,
|
|
|
|
- cwd: process.env.HOME,
|
|
|
|
- env: process.env as unknown as ProcessEnv,
|
|
|
|
- });
|
|
|
|
- ptyProcess.on('data', function (data) {
|
|
|
|
- // console.log('data', data);
|
|
|
|
- browserWindow.webContents.send('terminal.incomingData', data);
|
|
|
|
- });
|
|
|
|
|
|
|
|
// ptyProcess.write('ls\r');
|
|
// ptyProcess.write('ls\r');
|
|
// ptyProcess.resize(100, 40);
|
|
// ptyProcess.resize(100, 40);
|