@@ -66,35 +66,43 @@ export class RemoteSession extends Disposable {
6666 this . usePublicApi = await this . experiments . getUsePublicAPI ( this . connectionInfo . gitpodHost ) ;
6767 this . logService . info ( `Going to use ${ this . usePublicApi ? 'public' : 'server' } API` ) ;
6868
69- let instanceId : string ;
7069 if ( this . usePublicApi ) {
7170 this . workspaceState = new WorkspaceState ( this . connectionInfo . workspaceId , this . sessionService , this . logService ) ;
72- await this . workspaceState . initialize ( ) ;
73- if ( ! this . workspaceState . instanceId || ! this . workspaceState . isWorkspaceRunning ) {
74- throw new NoRunningInstanceError ( this . connectionInfo . workspaceId , this . workspaceState . workspaceData . phase ) ;
75- }
71+ this . workspaceState . initialize ( )
72+ . then ( ( ) => {
73+ if ( ! this . workspaceState ! . instanceId || ! this . workspaceState ! . isWorkspaceRunning ) {
74+ vscode . commands . executeCommand ( 'workbench.action.remote.close' ) ;
75+ return ;
76+ }
77+ const instanceId = this . workspaceState ! . instanceId ;
78+ if ( instanceId !== this . connectionInfo . instanceId ) {
79+ this . logService . info ( `Updating workspace ${ this . connectionInfo . workspaceId } latest instance id ${ this . connectionInfo . instanceId } => ${ instanceId } ` ) ;
80+ this . connectionInfo . instanceId = instanceId ;
81+ }
82+
83+ const { sshDestStr } = getGitpodRemoteWindowConnectionInfo ( this . context ) ! ;
84+ this . context . globalState . update ( `${ SSH_DEST_KEY } ${ sshDestStr } ` , { ...this . connectionInfo } as SSHConnectionParams ) ;
85+ } ) ;
7686
7787 this . _register ( this . workspaceState . onWorkspaceWillStop ( async ( ) => {
7888 await this . remoteService . saveRestartInfo ( ) ;
7989 vscode . commands . executeCommand ( 'workbench.action.remote.close' ) ;
8090 } ) ) ;
81- instanceId = this . workspaceState . instanceId ;
8291 } else {
8392 const workspaceInfo = await withServerApi ( this . sessionService . getGitpodToken ( ) , this . connectionInfo . gitpodHost , service => service . server . getWorkspace ( this . connectionInfo . workspaceId ) , this . logService ) ;
8493 if ( ! workspaceInfo . latestInstance || workspaceInfo . latestInstance ?. status ?. phase === 'stopping' || workspaceInfo . latestInstance ?. status ?. phase === 'stopped' ) {
8594 throw new NoRunningInstanceError ( this . connectionInfo . workspaceId , workspaceInfo . latestInstance ?. status ?. phase ) ;
8695 }
87- instanceId = workspaceInfo . latestInstance . id ;
88- }
96+ const instanceId = workspaceInfo . latestInstance . id ;
97+ if ( instanceId !== this . connectionInfo . instanceId ) {
98+ this . logService . info ( `Updating workspace ${ this . connectionInfo . workspaceId } latest instance id ${ this . connectionInfo . instanceId } => ${ instanceId } ` ) ;
99+ this . connectionInfo . instanceId = instanceId ;
100+ }
89101
90- if ( instanceId !== this . connectionInfo . instanceId ) {
91- this . logService . info ( `Updating workspace ${ this . connectionInfo . workspaceId } latest instance id ${ this . connectionInfo . instanceId } => ${ instanceId } ` ) ;
92- this . connectionInfo . instanceId = instanceId ;
102+ const { sshDestStr } = getGitpodRemoteWindowConnectionInfo ( this . context ) ! ;
103+ this . context . globalState . update ( `${ SSH_DEST_KEY } ${ sshDestStr } ` , { ...this . connectionInfo } as SSHConnectionParams ) ;
93104 }
94105
95- const { sshDestStr } = getGitpodRemoteWindowConnectionInfo ( this . context ) ! ;
96- await this . context . globalState . update ( `${ SSH_DEST_KEY } ${ sshDestStr } ` , { ...this . connectionInfo } as SSHConnectionParams ) ;
97-
98106 this . heartbeatManager = new HeartbeatManager ( this . connectionInfo , this . workspaceState , this . sessionService , this . logService , this . telemetryService ) ;
99107
100108 this . remoteService . initializeRemoteExtensions ( ) ;
0 commit comments