@@ -15,7 +15,7 @@ import { RemoteConnector } from './remoteConnector';
15
15
import { SettingsSync } from './settingsSync' ;
16
16
import { TelemetryService } from './services/telemetryService' ;
17
17
import { RemoteSession } from './remoteSession' ;
18
- import { checkForStoppedWorkspaces , getGitpodRemoteWindowConnectionInfo } from './remote' ;
18
+ import { SSHConnectionParams , checkForStoppedWorkspaces , getGitpodRemoteWindowConnectionInfo } from './remote' ;
19
19
import { HostService } from './services/hostService' ;
20
20
import { SessionService } from './services/sessionService' ;
21
21
import { CommandManager } from './commandManager' ;
@@ -35,95 +35,106 @@ if (!global.fetch) {
35
35
const FIRST_INSTALL_KEY = 'gitpod-desktop.firstInstall' ;
36
36
37
37
let telemetryService : TelemetryService ;
38
- let remoteSession : RemoteSession ;
38
+ let remoteSession : RemoteSession | undefined ;
39
39
40
40
export async function activate ( context : vscode . ExtensionContext ) {
41
41
const extensionId = context . extension . id ;
42
42
const packageJSON = context . extension . packageJSON ;
43
43
44
- // sync between machines
45
- context . globalState . setKeysForSync ( [ ReleaseNotes . RELEASE_NOTES_LAST_READ_KEY ] ) ;
44
+ let remoteConnectionInfo : { remoteAuthority : string ; connectionInfo : SSHConnectionParams } | undefined ;
45
+ let success = false ;
46
+ try {
47
+ // sync between machines
48
+ context . globalState . setKeysForSync ( [ ReleaseNotes . RELEASE_NOTES_LAST_READ_KEY ] ) ;
46
49
47
- const logger = vscode . window . createOutputChannel ( 'Gitpod' , { log : true } ) ;
48
- context . subscriptions . push ( logger ) ;
50
+ const logger = vscode . window . createOutputChannel ( 'Gitpod' , { log : true } ) ;
51
+ context . subscriptions . push ( logger ) ;
49
52
50
- const onDidChangeLogLevel = ( logLevel : vscode . LogLevel ) => {
51
- logger . info ( `Log level: ${ vscode . LogLevel [ logLevel ] } ` ) ;
52
- } ;
53
- context . subscriptions . push ( logger . onDidChangeLogLevel ( onDidChangeLogLevel ) ) ;
54
- onDidChangeLogLevel ( logger . logLevel ) ;
53
+ const onDidChangeLogLevel = ( logLevel : vscode . LogLevel ) => {
54
+ logger . info ( `Log level: ${ vscode . LogLevel [ logLevel ] } ` ) ;
55
+ } ;
56
+ context . subscriptions . push ( logger . onDidChangeLogLevel ( onDidChangeLogLevel ) ) ;
57
+ onDidChangeLogLevel ( logger . logLevel ) ;
55
58
56
- logger . info ( `${ extensionId } /${ packageJSON . version } (${ os . release ( ) } ${ os . platform ( ) } ${ os . arch ( ) } ) vscode/${ vscode . version } (${ vscode . env . appName } )` ) ;
59
+ logger . info ( `${ extensionId } /${ packageJSON . version } (${ os . release ( ) } ${ os . platform ( ) } ${ os . arch ( ) } ) vscode/${ vscode . version } (${ vscode . env . appName } )` ) ;
57
60
58
- telemetryService = new TelemetryService ( extensionId , packageJSON . version , packageJSON . segmentKey ) ;
61
+ telemetryService = new TelemetryService ( extensionId , packageJSON . version , packageJSON . segmentKey ) ;
59
62
60
- const notificationService = new NotificationService ( telemetryService ) ;
63
+ const notificationService = new NotificationService ( telemetryService ) ;
61
64
62
- const commandManager = new CommandManager ( ) ;
63
- context . subscriptions . push ( commandManager ) ;
65
+ const commandManager = new CommandManager ( ) ;
66
+ context . subscriptions . push ( commandManager ) ;
64
67
65
- // Create auth provider as soon as possible
66
- const authProvider = new GitpodAuthenticationProvider ( context , logger , telemetryService , notificationService ) ;
67
- context . subscriptions . push ( authProvider ) ;
68
+ // Create auth provider as soon as possible
69
+ const authProvider = new GitpodAuthenticationProvider ( context , logger , telemetryService , notificationService ) ;
70
+ context . subscriptions . push ( authProvider ) ;
68
71
69
- const hostService = new HostService ( context , notificationService , logger ) ;
70
- context . subscriptions . push ( hostService ) ;
72
+ const hostService = new HostService ( context , notificationService , logger ) ;
73
+ context . subscriptions . push ( hostService ) ;
71
74
72
- const sessionService = new SessionService ( hostService , logger ) ;
73
- context . subscriptions . push ( sessionService ) ;
75
+ const sessionService = new SessionService ( hostService , logger ) ;
76
+ context . subscriptions . push ( sessionService ) ;
74
77
75
- const experiments = new ExperimentalSettings ( 'gitpod' , packageJSON . version , sessionService , context , logger ) ;
76
- context . subscriptions . push ( experiments ) ;
78
+ const experiments = new ExperimentalSettings ( 'gitpod' , packageJSON . version , sessionService , context , logger ) ;
79
+ context . subscriptions . push ( experiments ) ;
77
80
78
- const settingsSync = new SettingsSync ( commandManager , logger , telemetryService , notificationService ) ;
79
- context . subscriptions . push ( settingsSync ) ;
81
+ const settingsSync = new SettingsSync ( commandManager , logger , telemetryService , notificationService ) ;
82
+ context . subscriptions . push ( settingsSync ) ;
80
83
81
- const remoteConnector = new RemoteConnector ( context , sessionService , hostService , experiments , logger , telemetryService , notificationService ) ;
82
- context . subscriptions . push ( remoteConnector ) ;
84
+ const remoteConnector = new RemoteConnector ( context , sessionService , hostService , experiments , logger , telemetryService , notificationService ) ;
85
+ context . subscriptions . push ( remoteConnector ) ;
83
86
84
- context . subscriptions . push ( vscode . window . registerUriHandler ( {
85
- handleUri ( uri : vscode . Uri ) {
86
- // logger.trace('Handling Uri...', uri.toString());
87
- if ( uri . path === GitpodServer . AUTH_COMPLETE_PATH ) {
88
- authProvider . handleUri ( uri ) ;
89
- } else {
90
- remoteConnector . handleUri ( uri ) ;
87
+ context . subscriptions . push ( vscode . window . registerUriHandler ( {
88
+ handleUri ( uri : vscode . Uri ) {
89
+ // logger.trace('Handling Uri...', uri.toString());
90
+ if ( uri . path === GitpodServer . AUTH_COMPLETE_PATH ) {
91
+ authProvider . handleUri ( uri ) ;
92
+ } else {
93
+ remoteConnector . handleUri ( uri ) ;
94
+ }
91
95
}
92
- }
93
- } ) ) ;
94
-
95
- const remoteConnectionInfo = getGitpodRemoteWindowConnectionInfo ( context ) ;
96
- if ( remoteConnectionInfo ) {
97
- commandManager . register ( { id : 'gitpod.api.autoTunnel' , execute : ( ) => remoteConnector . autoTunnelCommand } ) ;
98
-
99
- remoteSession = new RemoteSession ( remoteConnectionInfo . remoteAuthority , remoteConnectionInfo . connectionInfo , context , hostService , sessionService , settingsSync , experiments , logger , telemetryService , notificationService ) ;
100
- // Don't await this on purpose so it doesn't block extension activation.
101
- // Internally requesting a Gitpod Session requires the extension to be already activated.
102
- remoteSession . initialize ( ) ;
103
- } else if ( sessionService . isSignedIn ( ) ) {
104
- const restartFlow = { flow : 'restart_workspace' , userId : sessionService . getUserId ( ) } ;
105
- checkForStoppedWorkspaces ( context , hostService . gitpodHost , restartFlow , notificationService , logger ) ;
106
- }
96
+ } ) ) ;
107
97
108
- context . subscriptions . push ( new ReleaseNotes ( context , commandManager , logger ) ) ;
98
+ context . subscriptions . push ( new ReleaseNotes ( context , commandManager , logger ) ) ;
109
99
110
- if ( ! context . globalState . get < boolean > ( FIRST_INSTALL_KEY , false ) ) {
111
- await context . globalState . update ( FIRST_INSTALL_KEY , true ) ;
112
- telemetryService . sendTelemetryEvent ( 'gitpod_desktop_installation' , { kind : 'install' } ) ;
113
- }
100
+ // Register global commands
101
+ commandManager . register ( new SignInCommand ( sessionService ) ) ;
102
+ commandManager . register ( new ExportLogsCommand ( context . logUri , notificationService , telemetryService , logger ) ) ;
114
103
115
- // Register global commands
116
- commandManager . register ( new SignInCommand ( sessionService ) ) ;
117
- commandManager . register ( new ExportLogsCommand ( context . logUri , notificationService , telemetryService , logger ) ) ;
118
-
119
- telemetryService . sendTelemetryEvent ( 'vscode_desktop_activate' , {
120
- remoteName : vscode . env . remoteName || '' ,
121
- remoteUri : String ( ! ! ( vscode . workspace . workspaceFile || vscode . workspace . workspaceFolders ?. [ 0 ] . uri ) ) ,
122
- workspaceId : remoteConnectionInfo ?. connectionInfo . workspaceId || '' ,
123
- instanceId : remoteConnectionInfo ?. connectionInfo . instanceId || '' ,
124
- gitpodHost : remoteConnectionInfo ?. connectionInfo . gitpodHost || '' ,
125
- debugWorkspace : remoteConnectionInfo ? String ( ! ! remoteConnectionInfo . connectionInfo . debugWorkspace ) : '' ,
126
- } ) ;
104
+ if ( ! context . globalState . get < boolean > ( FIRST_INSTALL_KEY , false ) ) {
105
+ context . globalState . update ( FIRST_INSTALL_KEY , true ) ;
106
+ telemetryService . sendTelemetryEvent ( 'gitpod_desktop_installation' , { kind : 'install' } ) ;
107
+ }
108
+
109
+ remoteConnectionInfo = getGitpodRemoteWindowConnectionInfo ( context ) ;
110
+ // Because auth provider implementation is in the same extension, we need to wait for it to activate first
111
+ sessionService . didFirstLoad . then ( async ( ) => {
112
+ if ( remoteConnectionInfo ) {
113
+ commandManager . register ( { id : 'gitpod.api.autoTunnel' , execute : ( ) => remoteConnector . autoTunnelCommand } ) ;
114
+
115
+ remoteSession = new RemoteSession ( remoteConnectionInfo . remoteAuthority , remoteConnectionInfo . connectionInfo , context , hostService , sessionService , settingsSync , experiments , logger , telemetryService , notificationService ) ;
116
+ await remoteSession . initialize ( ) ;
117
+ } else if ( sessionService . isSignedIn ( ) ) {
118
+ const restartFlow = { flow : 'restart_workspace' , userId : sessionService . getUserId ( ) } ;
119
+ checkForStoppedWorkspaces ( context , hostService . gitpodHost , restartFlow , notificationService , logger ) ;
120
+ }
121
+ } ) ;
122
+
123
+ success = true ;
124
+ } catch ( e ) {
125
+ telemetryService ?. sendTelemetryException ( e ) ;
126
+ throw e ;
127
+ } finally {
128
+ telemetryService ?. sendTelemetryEvent ( 'vscode_desktop_activate' , {
129
+ remoteName : vscode . env . remoteName || '' ,
130
+ remoteUri : String ( ! ! ( vscode . workspace . workspaceFile || vscode . workspace . workspaceFolders ?. [ 0 ] . uri ) ) ,
131
+ workspaceId : remoteConnectionInfo ?. connectionInfo . workspaceId || '' ,
132
+ instanceId : remoteConnectionInfo ?. connectionInfo . instanceId || '' ,
133
+ gitpodHost : remoteConnectionInfo ?. connectionInfo . gitpodHost || '' ,
134
+ debugWorkspace : remoteConnectionInfo ? String ( ! ! remoteConnectionInfo . connectionInfo . debugWorkspace ) : '' ,
135
+ success : String ( success )
136
+ } ) ;
137
+ }
127
138
}
128
139
129
140
export async function deactivate ( ) {
0 commit comments