@@ -107,10 +107,6 @@ export default class RemoteConnector extends Disposable {
107
107
super ( ) ;
108
108
109
109
this . releaseStaleLocks ( ) ;
110
-
111
- if ( vscode . env . remoteName && context . extension . extensionKind === vscode . ExtensionKind . UI ) {
112
- this . _register ( vscode . commands . registerCommand ( 'gitpod.api.autoTunnel' , this . autoTunnelCommand . bind ( this ) ) ) ;
113
- }
114
110
}
115
111
116
112
private releaseStaleLocks ( ) : void {
@@ -666,8 +662,6 @@ export default class RemoteConnector extends Disposable {
666
662
if ( password ) {
667
663
await this . showSSHPasswordModal ( password ) ;
668
664
}
669
-
670
- this . telemetry . sendTelemetryEvent ( 'vscode_desktop_ssh' , { kind : 'gateway' , status : 'connected' , ...params } ) ;
671
665
} catch ( e ) {
672
666
this . telemetry . sendTelemetryEvent ( 'vscode_desktop_ssh' , { kind : 'gateway' , status : 'failed' , reason : e . toString ( ) , ...params } ) ;
673
667
if ( e instanceof NoSSHGatewayError ) {
@@ -706,8 +700,6 @@ export default class RemoteConnector extends Disposable {
706
700
const localAppDestData = await this . getWorkspaceLocalAppSSHDestination ( params ) ;
707
701
sshDestination = localAppDestData . localAppSSHDest ;
708
702
localAppSSHConfigPath = localAppDestData . localAppSSHConfigPath ;
709
-
710
- this . telemetry . sendTelemetryEvent ( 'vscode_desktop_ssh' , { kind : 'local-app' , status : 'connected' , ...params } ) ;
711
703
} catch ( e ) {
712
704
this . logger . error ( `Failed to connect ${ params . workspaceId } Gitpod workspace:` , e ) ;
713
705
if ( e instanceof LocalAppError ) {
@@ -734,6 +726,8 @@ export default class RemoteConnector extends Disposable {
734
726
735
727
await this . updateRemoteSSHConfig ( usingSSHGateway , localAppSSHConfigPath ) ;
736
728
729
+ await this . context . globalState . update ( sshDestination ! , { ...params , usingSSHGateway } ) ;
730
+
737
731
vscode . commands . executeCommand (
738
732
'vscode.openFolder' ,
739
733
vscode . Uri . parse ( `vscode-remote://ssh-remote+${ sshDestination } ${ uri . path || '/' } ` ) ,
@@ -748,7 +742,7 @@ export default class RemoteConnector extends Disposable {
748
742
const configKey = `config/${ authority } ` ;
749
743
const localAppconfig = this . context . globalState . get < LocalAppConfig > ( configKey ) ;
750
744
if ( ! localAppconfig || checkRunning ( localAppconfig . pid ) !== true ) {
751
- // Do nothing if we are using SSH gateway
745
+ // Do nothing if we are using SSH gateway and local app is not running
752
746
return ;
753
747
}
754
748
}
@@ -766,4 +760,53 @@ export default class RemoteConnector extends Disposable {
766
760
this . logger . error ( 'Failed to disable auto tunneling:' , e ) ;
767
761
}
768
762
}
763
+
764
+ public async checkRemoteConnectionSuccessful ( ) {
765
+ const isRemoteExtensionHostRunning = async ( ) => {
766
+ try {
767
+ // Invoke command from gitpot-remote extension to test if connection is successful
768
+ await vscode . commands . executeCommand ( '__gitpod.getGitpodRemoteLogsUri' ) ;
769
+ return true ;
770
+ } catch {
771
+ return false ;
772
+ }
773
+ } ;
774
+
775
+ const remoteUri = vscode . workspace . workspaceFile || vscode . workspace . workspaceFolders ?. [ 0 ] . uri ;
776
+ if ( vscode . env . remoteName === 'ssh-remote' && this . context . extension . extensionKind === vscode . ExtensionKind . UI && remoteUri ) {
777
+ const [ , sshDestStr ] = remoteUri . authority . split ( '+' ) ;
778
+ const sshDest : { user : string ; hostName : string } = JSON . parse ( Buffer . from ( sshDestStr , 'hex' ) . toString ( 'utf8' ) ) ;
779
+ const gitpodHost = vscode . workspace . getConfiguration ( 'gitpod' ) . get < string > ( 'host' ) ! ;
780
+ const host = new URL ( gitpodHost ) . host ;
781
+ const connectionSuccessful = sshDest . hostName . endsWith ( host ) && await isRemoteExtensionHostRunning ( ) ;
782
+
783
+ const connectionInfo = this . context . globalState . get < SSHConnectionParams & { usingSSHGateway : boolean } > ( sshDestStr ) ;
784
+ if ( connectionInfo ) {
785
+ const kind = connectionInfo . usingSSHGateway ? 'gateway' : 'local-app' ;
786
+ if ( connectionSuccessful ) {
787
+ this . telemetry . sendTelemetryEvent ( 'vscode_desktop_ssh' , {
788
+ kind,
789
+ status : 'connected' ,
790
+ instanceId : connectionInfo . instanceId ,
791
+ workspaceId : connectionInfo . workspaceId ,
792
+ gitpodHost : connectionInfo . gitpodHost
793
+ } ) ;
794
+ } else {
795
+ this . telemetry . sendTelemetryEvent ( 'vscode_desktop_ssh' , {
796
+ kind,
797
+ status : 'failed' ,
798
+ reason : 'remote-ssh extension: connection failed' ,
799
+ instanceId : connectionInfo . instanceId ,
800
+ workspaceId : connectionInfo . workspaceId ,
801
+ gitpodHost : connectionInfo . gitpodHost
802
+ } ) ;
803
+ }
804
+ await this . context . globalState . update ( remoteUri . authority , undefined ) ;
805
+ }
806
+
807
+ return connectionSuccessful ;
808
+ }
809
+
810
+ return false ;
811
+ }
769
812
}
0 commit comments