| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import { BrowserWindow, ipcMain } from 'electron';
- import { join } from 'path';
- import { URL } from 'url';
- import * as pty from 'node-pty';
- import * as os from 'os';
- const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
- interface ProcessEnv { [key: string]: string; }
- async function createWindow() {
- const browserWindow = new BrowserWindow({
- show: false, // Use 'ready-to-show' event to show window
- 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
- preload: join(__dirname, '../../preload/dist/index.cjs'),
- },
- });
- /**
- * If you install `show: true` then it can cause issues when trying to close the window.
- * Use `show: false` and listener events `ready-to-show` to fix these issues.
- *
- * @see https://github.com/electron/electron/issues/25012
- */
- browserWindow.on('ready-to-show', () => {
- browserWindow?.show();
- if (import.meta.env.DEV) {
- browserWindow?.webContents.openDevTools();
- }
- ipcMain.on('start-Benmark-test', () => {
- console.log('hey');
- // 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.resize(100, 40);
- // ptyProcess.write('ls\r');
- });
- });
- /**
- * URL for main window.
- * Vite dev server for development.
- * `file://../renderer/index.html` for production and test
- */
- const pageUrl = import.meta.env.DEV && import.meta.env.VITE_DEV_SERVER_URL !== undefined
- ? import.meta.env.VITE_DEV_SERVER_URL
- : new URL('../renderer/dist/index.html', 'file://' + __dirname).toString();
- await browserWindow.loadURL(pageUrl);
- return browserWindow;
- }
- /**
- * Restore existing BrowserWindow or Create new BrowserWindow
- */
- export async function restoreOrCreateWindow() {
- let window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed());
- if (window === undefined) {
- window = await createWindow();
- }
- if (window.isMinimized()) {
- window.restore();
- }
- window.focus();
- }
|