Skip to content

Commit 107c3b0

Browse files
authored
Readd onResolveRemoteAuthority:ssh-remote and fix for configuration default values (#45)
1 parent a50635f commit 107c3b0

File tree

11 files changed

+122
-93
lines changed

11 files changed

+122
-93
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
}
3333
},
3434
"activationEvents": [
35+
"onResolveRemoteAuthority:ssh-remote",
3536
"onCommand:gitpod.syncProvider.add",
3637
"onCommand:gitpod.syncProvider.remove",
3738
"onCommand:gitpod.exportLogs",

scripts/prepare-release-build.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,4 @@ const fs = require("fs");
44

55
const releasePackageJson = JSON.parse(fs.readFileSync('./package.json').toString());
66

7-
const releaseDefaultConfig = new Map([
8-
["gitpod.remote.useLocalApp", true],
9-
]);
10-
11-
const gitpodConfig = releasePackageJson.contributes.configuration.find(e => e.title.toLowerCase() === 'gitpod');
12-
for (const [setting, value] of releaseDefaultConfig) {
13-
gitpodConfig.properties[setting].default = value;
14-
}
15-
167
fs.writeFileSync('./package.release.json', JSON.stringify(releasePackageJson, undefined, '\t') + '\n');

src/authentication/authentication.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Disposable } from '../common/dispose';
1212
import { ITelemetryService, UserFlowTelemetry } from '../services/telemetryService';
1313
import { INotificationService } from '../services/notificationService';
1414
import { ILogService } from '../services/logService';
15+
import { Configuration } from '../configuration';
1516

1617
interface SessionData {
1718
id: string;
@@ -59,7 +60,7 @@ export default class GitpodAuthenticationProvider extends Disposable implements
5960
}
6061

