Skip to content

Commit

Permalink
Terminal tab auto-close fixes (#314)
Browse files Browse the repository at this point in the history
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
  • Loading branch information
jakolehm authored Apr 28, 2020
1 parent 1050215 commit b8fd404
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dashboard/client/components/dock/terminal-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Props extends DockTabProps {
@observer
export class TerminalTab extends React.Component<Props> {
componentDidMount() {
reaction(() => this.isDisconnected, () => {
reaction(() => this.isDisconnected === true, () => {
dockStore.closeTab(this.tabId)
})
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/shell-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class ShellSession extends EventEmitter {
protected kubectlBinDir: string;
protected helmBinDir: string;
protected preferences: ClusterPreferences;
protected running = false;

constructor(socket: WebSocket, pathToKubeconfig: string, cluster: Cluster) {
super()
Expand All @@ -42,6 +43,7 @@ export class ShellSession extends EventEmitter {
name: "xterm-256color",
rows: 30,
});
this.running = true;

this.pipeStdout()
this.pipeStdin()
Expand Down Expand Up @@ -137,6 +139,8 @@ export class ShellSession extends EventEmitter {
protected pipeStdin() {
// write websocket messages to shellProcess
this.websocket.on("message", function(data: string) {
if (!this.running) { return }

const message = Buffer.from(data.slice(1, data.length), "base64").toString()
switch (data[0]) {
case "0":
Expand All @@ -160,8 +164,16 @@ export class ShellSession extends EventEmitter {
}

protected closeWebsocketOnProcessExit() {
this.shellProcess.on("exit", (_code) => {
this.exit()
this.shellProcess.on("exit", (code) => {
this.running = false
let timeout = 0
if (code > 0) {
this.sendResponse("Terminal will auto-close in 15 seconds ...")
timeout = 15*1000
}
setTimeout(() => {
this.exit()
}, timeout)
});
}

Expand Down

0 comments on commit b8fd404

Please sign in to comment.