diff --git a/apps/remixdesktop/src/engine.ts b/apps/remixdesktop/src/engine.ts index b9631b5625..e14b59dc7b 100644 --- a/apps/remixdesktop/src/engine.ts +++ b/apps/remixdesktop/src/engine.ts @@ -36,6 +36,12 @@ ipcMain.on('fs:openFolder', async (event) => { fsPlugin.openFolder(event) }) + +ipcMain.on('terminal:new', async (event) => { + console.log('terminal:new', event) + xtermPlugin.new(event) +}) + ipcMain.on('template:open', async (event) => { console.log('template:open', event) templatesPlugin.openTemplate(event) diff --git a/apps/remixdesktop/src/main.ts b/apps/remixdesktop/src/main.ts index cfec7a6cef..0f2e599b8c 100644 --- a/apps/remixdesktop/src/main.ts +++ b/apps/remixdesktop/src/main.ts @@ -96,6 +96,7 @@ import WindowMenu from './menus/window'; import EditMenu from './menus/edit'; import GitMenu from './menus/git'; import ViewMenu from './menus/view'; +import TerminalMenu from './menus/terminal'; import { execCommand } from './menus/commands'; diff --git a/apps/remixdesktop/src/menus/commands.ts b/apps/remixdesktop/src/menus/commands.ts index 7a3b11fac5..80c00766d6 100644 --- a/apps/remixdesktop/src/menus/commands.ts +++ b/apps/remixdesktop/src/menus/commands.ts @@ -12,6 +12,11 @@ const commands: Record void> = { ipcMain.emit('fs:openFolder', focusedWindow.webContents.id); } }, + 'terminal:new': (focusedWindow) => { + if (focusedWindow) { + ipcMain.emit('terminal:new', focusedWindow.webContents.id); + } + }, 'template:open': (focusedWindow) => { if (focusedWindow) { ipcMain.emit('template:open', focusedWindow.webContents.id); diff --git a/apps/remixdesktop/src/menus/terminal.ts b/apps/remixdesktop/src/menus/terminal.ts new file mode 100644 index 0000000000..4059ae5bde --- /dev/null +++ b/apps/remixdesktop/src/menus/terminal.ts @@ -0,0 +1,20 @@ +import {BrowserWindow, MenuItemConstructorOptions} from 'electron'; + +export default ( + commandKeys: Record, + execCommand: (command: string, focusedWindow?: BrowserWindow) => void +): MenuItemConstructorOptions => { + const isMac = process.platform === 'darwin'; + + return { + label: 'Terminal', + submenu: [ + { + label: 'New Terminal', + click(item, focusedWindow) { + execCommand('terminal:new', focusedWindow); + } + } + ] + }; +}; diff --git a/apps/remixdesktop/src/plugins/xtermPlugin.ts b/apps/remixdesktop/src/plugins/xtermPlugin.ts index 2f503ce81f..bf0673fa41 100644 --- a/apps/remixdesktop/src/plugins/xtermPlugin.ts +++ b/apps/remixdesktop/src/plugins/xtermPlugin.ts @@ -6,27 +6,27 @@ import os from 'os'; import * as pty from "node-pty" import process from 'node:process'; -import {userInfo} from 'node:os'; +import { userInfo } from 'node:os'; export const detectDefaultShell = () => { - const {env} = process; + const { env } = process; - if (process.platform === 'win32') { - return env.SHELL || 'powershell.exe'; - } + if (process.platform === 'win32') { + return env.SHELL || 'powershell.exe'; + } - try { - const {shell} = userInfo(); - if (shell) { - return shell; - } - } catch {} + try { + const { shell } = userInfo(); + if (shell) { + return shell; + } + } catch { } - if (process.platform === 'darwin') { - return env.SHELL || '/bin/zsh'; - } + if (process.platform === 'darwin') { + return env.SHELL || '/bin/zsh'; + } - return env.SHELL || '/bin/sh'; + return env.SHELL || '/bin/sh'; }; // Stores default shell when imported. @@ -49,6 +49,13 @@ export class XtermPlugin extends ElectronBasePlugin { super(profile, clientProfile, XtermPluginClient) } + new(webContentsId: any): void { + const client = this.clients.find(c => c.webContentsId === webContentsId) + if (client) { + client.new() + } + } + } const clientProfile: Profile = { @@ -114,4 +121,7 @@ class XtermPluginClient extends ElectronBasePluginClient { this.emit('data', data, pid) } + async new(): Promise { + } + } \ No newline at end of file