some terminal session fixes
This commit is contained in:
parent
272f763e71
commit
7fd4968a35
46
main.ts
46
main.ts
|
|
@ -5,20 +5,8 @@ import * as os from "os";
|
|||
let mainWindow: BrowserWindow;
|
||||
const terminals = new Map<string, pty.IPty>();
|
||||
|
||||
const createWindow = () => {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1400,
|
||||
height: 900,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
},
|
||||
});
|
||||
|
||||
mainWindow.loadFile("index.html");
|
||||
|
||||
// Create new terminal
|
||||
ipcMain.on("create-terminal", (event) => {
|
||||
// Create new terminal
|
||||
ipcMain.on("create-terminal", (event) => {
|
||||
const terminalId = `terminal-${Date.now()}`;
|
||||
const shell = os.platform() === "darwin" ? "zsh" : "bash";
|
||||
|
||||
|
|
@ -37,32 +25,44 @@ const createWindow = () => {
|
|||
});
|
||||
|
||||
event.reply("terminal-created", terminalId);
|
||||
});
|
||||
});
|
||||
|
||||
// Handle terminal input
|
||||
ipcMain.on("terminal-input", (_event, terminalId: string, data: string) => {
|
||||
// Handle terminal input
|
||||
ipcMain.on("terminal-input", (_event, terminalId: string, data: string) => {
|
||||
const terminal = terminals.get(terminalId);
|
||||
if (terminal) {
|
||||
terminal.write(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Handle terminal resize
|
||||
ipcMain.on("terminal-resize", (_event, terminalId: string, cols: number, rows: number) => {
|
||||
// Handle terminal resize
|
||||
ipcMain.on("terminal-resize", (_event, terminalId: string, cols: number, rows: number) => {
|
||||
const terminal = terminals.get(terminalId);
|
||||
if (terminal) {
|
||||
terminal.resize(cols, rows);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Handle terminal close
|
||||
ipcMain.on("close-terminal", (_event, terminalId: string) => {
|
||||
// Handle terminal close
|
||||
ipcMain.on("close-terminal", (_event, terminalId: string) => {
|
||||
const terminal = terminals.get(terminalId);
|
||||
if (terminal) {
|
||||
terminal.kill();
|
||||
terminals.delete(terminalId);
|
||||
}
|
||||
});
|
||||
|
||||
const createWindow = () => {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1400,
|
||||
height: 900,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
},
|
||||
});
|
||||
|
||||
mainWindow.loadFile("index.html");
|
||||
};
|
||||
|
||||
app.whenReady().then(() => {
|
||||
|
|
|
|||
|
|
@ -198,8 +198,3 @@ ipcRenderer.on("terminal-created", (_event, terminalId: string) => {
|
|||
document.getElementById("new-terminal")?.addEventListener("click", () => {
|
||||
ipcRenderer.send("create-terminal");
|
||||
});
|
||||
|
||||
// Create first terminal on load
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
ipcRenderer.send("create-terminal");
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue