Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e0b8ff4

Browse files
committedSep 23, 2024·
Polishing
1 parent d1d039f commit e0b8ff4

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed
 

‎src/gate.ts

+20-22
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class Gate {
6262
sshPort: number
6363
reconnectCount: number
6464
lastState: ServerPayload
65+
wasSSH: boolean | undefined
6566
constructor (props) {
6667
// given properties
6768
this.id = props.id
@@ -206,9 +207,9 @@ export class Gate {
206207
async handleFailure(failure: Failure) {
207208
// KeyRejected and WrongPassword are "light failure"
208209
const shell = this.map.shell
209-
const wasSSH = this.session?.isSSH
210210
const closeSession = () => {
211211
if (this.session) {
212+
this.wasSSH = this.session.isSSH
212213
this.session.close()
213214
this.session = null
214215
}
@@ -235,7 +236,6 @@ export class Gate {
235236
this.marker = null
236237
closeSession()
237238
await this.connect()
238-
// We should probably replace the next to lines with a break
239239
return
240240

241241
case Failure.NoKey:
@@ -248,7 +248,7 @@ export class Gate {
248248
return
249249

250250
case Failure.NotSupported:
251-
if (wasSSH) {
251+
if (this.wasSSH) {
252252
this.notify("SSH status unknown")
253253
} else
254254
this.notify("WebRTC agent unreachable")
@@ -282,34 +282,30 @@ export class Gate {
282282

283283
}
284284
closeSession()
285-
if (wasSSH) {
286-
await this.handleSSHFailure()
287-
return
288-
}
289-
// TODO: move thgis to the top
290285
if (!terminal7.isActive(this)){
291286
this.stopBoarding()
292287
return
293288
}
289+
if (this.firstConnection) {
290+
this.onFirstConnectionDisconnect()
291+
return
292+
}
293+
294+
if (this.wasSSH) {
295+
await this.handleSSHFailure()
296+
return
297+
}
294298
if (terminal7.recovering) {
295299
terminal7.log("retrying...")
296300
try {
297301
await this.reconnect()
298302
} catch (e) {
299303
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)
304305
}
305306
return
306307
}
307308

308-
if (this.firstConnection) {
309-
this.onFirstConnectionDisconnect()
310-
return
311-
}
312-
313309
let res: string
314310
try {
315311
res = await shell.runForm(shell.reconnectForm, "menu")
@@ -369,7 +365,7 @@ export class Gate {
369365
reconnect(): Promise<void> {
370366
return new Promise((resolve, reject) => {
371367
const session = this.session
372-
const isSSH = session?.isSSH
368+
const isSSH = session?session.isSSH:this.wasSSH
373369
const isNative = Capacitor.isNativePlatform()
374370
console.log(`reconnecting: # ${this.reconnectCount} ${(session===null)?"null session ":"has session "} \
375371
${isSSH?"is ssh":"is webrtc"}`)
@@ -396,22 +392,23 @@ export class Gate {
396392
this.setLayout(JSON.parse(layout) as ServerPayload)
397393
resolve()
398394
}
399-
if (!isSSH && !isNative) {
395+
if (!isNative) {
400396
this.session.reconnect(this.marker)
401397
.then(layout => finish(layout))
402398
.catch(e => {
403399
if (this.session) {
400+
this.wasSSH = this.session.isSSH
404401
this.session.close()
405402
this.session = null
406403
}
407-
terminal7.log("reconnect failed, calling the shell to handle it", isSSH)
404+
terminal7.log("reconnect failed:", e)
408405
reject(e)
409-
// this.map.shell.onDisconnect(this, isSSH).then(resolve).catch(reject)
410406
})
411407
return
412408
}
413409
const closeSessionAndDisconnect = (e) => {
414-
if (this.session && !this.session.isSSH) {
410+
if (this.session) {
411+
this.wasSSH = this.session.isSSH
415412
this.session.close()
416413
this.session = null
417414
}
@@ -918,6 +915,7 @@ export class Gate {
918915
}
919916
}, 10)
920917
if (this.session) {
918+
this.wasSSH = this.session.isSSH
921919
this.session.close()
922920
this.session = null
923921
}

‎src/map.ts

-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ export class T7Map {
191191
if (ev.dt < 500) {
192192
ev.stopPropagation()
193193
const command = (ev.target.closest(".gate-edit"))? "edit" : "connect"
194-
console.log("tap", command)
195194
this.shell.runCommand(command, [g.name])
196195
.then(() => this.showLog(false))
197196
.catch(e => terminal7.notify(e))

‎src/shell.ts

-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ export class Shell {
483483
} else {
484484
this.t.writeln("\n For persistent sessions & WebRTC 🍯 please install webexec")
485485
install.splice(1, 0, { prompt: "Install" })
486-
// only for native platforms
487486
if (Capacitor.isNativePlatform())
488487
install.splice(2, 0, { prompt: "Always use SSH" })
489488
}

‎src/terminal7.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ export class Terminal7 {
244244
this.run(() => this.recovering=false, this.conf.net.timeout)
245245
// real work is done in updateNetworkStatus
246246
Network.getStatus().then(async s => await this.updateNetworkStatus(s))
247-
}
247+
} else
248+
this.log("app state change ignored")
248249
}
249250
/*
250251
* Terminal7.open opens terminal on the given DOM element,

0 commit comments

Comments
 (0)
Please sign in to comment.