@@ -165,7 +165,7 @@ export class RemoteTunnelService extends Disposable implements IRemoteTunnelServ
165165 }
166166
167167 async startTunnel ( session : IRemoteTunnelSession ) : Promise < TunnelStatus > {
168- if ( isSameSession ( session , this . _session ) ) {
168+ if ( isSameSession ( session , this . _session ) && this . _tunnelStatus . type !== 'disconnected' ) {
169169 return this . _tunnelStatus ;
170170 }
171171 this . setSession ( session ) ;
@@ -195,7 +195,7 @@ export class RemoteTunnelService extends Disposable implements IRemoteTunnelServ
195195 }
196196 } ;
197197 try {
198- await this . runCodeTunneCommand ( 'stop' , [ 'kill' ] , onOutput ) ;
198+ await this . runCodeTunnelCommand ( 'stop' , [ 'kill' ] , onOutput ) ;
199199 } catch ( e ) {
200200 this . _logger . error ( e ) ;
201201 }
@@ -213,26 +213,35 @@ export class RemoteTunnelService extends Disposable implements IRemoteTunnelServ
213213 }
214214
215215 let isAttached = false ;
216+ let output = '' ;
216217
217218 const onOutput = ( a : string , isErr : boolean ) => {
218219 if ( isErr ) {
219220 this . _logger . error ( a ) ;
220221 } else {
221- this . _logger . info ( a ) ;
222+ output += a ;
222223 }
223224 if ( ! this . environmentService . isBuilt && a . startsWith ( ' Compiling' ) ) {
224225 this . setTunnelStatus ( TunnelStates . connecting ( localize ( 'remoteTunnelService.building' , 'Building CLI from sources' ) ) ) ;
225226 }
226227 } ;
227228
228- const statusProcess = this . runCodeTunneCommand ( 'status' , [ 'status' ] , onOutput ) ;
229+ const statusProcess = this . runCodeTunnelCommand ( 'status' , [ 'status' ] , onOutput ) ;
229230 this . _tunnelProcess = statusProcess ;
230231 try {
231- const status = await statusProcess ;
232+ await statusProcess ;
232233 if ( this . _tunnelProcess !== statusProcess ) {
233234 return ;
234235 }
235- isAttached = status === 0 ;
236+
237+ // split and find the line, since in dev builds additional noise is
238+ // added by cargo to the output.
239+ const status : {
240+ service_installed : boolean ;
241+ tunnel : object | null ;
242+ } = JSON . parse ( output . trim ( ) . split ( '\n' ) . find ( l => l . startsWith ( '{' ) ) ! ) ;
243+
244+ isAttached = ! ! status . tunnel ;
236245 this . _logger . info ( isAttached ? 'Other tunnel running, attaching...' : 'No other tunnel running' ) ;
237246 if ( ! isAttached && ! this . _session ) {
238247 this . _tunnelProcess = undefined ;
@@ -255,7 +264,7 @@ export class RemoteTunnelService extends Disposable implements IRemoteTunnelServ
255264 a = a . replaceAll ( token , '*' . repeat ( 4 ) ) ;
256265 onOutput ( a , isErr ) ;
257266 } ;
258- const loginProcess = this . runCodeTunneCommand ( 'login' , [ 'user' , 'login' , '--provider' , session . providerId , '--access-token' , token , '--log' , LogLevelToString ( this . _logger . getLevel ( ) ) ] , onLoginOutput ) ;
267+ const loginProcess = this . runCodeTunnelCommand ( 'login' , [ 'user' , 'login' , '--provider' , session . providerId , '--access-token' , token , '--log' , LogLevelToString ( this . _logger . getLevel ( ) ) ] , onLoginOutput ) ;
259268 this . _tunnelProcess = loginProcess ;
260269 try {
261270 await loginProcess ;
@@ -286,7 +295,7 @@ export class RemoteTunnelService extends Disposable implements IRemoteTunnelServ
286295 if ( this . _preventSleep ( ) ) {
287296 args . push ( '--no-sleep' ) ;
288297 }
289- const serveCommand = this . runCodeTunneCommand ( 'tunnel' , args , ( message : string , isErr : boolean ) => {
298+ const serveCommand = this . runCodeTunnelCommand ( 'tunnel' , args , ( message : string , isErr : boolean ) => {
290299 if ( isErr ) {
291300 this . _logger . error ( message ) ;
292301 } else {
@@ -315,7 +324,7 @@ export class RemoteTunnelService extends Disposable implements IRemoteTunnelServ
315324 } ) ;
316325 }
317326
318- private runCodeTunneCommand ( logLabel : string , commandArgs : string [ ] , onOutput : ( message : string , isError : boolean ) => void = ( ) => { } ) : CancelablePromise < number > {
327+ private runCodeTunnelCommand ( logLabel : string , commandArgs : string [ ] , onOutput : ( message : string , isError : boolean ) => void = ( ) => { } ) : CancelablePromise < number > {
319328 return createCancelablePromise < number > ( token => {
320329 return new Promise ( ( resolve , reject ) => {
321330 if ( token . isCancellationRequested ) {
0 commit comments