-
Notifications
You must be signed in to change notification settings - Fork 897
open new window #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
open new window #59
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,91 +1,115 @@ | ||
| import { type BrowserWindow, ipcMain, shell } from "electron"; | ||
| import { | ||
| BrowserWindow, | ||
| type BrowserWindow as BrowserWindowType, | ||
| ipcMain, | ||
| shell, | ||
| } from "electron"; | ||
| import tmuxManager from "./tmux-manager"; | ||
|
|
||
| export function registerTerminalIPCs(mainWindow: BrowserWindow) { | ||
| // Set main window reference | ||
| tmuxManager.setMainWindow(mainWindow); | ||
|
|
||
| // Initialize tmux manager (restore sessions) | ||
| tmuxManager.initialize().catch((error) => { | ||
| console.error("[Terminal IPC] Failed to initialize tmux manager:", error); | ||
| }); | ||
|
|
||
| // Create terminal (or reattach to existing tmux session) | ||
| ipcMain.handle( | ||
| "terminal-create", | ||
| async ( | ||
| _event, | ||
| options: { | ||
| id?: string; | ||
| cols?: number; | ||
| rows?: number; | ||
| cwd?: string; | ||
| command?: string; | ||
| let ipcHandlersRegistered = false; | ||
|
|
||
| export function registerTerminalIPCs(window: BrowserWindowType) { | ||
| // Initialize tmux manager (restore sessions) only once | ||
| if (!ipcHandlersRegistered) { | ||
| tmuxManager.initialize().catch((error) => { | ||
| console.error("[Terminal IPC] Failed to initialize tmux manager:", error); | ||
| }); | ||
| } | ||
|
|
||
| // Register IPC handlers only once globally | ||
| if (!ipcHandlersRegistered) { | ||
| // Create terminal (or reattach to existing tmux session) | ||
| ipcMain.handle( | ||
| "terminal-create", | ||
| async ( | ||
| event, | ||
| options: { | ||
| id?: string; | ||
| cols?: number; | ||
| rows?: number; | ||
| cwd?: string; | ||
| command?: string; | ||
| }, | ||
| ) => { | ||
| // Get the window that sent this request | ||
| const senderWindow = BrowserWindow.fromWebContents(event.sender); | ||
| const terminalId = await tmuxManager.create(options); | ||
|
|
||
| // Register this window to receive output from this terminal | ||
| if (senderWindow) { | ||
| tmuxManager.registerTerminalWindow(terminalId, senderWindow); | ||
| } | ||
|
|
||
| return terminalId; | ||
| }, | ||
| ); | ||
|
|
||
| // Send input to terminal | ||
| ipcMain.on( | ||
| "terminal-input", | ||
| (_event, message: { id: string; data: string }) => { | ||
| tmuxManager.write(message.id, message.data); | ||
| }, | ||
| ); | ||
|
|
||
| // Resize terminal with sequence tracking | ||
| ipcMain.on( | ||
| "terminal-resize", | ||
| ( | ||
| _event, | ||
| message: { id: string; cols: number; rows: number; seq: number }, | ||
| ) => { | ||
| tmuxManager.resize(message.id, message.cols, message.rows, message.seq); | ||
| }, | ||
| ); | ||
|
|
||
| // Send signal to terminal foreground process | ||
| ipcMain.on( | ||
| "terminal-signal", | ||
| (_event, message: { id: string; signal: string }) => { | ||
| tmuxManager.signal(message.id, message.signal); | ||
| }, | ||
| ) => { | ||
| return await tmuxManager.create(options); | ||
| }, | ||
| ); | ||
|
|
||
| // Send input to terminal | ||
| ipcMain.on( | ||
| "terminal-input", | ||
| (_event, message: { id: string; data: string }) => { | ||
| tmuxManager.write(message.id, message.data); | ||
| }, | ||
| ); | ||
|
|
||
| // Resize terminal with sequence tracking | ||
| ipcMain.on( | ||
| "terminal-resize", | ||
| ( | ||
| _event, | ||
| message: { id: string; cols: number; rows: number; seq: number }, | ||
| ) => { | ||
| tmuxManager.resize(message.id, message.cols, message.rows, message.seq); | ||
| }, | ||
| ); | ||
|
|
||
| // Send signal to terminal foreground process | ||
| ipcMain.on( | ||
| "terminal-signal", | ||
| (_event, message: { id: string; signal: string }) => { | ||
| tmuxManager.signal(message.id, message.signal); | ||
| }, | ||
| ); | ||
|
|
||
| // Detach from terminal (keep tmux session alive) | ||
| ipcMain.on("terminal-detach", (_event, id: string) => { | ||
| tmuxManager.detach(id); | ||
| }); | ||
|
|
||
| // Execute command in terminal | ||
| ipcMain.on( | ||
| "terminal-execute-command", | ||
| (_event, message: { id: string; command: string }) => { | ||
| tmuxManager.executeCommand(message.id, message.command); | ||
| }, | ||
| ); | ||
|
|
||
| // Kill terminal (destroy tmux session completely) | ||
| ipcMain.on("terminal-kill", (_event, id: string) => { | ||
| tmuxManager.kill(id); | ||
| }); | ||
|
|
||
| // Get terminal history | ||
| ipcMain.handle("terminal-get-history", (_event, id: string) => { | ||
| return tmuxManager.getHistory(id); | ||
| }); | ||
|
|
||
| // Open external URLs | ||
| ipcMain.handle("open-external", async (_event, url: string) => { | ||
| await shell.openExternal(url); | ||
| }); | ||
|
|
||
| // Clean up on app quit | ||
| ); | ||
|
|
||
| // Detach from terminal (keep tmux session alive) | ||
| ipcMain.on("terminal-detach", (_event, id: string) => { | ||
| tmuxManager.detach(id); | ||
| }); | ||
|
|
||
| // Execute command in terminal | ||
| ipcMain.on( | ||
| "terminal-execute-command", | ||
| (_event, message: { id: string; command: string }) => { | ||
| tmuxManager.executeCommand(message.id, message.command); | ||
| }, | ||
| ); | ||
|
|
||
| // Kill terminal (destroy tmux session completely) | ||
| ipcMain.on("terminal-kill", (_event, id: string) => { | ||
| tmuxManager.kill(id); | ||
| }); | ||
|
|
||
| // Get terminal history | ||
| ipcMain.handle("terminal-get-history", (_event, id: string) => { | ||
| return tmuxManager.getHistory(id); | ||
| }); | ||
|
|
||
| // Open external URLs | ||
| ipcMain.handle("open-external", async (_event, url: string) => { | ||
| await shell.openExternal(url); | ||
| }); | ||
|
|
||
| ipcHandlersRegistered = true; | ||
| } | ||
|
|
||
| // Clean up when this window closes | ||
| const cleanup = () => { | ||
| // tmuxManager.killAll(); | ||
| console.log("[Terminal IPC] Cleaning up window terminal registrations"); | ||
| tmuxManager.unregisterWindow(window); | ||
| }; | ||
|
|
||
| // Register cleanup on window close | ||
| window.on("closed", cleanup); | ||
|
|
||
| return cleanup; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { ipcMain } from "electron"; | ||
| import windowManager from "./window-manager"; | ||
|
|
||
| export function registerWindowIPCs() { | ||
| ipcMain.handle("window-create", async () => { | ||
| try { | ||
| await windowManager.createWindow(); | ||
| return { success: true }; | ||
| } catch (error) { | ||
| console.error("[Window IPC] Failed to create window:", error); | ||
| return { | ||
| success: false, | ||
| error: error instanceof Error ? error.message : "Unknown error", | ||
| }; | ||
| } | ||
| }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wire up the new window-create IPC channel
You added
registerWindowIPCs()but never invoke it here, so any renderer callingipcRenderer.invoke("window-create")will reject because noipcMain.handlewas registered. Please import the new helper and call it alongside the other startup registrations so the channel is live before windows request it. (electronjs.org)🤖 Prompt for AI Agents