@@ -24,8 +24,8 @@ const activeConnections = new Map();
2424
2525function createWindow ( ) {
2626 mainWindow = new BrowserWindow ( {
27- width : 1000 ,
28- height : 800 ,
27+ width : 1280 ,
28+ height : 1024 ,
2929 webPreferences : {
3030 preload : path . join ( __dirname , 'preload.js' ) ,
3131 nodeIntegration : false ,
@@ -35,7 +35,7 @@ function createWindow() {
3535
3636 mainWindow . loadFile ( 'index.html' ) ;
3737
38- // Abrir DevTools en desarrollo
38+ // Abrir DevTools en desarrollo (descomentar para depuración)
3939 // mainWindow.webContents.openDevTools();
4040}
4141
@@ -53,7 +53,8 @@ app.on('window-all-closed', function () {
5353
5454// Manejar eventos desde el renderer
5555ipcMain . handle ( 'get-ssh-profiles' , async ( ) => {
56- return store . get ( 'sshProfiles' , [ ] ) ;
56+ const profiles = store . get ( 'sshProfiles' , [ ] ) ;
57+ return profiles ;
5758} ) ;
5859
5960ipcMain . handle ( 'get-favorites' , async ( ) => {
@@ -96,6 +97,14 @@ ipcMain.handle('delete-ssh-profile', async (event, profileName) => {
9697 const profiles = store . get ( 'sshProfiles' , [ ] ) ;
9798 const updatedProfiles = profiles . filter ( p => p . name !== profileName ) ;
9899 store . set ( 'sshProfiles' , updatedProfiles ) ;
100+
101+ // También eliminar de favoritos si existe
102+ const favorites = store . get ( 'favorites' , [ ] ) ;
103+ if ( favorites . includes ( profileName ) ) {
104+ const updatedFavorites = favorites . filter ( name => name !== profileName ) ;
105+ store . set ( 'favorites' , updatedFavorites ) ;
106+ }
107+
99108 return updatedProfiles ;
100109} ) ;
101110
@@ -170,68 +179,58 @@ ipcMain.handle('open-shell', async (event, profileName) => {
170179 return ;
171180 }
172181
173- // Crear ventana para la terminal
174- const terminalWindow = new BrowserWindow ( {
175- width : 800 ,
176- height : 600 ,
177- title : `SSH Terminal - ${ profileName } ` ,
178- webPreferences : {
179- preload : path . join ( __dirname , 'preload.js' ) ,
180- nodeIntegration : false ,
181- contextIsolation : true ,
182- } ,
183- } ) ;
184-
185- // Almacenar el stream para esta ventana
186- terminalWindow . sshStream = stream ;
187- terminalWindow . profileName = profileName ;
182+ // Almacenar el stream para este proceso de renderizado
183+ const webContents = event . sender ;
188184
189- terminalWindow . loadFile ( 'terminal.html' ) ;
190-
191- // Configurar el stream para reenviar datos a la ventana
185+ // Configurar el stream para reenviar datos al proceso de renderizado
192186 stream . on ( 'data' , data => {
193- if ( ! terminalWindow . isDestroyed ( ) ) {
194- terminalWindow . webContents . send ( 'terminal-data' , data ) ;
187+ if ( ! webContents . isDestroyed ( ) ) {
188+ webContents . send ( 'terminal-data' , data ) ;
195189 }
196190 } ) ;
197191
198192 stream . on ( 'close' , ( ) => {
199- if ( ! terminalWindow . isDestroyed ( ) ) {
200- terminalWindow . webContents . send ( 'terminal-data' , '\r\n\x1b[1;31mConexión cerrada\x1b[0m\r\n' ) ;
193+ if ( ! webContents . isDestroyed ( ) ) {
194+ webContents . send ( 'terminal-data' , '\r\n\x1b[1;31mConexión cerrada\x1b[0m\r\n' ) ;
201195 }
202196 } ) ;
203197
204- // Manejar cierre de ventana
205- terminalWindow . on ( 'closed' , ( ) => {
206- if ( stream ) {
207- stream . end ( ) ;
198+ stream . on ( 'error' , err => {
199+ if ( ! webContents . isDestroyed ( ) ) {
200+ webContents . send ( 'terminal-data' , `\r\n\x1b[1;31mError: ${ err . message } \x1b[0m\r\n` ) ;
208201 }
209202 } ) ;
210203
204+ // Almacenar el stream para el sender actual
205+ event . sender . sshStream = stream ;
206+
211207 resolve ( { success : true , message : 'Terminal abierta' } ) ;
212208 } ) ;
213209 } ) ;
214210} ) ;
215211
216212// Enviar datos a la terminal
217- ipcMain . handle ( 'terminal-input' , ( event , { data, windowId } ) => {
218- const win = BrowserWindow . getAllWindows ( ) . find ( w => w . id === windowId ) ;
219- if ( win && win . sshStream ) {
220- win . sshStream . write ( data ) ;
213+ ipcMain . handle ( 'terminal-input' , ( event , data ) => {
214+ const webContents = event . sender ;
215+
216+ if ( webContents && webContents . sshStream ) {
217+ webContents . sshStream . write ( data ) ;
221218 return true ;
222219 }
223220 return false ;
224221} ) ;
225222
226- // Obtener el ID de la ventana
227- ipcMain . handle ( 'get-window-id' , event => {
228- return BrowserWindow . fromWebContents ( event . sender ) . id ;
229- } ) ;
230-
231223// Cerrar conexión SSH
232224ipcMain . handle ( 'disconnect-ssh' , ( event , profileName ) => {
233225 const conn = activeConnections . get ( profileName ) ;
234226 if ( conn ) {
227+ // Si hay un stream asociado al remitente, cerrarlo
228+ if ( event . sender . sshStream ) {
229+ event . sender . sshStream . end ( ) ;
230+ event . sender . sshStream = null ;
231+ }
232+
233+ // Cerrar la conexión
235234 conn . end ( ) ;
236235 activeConnections . delete ( profileName ) ;
237236 return { success : true , message : 'Desconectado' } ;
0 commit comments