@@ -62,6 +62,7 @@ export class Gate {
62
62
sshPort : number
63
63
reconnectCount : number
64
64
lastState : ServerPayload
65
+ wasSSH : boolean | undefined
65
66
constructor ( props ) {
66
67
// given properties
67
68
this . id = props . id
@@ -206,9 +207,9 @@ export class Gate {
206
207
async handleFailure ( failure : Failure ) {
207
208
// KeyRejected and WrongPassword are "light failure"
208
209
const shell = this . map . shell
209
- const wasSSH = this . session ?. isSSH
210
210
const closeSession = ( ) => {
211
211
if ( this . session ) {
212
+ this . wasSSH = this . session . isSSH
212
213
this . session . close ( )
213
214
this . session = null
214
215
}
@@ -235,7 +236,6 @@ export class Gate {
235
236
this . marker = null
236
237
closeSession ( )
237
238
await this . connect ( )
238
- // We should probably replace the next to lines with a break
239
239
return
240
240
241
241
case Failure . NoKey :
@@ -248,7 +248,7 @@ export class Gate {
248
248
return
249
249
250
250
case Failure . NotSupported :
251
- if ( wasSSH ) {
251
+ if ( this . wasSSH ) {
252
252
this . notify ( "SSH status unknown" )
253
253
} else
254
254
this . notify ( "WebRTC agent unreachable" )
@@ -282,34 +282,30 @@ export class Gate {
282
282
283
283
}
284
284
closeSession ( )
285
- if ( wasSSH ) {
286
- await this . handleSSHFailure ( )
287
- return
288
- }
289
- // TODO: move thgis to the top
290
285
if ( ! terminal7 . isActive ( this ) ) {
291
286
this . stopBoarding ( )
292
287
return
293
288
}
289
+ if ( this . firstConnection ) {
290
+ this . onFirstConnectionDisconnect ( )
291
+ return
292
+ }
293
+
294
+ if ( this . wasSSH ) {
295
+ await this . handleSSHFailure ( )
296
+ return
297
+ }
294
298
if ( terminal7 . recovering ) {
295
299
terminal7 . log ( "retrying..." )
296
300
try {
297
301
await this . reconnect ( )
298
302
} catch ( e ) {
299
303
terminal7 . log ( "reconnect failed" , e )
300
- this . notify ( "reconnect failed: " + e )
301
-
302
- } finally {
303
- terminal7 . log ( "reconnect done" )
304
+ this . notify ( "Reconnect failed: " + e )
304
305
}
305
306
return
306
307
}
307
308
308
- if ( this . firstConnection ) {
309
- this . onFirstConnectionDisconnect ( )
310
- return
311
- }
312
-
313
309
let res : string
314
310
try {
315
311
res = await shell . runForm ( shell . reconnectForm , "menu" )
@@ -369,7 +365,7 @@ export class Gate {
369
365
reconnect ( ) : Promise < void > {
370
366
return new Promise ( ( resolve , reject ) => {
371
367
const session = this . session
372
- const isSSH = session ?. isSSH
368
+ const isSSH = session ?session . isSSH : this . wasSSH
373
369
const isNative = Capacitor . isNativePlatform ( )
374
370
console . log ( `reconnecting: # ${ this . reconnectCount } ${ ( session === null ) ?"null session " :"has session " } \
375
371
${ isSSH ?"is ssh" :"is webrtc" } ` )
@@ -396,22 +392,23 @@ export class Gate {
396
392
this . setLayout ( JSON . parse ( layout ) as ServerPayload )
397
393
resolve ( )
398
394
}
399
- if ( ! isSSH && ! isNative ) {
395
+ if ( ! isNative ) {
400
396
this . session . reconnect ( this . marker )
401
397
. then ( layout => finish ( layout ) )
402
398
. catch ( e => {
403
399
if ( this . session ) {
400
+ this . wasSSH = this . session . isSSH
404
401
this . session . close ( )
405
402
this . session = null
406
403
}
407
- terminal7 . log ( "reconnect failed, calling the shell to handle it " , isSSH )
404
+ terminal7 . log ( "reconnect failed: " , e )
408
405
reject ( e )
409
- // this.map.shell.onDisconnect(this, isSSH).then(resolve).catch(reject)
410
406
} )
411
407
return
412
408
}
413
409
const closeSessionAndDisconnect = ( e ) => {
414
- if ( this . session && ! this . session . isSSH ) {
410
+ if ( this . session ) {
411
+ this . wasSSH = this . session . isSSH
415
412
this . session . close ( )
416
413
this . session = null
417
414
}
@@ -918,6 +915,7 @@ export class Gate {
918
915
}
919
916
} , 10 )
920
917
if ( this . session ) {
918
+ this . wasSSH = this . session . isSSH
921
919
this . session . close ( )
922
920
this . session = null
923
921
}
0 commit comments