@@ -5,7 +5,14 @@ process.on("uncaughtException", e => {
5
5
signale . fatal ( e ) ;
6
6
dialog . showErrorBox ( "eEDEX-UI failed to launch" , e . message || "Cannot retrieve error message." ) ;
7
7
if ( tty ) {
8
- tty . tty . kill ( ) ;
8
+ tty . close ( ) ;
9
+ }
10
+ if ( extraTtys ) {
11
+ Object . keys ( extraTtys ) . forEach ( key => {
12
+ if ( extraTtys [ key ] !== null ) {
13
+ extraTtys [ key ] . close ( ) ;
14
+ }
15
+ } ) ;
9
16
}
10
17
} ) ;
11
18
@@ -26,7 +33,7 @@ ipc.on("log", (e, type, content) => {
26
33
signale [ type ] ( content ) ;
27
34
} ) ;
28
35
29
- var win , tty ;
36
+ var win , tty , extraTtys ;
30
37
const settingsFile = path . join ( electron . app . getPath ( "userData" ) , "settings.json" ) ;
31
38
const themesDir = path . join ( electron . app . getPath ( "userData" ) , "themes" ) ;
32
39
const innerThemesDir = path . join ( __dirname , "assets/themes" ) ;
@@ -173,6 +180,57 @@ app.on('ready', () => {
173
180
} ) ;
174
181
175
182
createWindow ( settings ) ;
183
+
184
+ // Support for more terminals, used for creating tabs (currently limited to 4 extra terms)
185
+ extraTtys = { } ;
186
+ let basePort = settings . port || 3000 ;
187
+ basePort = Number ( basePort ) + 2 ;
188
+
189
+ for ( let i = 0 ; i < 4 ; i ++ ) {
190
+ extraTtys [ basePort + i ] = null ;
191
+ }
192
+
193
+ ipc . on ( "ttyspawn" , ( e , arg ) => {
194
+ let port = null ;
195
+ Object . keys ( extraTtys ) . forEach ( key => {
196
+ if ( extraTtys [ key ] === null && port === null ) {
197
+ extraTtys [ key ] = { } ;
198
+ port = key ;
199
+ }
200
+ } ) ;
201
+
202
+ if ( port === null ) {
203
+ signale . error ( "TTY spawn denied (Reason: exceeded max TTYs number)" ) ;
204
+ e . sender . send ( "ttyspawn-reply" , "ERROR: max number of ttys reached" ) ;
205
+ } else {
206
+ signale . pending ( `Creating new TTY process on port ${ port } ` ) ;
207
+ let term = new Terminal ( {
208
+ role : "server" ,
209
+ shell : settings . shell . split ( " " ) [ 0 ] ,
210
+ params : settings . shell . split ( " " ) . splice ( 1 ) ,
211
+ cwd : tty . tty . _cwd || settings . cwd ,
212
+ port : port
213
+ } ) ;
214
+ signale . success ( `New terminal back-end initialized at ${ port } ` ) ;
215
+ term . onclosed = ( code , signal ) => {
216
+ tty . ondisconnected = ( ) => { } ;
217
+ signale . complete ( `TTY exited at ${ port } ` , code , signal ) ;
218
+ extraTtys [ term . port ] = null ;
219
+ delete term ;
220
+ } ;
221
+ term . onopened = ( ) => {
222
+ signale . success ( `TTY ${ port } connected to frontend` ) ;
223
+ } ;
224
+ term . ondisconnected = ( ) => {
225
+ term . onclosed = ( ) => { } ;
226
+ term . close ( ) ;
227
+ extraTtys [ term . port ] = null ;
228
+ delete term ;
229
+ } ;
230
+
231
+ extraTtys [ port ] = term ;
232
+ }
233
+ } ) ;
176
234
} ) ;
177
235
178
236
app . on ( 'web-contents-created' , ( e , contents ) => {
@@ -193,6 +251,11 @@ app.on('window-all-closed', () => {
193
251
} ) ;
194
252
195
253
app . on ( 'before-quit' , ( ) => {
196
- tty . tty . kill ( ) ;
254
+ tty . close ( ) ;
255
+ Object . keys ( extraTtys ) . forEach ( key => {
256
+ if ( extraTtys [ key ] !== null ) {
257
+ extraTtys [ key ] . close ( ) ;
258
+ }
259
+ } ) ;
197
260
signale . complete ( "Shutting down..." ) ;
198
261
} ) ;
0 commit comments