@@ -85,7 +85,7 @@ async function initAddons(term: Terminal): Promise<void> {
85
85
term . unicode . activeVersion = '11' ;
86
86
}
87
87
88
- async function initiateRemoteTerminal ( terminal : Terminal ) {
88
+ async function initiateRemoteTerminal ( terminal : Terminal ) : Promise < void | ReconnectingWebSocket > {
89
89
updateTerminalSize ( terminal ) ;
90
90
91
91
const ReconnectingWebSocket = ( await import ( "reconnecting-websocket" ) ) . default ;
@@ -110,7 +110,8 @@ async function initiateRemoteTerminal(terminal: Terminal) {
110
110
socketURL += serverProcessId ;
111
111
112
112
await initiateRemoteCommunicationChannelSocket ( protocol ) ;
113
- let socket = new ReconnectingWebSocket ( socketURL , [ ] , webSocketSettings ) ;
113
+
114
+ const socket = new ReconnectingWebSocket ( socketURL , [ ] , webSocketSettings ) ;
114
115
socket . onopen = async ( ) => {
115
116
outputDialog . close ( ) ;
116
117
( document . querySelector ( ".xterm-helper-textarea" ) as HTMLTextAreaElement ) . focus ( ) ;
@@ -121,9 +122,11 @@ async function initiateRemoteTerminal(terminal: Terminal) {
121
122
socket . onclose = handleDisconnected ;
122
123
//@ts -ignore
123
124
socket . onerror = handleDisconnected ;
125
+
126
+ return socket ;
124
127
}
125
128
126
- async function createTerminal ( element : HTMLElement , toDispose : DisposableCollection ) : Promise < void > {
129
+ async function createTerminal ( element : HTMLElement , toDispose : DisposableCollection ) : Promise < { terminal : Terminal ; socket : ReconnectingWebSocket } > {
127
130
// Clean terminal
128
131
while ( element . children . length ) {
129
132
element . removeChild ( element . children [ 0 ] ) ;
@@ -185,10 +188,16 @@ async function createTerminal(element: HTMLElement, toDispose: DisposableCollect
185
188
updateTerminalSize ( term ) ;
186
189
term . focus ( ) ;
187
190
188
- await initiateRemoteTerminal ( term ) ;
191
+ const terminalSocket = await initiateRemoteTerminal ( term ) ;
192
+
193
+ if ( ! terminalSocket ) {
194
+ throw new Error ( "Couldn't set up a remote connection to the terminal process" ) ;
195
+ }
189
196
190
197
const debouncedUpdateTerminalSize = debounce ( ( ) => updateTerminalSize ( term ) , 200 , true ) ;
191
198
window . onresize = ( ) => debouncedUpdateTerminalSize ( ) ;
199
+
200
+ return { terminal : term , socket : terminalSocket } ;
192
201
}
193
202
194
203
const reloadButton = document . createElement ( "button" ) ;
@@ -291,8 +300,7 @@ window.gitpod.ideService = {
291
300
} )
292
301
const terminalContainer = document . getElementById ( "terminal-container" ) ;
293
302
if ( terminalContainer && ! terminalContainer . classList . contains ( "init" ) ) {
294
- createTerminal ( terminalContainer , toDispose ) ;
295
- terminalContainer . classList . add ( "init" ) ;
303
+ createTerminal ( terminalContainer , toDispose ) . then ( ( ) => terminalContainer . classList . add ( "init" ) ) ;
296
304
}
297
305
return toDispose ;
298
306
}
0 commit comments