1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-06-08 15:30:59 +03:00
parent 86fff0defa
commit 9c8381bac9

View File

@ -8,7 +8,6 @@ import { Kubectl } from "./kubectl"
import { tracker } from "./tracker" import { tracker } from "./tracker"
import { Cluster, ClusterPreferences } from "./cluster" import { Cluster, ClusterPreferences } from "./cluster"
import { helmCli } from "./helm-cli" import { helmCli } from "./helm-cli"
import logger from "./logger"
export class ShellSession extends EventEmitter { export class ShellSession extends EventEmitter {
static shellEnv: any static shellEnv: any
@ -160,14 +159,12 @@ export class ShellSession extends EventEmitter {
} }
protected exit(code = 1000) { protected exit(code = 1000) {
logger.debug("Shell closed")
if (this.websocket.readyState == this.websocket.OPEN) this.websocket.close(code) if (this.websocket.readyState == this.websocket.OPEN) this.websocket.close(code)
this.emit('exit') this.emit('exit')
} }
protected closeWebsocketOnProcessExit() { protected closeWebsocketOnProcessExit() {
this.shellProcess.on("exit", (code) => { this.shellProcess.on("exit", (code) => {
logger.debug("Shell process exited", code)
this.running = false this.running = false
let timeout = 0 let timeout = 0
if (code > 0) { if (code > 0) {
@ -182,19 +179,18 @@ export class ShellSession extends EventEmitter {
protected exitProcessOnWebsocketClose() { protected exitProcessOnWebsocketClose() {
this.websocket.on("close", () => { this.websocket.on("close", () => {
logger.debug("Killing shell process")
this.killShellProcess() this.killShellProcess()
}) })
} }
protected killShellProcess(){ protected killShellProcess(){
if(this.running) { if(this.running) {
// For windows we need to kill the shell process by pid, since Lens won't respond after a while if using `this.shellProcess.kill()` // On Windows we need to kill the shell process by pid, since Lens won't respond after a while if using `this.shellProcess.kill()`
if (process.platform == "win32") { if (process.platform == "win32") {
try { try {
process.kill(this.shellProcess.pid) process.kill(this.shellProcess.pid)
} catch(e) { } catch(e) {
logger.debug("Process id not exist") return
} }
} else { } else {
this.shellProcess.kill() this.shellProcess.kill()