@@ -129,6 +129,13 @@ async function initiateRemoteTerminal(terminal: Terminal): Promise<void | Reconn
129
129
return socket ;
130
130
}
131
131
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
+
132
139
async function createTerminal (
133
140
element : HTMLElement ,
134
141
toDispose : DisposableCollection ,
@@ -197,17 +204,12 @@ async function createTerminal(
197
204
const debouncedUpdateTerminalSize = debounce ( ( ) => updateTerminalSize ( term ) , 200 , { trailing : true } ) ;
198
205
window . onresize = ( ) => debouncedUpdateTerminalSize ( ) ;
199
206
207
+ // Register the onclick event for the reconnect button
208
+ reconnectButton . onclick = ( ) => terminalSocket . reconnect ( ) ;
209
+
200
210
return { terminal : term , socket : terminalSocket } ;
201
211
}
202
212
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
-
211
213
function handleDisconnected ( e : CloseEvent | ErrorEvent , socket : ReconnectingWebSocket ) {
212
214
if ( socket . retryCount < webSocketSettings . maxRetries ) {
213
215
console . info ( "Tried to reconnect WS, proceeding" ) ;
@@ -294,13 +296,19 @@ window.gitpod.ideService = {
294
296
toDispose . push ( {
295
297
dispose : ( ) => {
296
298
state = "terminated" ;
297
- window . socket ?. close ( ) ;
298
299
onDidChangeState . fire ( ) ;
299
300
} ,
300
301
} ) ;
301
302
const terminalContainer = document . getElementById ( "terminal-container" ) ;
302
303
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
+ } ) ;
304
312
}
305
313
return toDispose ;
306
314
} ,
0 commit comments