|
|
|
@ -1,16 +1,13 @@ |
|
|
|
|
import {PluginClient} from '@remixproject/plugin' |
|
|
|
|
import {Profile} from '@remixproject/plugin-utils' |
|
|
|
|
import { |
|
|
|
|
ElectronBasePlugin, |
|
|
|
|
ElectronBasePluginClient, |
|
|
|
|
} from '@remixproject/plugin-electron' |
|
|
|
|
import {ElectronBasePlugin, ElectronBasePluginClient} from '@remixproject/plugin-electron' |
|
|
|
|
|
|
|
|
|
import os from 'os' |
|
|
|
|
import * as pty from 'node-pty' |
|
|
|
|
import process from 'node:process' |
|
|
|
|
import {userInfo} from 'node:os' |
|
|
|
|
import {findExecutable} from '../utils/findExecutable' |
|
|
|
|
import { spawnSync } from 'child_process' |
|
|
|
|
import {exec, spawnSync} from 'child_process' |
|
|
|
|
import {stripAnsi} from '../lib' |
|
|
|
|
import {DataBatcher} from '../lib/databatcher' |
|
|
|
|
|
|
|
|
@ -38,10 +35,7 @@ export const detectDefaultShell = () => { |
|
|
|
|
// Stores default shell when imported.
|
|
|
|
|
const defaultShell = detectDefaultShell() |
|
|
|
|
|
|
|
|
|
const getShellEnvArgs = [ |
|
|
|
|
'-ilc', |
|
|
|
|
'echo -n "_SHELL_ENV_DELIMITER_"; env; echo -n "_SHELL_ENV_DELIMITER_"; exit', |
|
|
|
|
] |
|
|
|
|
const getShellEnvArgs = ['-ilc', 'echo -n "_SHELL_ENV_DELIMITER_"; env; echo -n "_SHELL_ENV_DELIMITER_"; exit'] |
|
|
|
|
|
|
|
|
|
const getShellEnvEnv = { |
|
|
|
|
// Disables Oh My Zsh auto-update thing that can block the process.
|
|
|
|
@ -150,7 +144,6 @@ class XtermPluginClient extends ElectronBasePluginClient { |
|
|
|
|
const start_time = Date.now() |
|
|
|
|
console.log('createTerminal', path, shell || defaultShell) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const env = this.parsedEnv || process.env |
|
|
|
|
|
|
|
|
|
const ptyProcess = pty.spawn(shell || defaultShell, [], { |
|
|
|
@ -160,11 +153,10 @@ class XtermPluginClient extends ElectronBasePluginClient { |
|
|
|
|
cwd: path || this.workingDir || process.cwd(), |
|
|
|
|
env: env, |
|
|
|
|
encoding: 'utf8', |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
const dataBatcher = new DataBatcher(ptyProcess.pid) |
|
|
|
|
this.dataBatchers[ptyProcess.pid] = dataBatcher |
|
|
|
|
ptyProcess.onData((data: string) => { |
|
|
|
|
//console.log('data', data)
|
|
|
|
|
dataBatcher.write(Buffer.from(data)) |
|
|
|
|
}) |
|
|
|
|
ptyProcess.onExit(() => { |
|
|
|
@ -181,19 +173,40 @@ class XtermPluginClient extends ElectronBasePluginClient { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async closeTerminal(pid: number): Promise<void> { |
|
|
|
|
console.log('closeTerminal', pid) |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
if (this.terminals) { |
|
|
|
|
|
|
|
|
|
if (this.dataBatchers[pid]) delete this.dataBatchers[pid] |
|
|
|
|
|
|
|
|
|
if (this.terminals[pid]) { |
|
|
|
|
try { |
|
|
|
|
this.terminals[pid].kill() |
|
|
|
|
if (os.platform() === 'win32') { |
|
|
|
|
// For Windows, use taskkill to terminate the process
|
|
|
|
|
exec(`taskkill /PID ${pid} /T /F`, (error, stdout, stderr) => { |
|
|
|
|
if (error) { |
|
|
|
|
console.error(`Error killing process: ${error}`); |
|
|
|
|
}else{ |
|
|
|
|
console.log(`stdout: ${stdout}`); |
|
|
|
|
console.error(`stderr: ${stderr}`); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
this.terminals[pid].kill(); |
|
|
|
|
} |
|
|
|
|
} catch (err) { |
|
|
|
|
console.error(err) |
|
|
|
|
// ignore
|
|
|
|
|
} |
|
|
|
|
delete this.terminals[pid] |
|
|
|
|
} |
|
|
|
|
if (this.dataBatchers[pid]) |
|
|
|
|
delete this.dataBatchers[pid] |
|
|
|
|
} |
|
|
|
|
this.emit('close', pid) |
|
|
|
|
} catch (err) { |
|
|
|
|
console.error(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async resize({cols, rows}: {cols: number; rows: number}, pid: number) { |
|
|
|
|