6162
private reconcile(): void {
62-
const gitpodHost = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
63+
const gitpodHost = Configuration.getGitpodHost();
6364
const gitpodHostUrl = new URL(gitpodHost);
6465
this._serviceUrl = gitpodHostUrl.toString().replace(/\/$/, '');
6566
Object.assign(this.flow, { gitpodHost: this._serviceUrl });

src/configuration.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Gitpod. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
8+
// Use these functions instead of `vscode.workspace.getConfiguration` API
9+
// When activating the extension early with `onResolveRemoteAuthority:ssh-remote`, default values
10+
// are not available yet and will return `undefined` so we hardcode the defaults here
11+
12+
function getGitpodHost() {
13+
return vscode.workspace.getConfiguration('gitpod').get<string>('host', 'https://gitpod.io/');
14+
}
15+
16+
function getShowReleaseNotes() {
17+
return vscode.workspace.getConfiguration('gitpod').get<boolean>('showReleaseNotes', true);
18+
}
19+
20+
function getUseLocalApp() {
21+
return vscode.workspace.getConfiguration('gitpod').get<boolean>('remote.useLocalApp', false);
22+
}
23+
24+
export const Configuration = {
25+
getGitpodHost,
26+
getShowReleaseNotes,
27+
getUseLocalApp
28+
};

src/extension.ts

Lines changed: 79 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { RemoteConnector } from './remoteConnector';
1515
import { SettingsSync } from './settingsSync';
1616
import { TelemetryService } from './services/telemetryService';
1717
import { RemoteSession } from './remoteSession';
18-
import { checkForStoppedWorkspaces, getGitpodRemoteWindowConnectionInfo } from './remote';
18+
import { SSHConnectionParams, checkForStoppedWorkspaces, getGitpodRemoteWindowConnectionInfo } from './remote';
1919
import { HostService } from './services/hostService';
2020
import { SessionService } from './services/sessionService';
2121
import { CommandManager } from './commandManager';
@@ -35,95 +35,106 @@ if (!global.fetch) {
3535
const FIRST_INSTALL_KEY = 'gitpod-desktop.firstInstall';
3636

3737
let telemetryService: TelemetryService;
38-
let remoteSession: RemoteSession;
38+
let remoteSession: RemoteSession | undefined;
3939

4040
export async function activate(context: vscode.ExtensionContext) {
4141
const extensionId = context.extension.id;
4242
const packageJSON = context.extension.packageJSON;
4343

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]);
4649

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);
4952

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);
5558

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})`);
5760

58-
telemetryService = new TelemetryService(extensionId, packageJSON.version, packageJSON.segmentKey);
61+
telemetryService = new TelemetryService(extensionId, packageJSON.version, packageJSON.segmentKey);
5962

60-
const notificationService = new NotificationService(telemetryService);
63+
const notificationService = new NotificationService(telemetryService);
6164

62-
const commandManager = new CommandManager();
63-
context.subscriptions.push(commandManager);
65+
const commandManager = new CommandManager();
66+
context.subscriptions.push(commandManager);
6467

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);
6871

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);
7174

72-
const sessionService = new SessionService(hostService, logger);
73-
context.subscriptions.push(sessionService);
75+
const sessionService = new SessionService(hostService, logger);
76+
context.subscriptions.push(sessionService);
7477

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);
7780

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);
8083

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);
8386

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+
}
9195
}
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+
}));
10797

108-
context.subscriptions.push(new ReleaseNotes(context, commandManager, logger));
98+
context.subscriptions.push(new ReleaseNotes(context, commandManager, logger));
10999

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));
114103

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+
}
127138
}
128139

129140
export async function deactivate() {

src/releaseNotes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { CacheHelper } from './common/cache';
99
import { Disposable, disposeAll } from './common/dispose';
1010
import { ILogService } from './services/logService';
1111
import { CommandManager } from './commandManager';
12+
import { Configuration } from './configuration';
1213

1314
export class ReleaseNotes extends Disposable {
1415
public static readonly viewType = 'gitpodReleaseNotes';
@@ -162,7 +163,7 @@ export class ReleaseNotes extends Disposable {
162163
}
163164

164165
private async showIfNewRelease(lastReadId: string | undefined) {
165-
const showReleaseNotes = vscode.workspace.getConfiguration('gitpod').get<boolean>('showReleaseNotes');
166+
const showReleaseNotes = Configuration.getShowReleaseNotes();
166167
if (showReleaseNotes) {
167168
const releaseId = await this.getLastPublish();
168169
if (releaseId && releaseId !== lastReadId) {

src/remoteConnector.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { NoRunningInstanceError, NoSSHGatewayError, SSHConnectionParams, SSH_DES
3737
import { ISessionService } from './services/sessionService';
3838
import { ILogService } from './services/logService';
3939
import { IHostService } from './services/hostService';
40+
import { Configuration } from './configuration';
4041

4142
interface LocalAppConfig {
4243
gitpodHost: string;
@@ -650,9 +651,7 @@ export class RemoteConnector extends Disposable {
650651
this.usePublicApi = await this.experiments.getRaw<boolean>('gitpod_experimental_publicApi', { gitpodHost: params.gitpodHost }) ?? false;
651652
this.logService.info(`Going to use ${this.usePublicApi ? 'public' : 'server'} API`);
652653

653-
const forceUseLocalApp = getServiceURL(params.gitpodHost) === 'https://gitpod.io'
654-
? (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', { gitpodHost: params.gitpodHost }))!
655-
: (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', { gitpodHost: params.gitpodHost }, 'gitpod_remote_useLocalApp_sh'))!;
654+
const forceUseLocalApp = Configuration.getUseLocalApp();
656655
const userOverride = String(isUserOverrideSetting('gitpod.remote.useLocalApp'));
657656
let sshDestination: SSHDestination | undefined;
658657
if (!forceUseLocalApp) {
@@ -766,9 +765,7 @@ export class RemoteConnector extends Disposable {
766765

767766
public async autoTunnelCommand(gitpodHost: string, instanceId: string, enabled: boolean) {
768767
if (this.sessionService.isSignedIn()) {
769-
const forceUseLocalApp = getServiceURL(gitpodHost) === 'https://gitpod.io'
770-
? (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', { gitpodHost }))!
771-
: (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', { gitpodHost }, 'gitpod_remote_useLocalApp_sh'))!;
768+
const forceUseLocalApp = Configuration.getUseLocalApp();
772769
if (!forceUseLocalApp) {
773770
const authority = vscode.Uri.parse(gitpodHost).authority;
774771
const configKey = `config/${authority}`;

src/remoteSession.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ export class RemoteSession extends Disposable {
5353
public async initialize() {
5454
this.logService.info('On remote window, RemoteSession initializing');
5555

56-
// Because auth provider implementation is in the same extension, we need to wait for it to activate first
57-
await this.sessionService.didFirstLoad;
58-
5956
if (!this.sessionService.isSignedIn()) {
6057
this.showSignInDialog();
6158
return;

src/services/hostService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { INotificationService } from './notificationService';
1010
import { getGitpodRemoteWindowConnectionInfo } from '../remote';
1111
import { UserFlowTelemetry } from './telemetryService';
1212
import { ILogService } from './logService';
13+
import { Configuration } from '../configuration';
1314

1415
export interface IHostService {
1516
gitpodHost: string;
@@ -39,11 +40,11 @@ export class HostService extends Disposable implements IHostService {
3940
) {
4041
super();
4142

42-
this._gitpodHost = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
43+
this._gitpodHost = Configuration.getGitpodHost();
4344

4445
this._register(vscode.workspace.onDidChangeConfiguration(e => {
4546
if (e.affectsConfiguration('gitpod.host')) {
46-
const newGitpodHost = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
47+
const newGitpodHost = Configuration.getGitpodHost();
4748
if (new URL(this._gitpodHost).host !== new URL(newGitpodHost).host) {
4849
this._gitpodHost = newGitpodHost;
4950
this._version = undefined;

src/services/telemetryService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { AppenderData, BaseTelemetryAppender, BaseTelemetryClient, BaseTelemetry
77
import { Analytics } from '@segment/analytics-node';
88
import * as os from 'os';
99
import * as vscode from 'vscode';
10+
import { Configuration } from '../configuration';
1011

1112
const analyticsClientFactory = async (key: string): Promise<BaseTelemetryClient> => {
1213
let segmentAnalyticsClient = new Analytics({ writeKey: key });
@@ -25,7 +26,7 @@ const analyticsClientFactory = async (key: string): Promise<BaseTelemetryClient>
2526
}
2627
},
2728
logException: (exception: Error, data?: AppenderData) => {
28-
const gitpodHost = vscode.workspace.getConfiguration('gitpod').get<string>('host')!;
29+
const gitpodHost = Configuration.getGitpodHost();
2930
const serviceUrl = new URL(gitpodHost);
3031
const errorMetricsEndpoint = `https://ide.${serviceUrl.hostname}/metrics-api/reportError`;
3132

0 commit comments

Comments
 (0)