@@ -129,6 +129,13 @@ async function initiateRemoteTerminal(terminal: Terminal): Promise<void | Reconn
129129 return socket ;
130130}
131131
132+ const reconnectButton = document . createElement ( "button" ) ;
133+ reconnectButton . innerText = "Reconnect" ;
134+
135+ const reloadButton = document . createElement ( "button" ) ;
136+ reloadButton . innerText = "Reload page" ;
137+ reloadButton . onclick = ( ) => location . reload ( ) ;
138+
132139async function createTerminal (
133140 element : HTMLElement ,
134141 toDispose : DisposableCollection ,
@@ -197,17 +204,12 @@ async function createTerminal(
197204 const debouncedUpdateTerminalSize = debounce ( ( ) => updateTerminalSize ( term ) , 200 , { trailing : true } ) ;
198205 window . onresize = ( ) => debouncedUpdateTerminalSize ( ) ;
199206
207+ // Register the onclick event for the reconnect button
208+ reconnectButton . onclick = ( ) => terminalSocket . reconnect ( ) ;
209+
200210 return { terminal : term , socket : terminalSocket } ;
201211}
202212
203- const reloadButton = document . createElement ( "button" ) ;
204- reloadButton . innerText = "Reload page" ;
205- reloadButton . onclick = ( ) => location . reload ( ) ;
206-
207- const reconnectButton = document . createElement ( "button" ) ;
208- reconnectButton . innerText = "Reconnect" ;
209- reconnectButton . onclick = ( ) => window . socket ?. reconnect ( ) ;
210-
211213function handleDisconnected ( e : CloseEvent | ErrorEvent , socket : ReconnectingWebSocket ) {
212214 if ( socket . retryCount < webSocketSettings . maxRetries ) {
213215 console . info ( "Tried to reconnect WS, proceeding" ) ;
@@ -294,13 +296,19 @@ window.gitpod.ideService = {
294296 toDispose . push ( {
295297 dispose : ( ) => {
296298 state = "terminated" ;
297- window . socket ?. close ( ) ;
298299 onDidChangeState . fire ( ) ;
299300 } ,
300301 } ) ;
301302 const terminalContainer = document . getElementById ( "terminal-container" ) ;
302303 if ( terminalContainer && ! terminalContainer . classList . contains ( "init" ) ) {
303- createTerminal ( terminalContainer , toDispose ) . then ( ( ) => terminalContainer . classList . add ( "init" ) ) ;
304+ createTerminal ( terminalContainer , toDispose ) . then ( ( { socket } ) => {
305+ terminalContainer . classList . add ( "init" ) ;
306+ toDispose . push ( {
307+ dispose : ( ) => {
308+ socket . close ( ) ;
309+ } ,
310+ } ) ;
311+ } ) ;
304312 }
305313 return toDispose ;
306314 } ,
0 commit comments