From 33bea35b12fe71a069439ad48a1b5c59dd36d251 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 24 Apr 2024 12:34:54 +0200 Subject: [PATCH] terminals --- apps/remixdesktop/src/plugins/xtermPlugin.ts | 9 ++++----- .../remix-ui-terminal-menu-buttons.tsx | 17 ++++++++++++++--- .../src/lib/components/remix-ui-xterminals.tsx | 16 +++++----------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/apps/remixdesktop/src/plugins/xtermPlugin.ts b/apps/remixdesktop/src/plugins/xtermPlugin.ts index a00fd843f4..b1eff777b8 100644 --- a/apps/remixdesktop/src/plugins/xtermPlugin.ts +++ b/apps/remixdesktop/src/plugins/xtermPlugin.ts @@ -139,6 +139,7 @@ class XtermPluginClient extends ElectronBasePluginClient { } async createTerminal(path?: string, shell?: string): Promise { + const start_time = Date.now() console.log('createTerminal', path, shell || defaultShell) let parsedEnv: any = null if (!(process.platform === 'win32')) { @@ -172,7 +173,8 @@ class XtermPluginClient extends ElectronBasePluginClient { this.sendData(data, uid) }) this.terminals[ptyProcess.pid] = ptyProcess - + const end_time = Date.now() + console.log('createTerminal', end_time - start_time) return ptyProcess.pid } @@ -218,9 +220,6 @@ class XtermPluginClient extends ElectronBasePluginClient { } async new(): Promise { - console.log('new terminal in client') - const pid = await this.createTerminal(this.workingDir) - console.log('new terminal in client', pid) - this.emit('new', pid) + this.emit('new') } } diff --git a/libs/remix-ui/terminal/src/lib/components/remix-ui-terminal-menu-buttons.tsx b/libs/remix-ui/terminal/src/lib/components/remix-ui-terminal-menu-buttons.tsx index 8802f8a65c..4fecfd13e7 100644 --- a/libs/remix-ui/terminal/src/lib/components/remix-ui-terminal-menu-buttons.tsx +++ b/libs/remix-ui/terminal/src/lib/components/remix-ui-terminal-menu-buttons.tsx @@ -12,9 +12,19 @@ export const RemixUITerminalMenuButtons = (props: RemixUiTerminalProps) => { dispatch({ type: SET_OPEN, payload: true }) } - function showTerminal(event: any): void { + const showTerminal = async(event: any): Promise => { props.plugin.call('layout', 'minimize', props.plugin.profile.name, false) - dispatchXterm({ type: 'SHOW_OUTPUT', payload: false }) + if( xtermState.terminals.length === 0) { + const start_time = Date.now() + const pid = await props.plugin.call('xterm', 'createTerminal', xtermState.workingDir, null) + const end_time = Date.now() + console.log(`createTerminal took ${end_time - start_time} ms`) + dispatchXterm({ type: 'HIDE_ALL_TERMINALS', payload: null }) + dispatchXterm({ type: 'SHOW_OUTPUT', payload: false }) + dispatchXterm({ type: 'ADD_TERMINAL', payload: { pid, queue: '', timeStamp: Date.now(), ref: null, hidden: false } }) + } else { + dispatchXterm({ type: 'SHOW_OUTPUT', payload: false }) + } dispatch({ type: SET_OPEN, payload: true }) } @@ -23,7 +33,8 @@ export const RemixUITerminalMenuButtons = (props: RemixUiTerminalProps) => { - diff --git a/libs/remix-ui/xterm/src/lib/components/remix-ui-xterminals.tsx b/libs/remix-ui/xterm/src/lib/components/remix-ui-xterminals.tsx index cf5daed645..7e5b67d429 100644 --- a/libs/remix-ui/xterm/src/lib/components/remix-ui-xterminals.tsx +++ b/libs/remix-ui/xterm/src/lib/components/remix-ui-xterminals.tsx @@ -33,10 +33,11 @@ export const RemixUiXterminals = (props: RemixUiXterminalsProps) => { dispatchXterm({ type: 'REMOVE_TERMINAL', payload: pid }) }) - plugin.on('xterm', 'new', async (pid: number) => { - dispatchXterm({ type: 'ADD_TERMINAL', payload: { pid, queue: '', timeStamp: Date.now(), ref: null, hidden: false } }) - dispatchXterm({ type: 'SHOW_OUTPUT', payload: false }) - dispatchXterm({ type: 'HIDE_ALL_TERMINALS', payload: null }) + plugin.on('xterm', 'new', async () => { + const pid = await plugin.call('xterm', 'createTerminal', workingDir, null) + dispatchXterm({ type: 'HIDE_ALL_TERMINALS', payload: null }) + dispatchXterm({ type: 'SHOW_OUTPUT', payload: false }) + dispatchXterm({ type: 'ADD_TERMINAL', payload: { pid, queue: '', timeStamp: Date.now(), ref: null, hidden: false } }) }) @@ -135,13 +136,6 @@ export const RemixUiXterminals = (props: RemixUiXterminalsProps) => { }) } - useEffect(() => { - if (!xtermState.showOutput) { - console.log('create terminal because of showOutput') - //if (terminals.length === 0) createTerminal('', plugin, xtermState.workingDir, dispatchXterm) - } - }, [xtermState.showOutput]) - return (<> {
<>