From 1f3874aa565dc5cb429d49b58fbacb14a86703de Mon Sep 17 00:00:00 2001 From: Roberto Bruggemann Date: Mon, 5 Feb 2018 17:33:24 +0000 Subject: [PATCH] Delete underlying pipe when terminal window closes --- client/app/scripts/components/terminal.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/app/scripts/components/terminal.js b/client/app/scripts/components/terminal.js index 92e1ad517..aae057351 100644 --- a/client/app/scripts/components/terminal.js +++ b/client/app/scripts/components/terminal.js @@ -56,7 +56,7 @@ function terminalCellSize(wrapperNode) { } -function openNewWindow(url, bcr, minWidth = 200) { +function openNewWindow(url, bcr, pipeId, minWidth = 200) { const screenLeft = window.screenX || window.screenLeft; const screenTop = window.screenY || window.screenTop; const popoutWindowToolbarHeight = 51; @@ -164,6 +164,7 @@ class Terminal extends React.Component { if (this.props.connect) { this.mountTerminal(); } + window.addEventListener('beforeunload', this.handleBeforeUnload); } mountTerminal() { @@ -206,6 +207,7 @@ class Terminal extends React.Component { clearTimeout(this.resizeTimeout); window.removeEventListener('resize', this.handleResizeDebounced); + window.removeEventListener('beforeunload', this.handleBeforeUnload); if (this.term) { log('destroy terminal'); @@ -238,6 +240,10 @@ class Terminal extends React.Component { } } + handleBeforeUnload() { + deletePipe(this.getPipeId()); + } + handleCloseClick(ev) { ev.preventDefault(); this.props.dispatch(clickCloseTerminal(this.getPipeId())); @@ -251,7 +257,7 @@ class Terminal extends React.Component { const bcr = this.node.getBoundingClientRect(); const minWidth = (this.state.characterWidth * 80) + (8 * 2); - openNewWindow(`${basePath(window.location.pathname)}/terminal.html#!/state/${paramString}`, bcr, minWidth); + openNewWindow(`${basePath(window.location.pathname)}/terminal.html#!/state/${paramString}`, bcr, this.getPipeId(), minWidth); } handleResize() {