exit terminals

pull/4837/head
filip mertens 9 months ago
parent b17129bba7
commit 7a089ebdfd
  1. 33
      apps/remixdesktop/src/plugins/xtermPlugin.ts

@ -1,5 +1,5 @@
import {PluginClient} from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
import {Profile} from '@remixproject/plugin-utils' import { Profile } from '@remixproject/plugin-utils'
import { import {
ElectronBasePlugin, ElectronBasePlugin,
ElectronBasePluginClient, ElectronBasePluginClient,
@ -8,25 +8,25 @@ import {
import os from 'os' import os from 'os'
import * as pty from 'node-pty' import * as pty from 'node-pty'
import process from 'node:process' import process from 'node:process'
import {userInfo} from 'node:os' import { userInfo } from 'node:os'
import {findExecutable} from '../utils/findExecutable' import { findExecutable } from '../utils/findExecutable'
import {spawnSync} from 'child_process' import { spawnSync } from 'child_process'
import { stripAnsi } from '../lib' import { stripAnsi } from '../lib'
import { DataBatcher } from '../lib/databatcher' import { DataBatcher } from '../lib/databatcher'
export const detectDefaultShell = () => { export const detectDefaultShell = () => {
const {env} = process const { env } = process
if (process.platform === 'win32') { if (process.platform === 'win32') {
return env.SHELL || 'powershell.exe' return env.SHELL || 'powershell.exe'
} }
try { try {
const {shell} = userInfo() const { shell } = userInfo()
if (shell) { if (shell) {
return shell return shell
} }
} catch {} } catch { }
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
return env.SHELL || '/bin/zsh' return env.SHELL || '/bin/zsh'
@ -123,7 +123,7 @@ class XtermPluginClient extends ElectronBasePluginClient {
async getShells(): Promise<string[]> { async getShells(): Promise<string[]> {
if (os.platform() === 'win32') { if (os.platform() === 'win32') {
let bash = await findExecutable('bash.exe') let bash = await findExecutable('bash.exe')
if(bash.length === 0) { if (bash.length === 0) {
bash = await findExecutable('bash.exe', undefined, [process.env['ProgramFiles'] + '\\Git\\bin']) bash = await findExecutable('bash.exe', undefined, [process.env['ProgramFiles'] + '\\Git\\bin'])
} }
if (bash) { if (bash) {
@ -139,7 +139,7 @@ class XtermPluginClient extends ElectronBasePluginClient {
async createTerminal(path?: string, shell?: string): Promise<number> { async createTerminal(path?: string, shell?: string): Promise<number> {
let parsedEnv: any = null let parsedEnv: any = null
if (!(process.platform === 'win32')) { if (!(process.platform === 'win32')) {
const {stdout} = spawnSync(defaultShell, getShellEnvArgs, { const { stdout } = spawnSync(defaultShell, getShellEnvArgs, {
encoding: 'utf8', encoding: 'utf8',
}) })
parsedEnv = parseEnv(stdout) parsedEnv = parseEnv(stdout)
@ -155,10 +155,18 @@ class XtermPluginClient extends ElectronBasePluginClient {
env: env, env: env,
}) })
const dataBatcher = new DataBatcher(ptyProcess.pid) const dataBatcher = new DataBatcher(ptyProcess.pid)
this.dataBatchers[ptyProcess.pid] = dataBatcher
ptyProcess.onData((data: string) => { ptyProcess.onData((data: string) => {
dataBatcher.write(Buffer.from(data)) dataBatcher.write(Buffer.from(data))
//this.sendData(data, ptyProcess.pid) //this.sendData(data, ptyProcess.pid)
}) })
ptyProcess.onExit(() => {
const pid = ptyProcess.pid
this.terminals[pid].kill()
delete this.terminals[pid]
delete this.dataBatchers[pid]
this.emit('close', pid)
})
dataBatcher.on('flush', (data: string, uid: number) => { dataBatcher.on('flush', (data: string, uid: number) => {
this.sendData(data, uid) this.sendData(data, uid)
}) })
@ -170,15 +178,16 @@ class XtermPluginClient extends ElectronBasePluginClient {
async closeTerminal(pid: number): Promise<void> { async closeTerminal(pid: number): Promise<void> {
this.terminals[pid].kill() this.terminals[pid].kill()
delete this.terminals[pid] delete this.terminals[pid]
delete this.dataBatchers[pid]
this.emit('close', pid) this.emit('close', pid)
} }
async resize({cols, rows}: {cols: number; rows: number}, pid: number) { async resize({ cols, rows }: { cols: number; rows: number }, pid: number) {
if (this.terminals[pid]) { if (this.terminals[pid]) {
try { try {
this.terminals[pid].resize(cols, rows) this.terminals[pid].resize(cols, rows)
} catch (_err) { } catch (_err) {
const err = _err as {stack: any} const err = _err as { stack: any }
console.error(err.stack) console.error(err.stack)
} }
} else { } else {

Loading…
Cancel
Save