Skip to content

Commit 384c515

Browse files
mustard-mhjeanp413
andauthored
Always update remotePlatform for gitpodHost's wildcard (#103)
* Always update remotePlatform for gitpodHost's wildcard * address feedback * 💄 --------- Co-authored-by: jeanp413 <[email protected]>
1 parent edbfdcf commit 384c515

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

src/extension.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ export async function activate(context: vscode.ExtensionContext) {
9292
const remoteConnector = new RemoteConnector(context, sessionService, hostService, experiments, logger, telemetryService, notificationService, remoteService);
9393
context.subscriptions.push(remoteConnector);
9494

95-
context.subscriptions.push(vscode.window.registerUriHandler({
96-
handleUri(uri: vscode.Uri) {
97-
// logger.trace('Handling Uri...', uri.toString());
98-
if (uri.path === GitpodServer.AUTH_COMPLETE_PATH) {
99-
authProvider.handleUri(uri);
100-
} else {
101-
remoteConnector.handleUri(uri);
102-
}
103-
}
104-
}));
105-
10695
remoteConnectionInfo = getGitpodRemoteWindowConnectionInfo(context);
10796
vscode.commands.executeCommand('setContext', 'gitpod.remoteConnection', !!remoteConnectionInfo);
10897

@@ -121,13 +110,21 @@ export async function activate(context: vscode.ExtensionContext) {
121110
// Backwards compatibility with older gitpod-remote extensions
122111
commandManager.register({ id: 'gitpod.api.autoTunnel', execute: () => { } });
123112

124-
if (!context.globalState.get<boolean>(FIRST_INSTALL_KEY, false)) {
125-
context.globalState.update(FIRST_INSTALL_KEY, true);
126-
telemetryService.sendTelemetryEvent('gitpod_desktop_installation', { gitpodHost: hostService.gitpodHost, kind: 'install' });
127-
}
113+
const firstLoadPromise = sessionService.didFirstLoad.then(() => remoteConnector.updateSSHRemotePlatform());
114+
115+
context.subscriptions.push(vscode.window.registerUriHandler({
116+
handleUri(uri: vscode.Uri) {
117+
// logger.trace('Handling Uri...', uri.toString());
118+
if (uri.path === GitpodServer.AUTH_COMPLETE_PATH) {
119+
authProvider.handleUri(uri);
120+
} else {
121+
firstLoadPromise.then(() => remoteConnector.handleUri(uri));
122+
}
123+
}
124+
}));
128125

129126
// Because auth provider implementation is in the same extension, we need to wait for it to activate first
130-
sessionService.didFirstLoad.then(async () => {
127+
firstLoadPromise.then(async () => {
131128
if (remoteConnectionInfo) {
132129
remoteSession = new RemoteSession(remoteConnectionInfo.connectionInfo, context, remoteService, hostService, sessionService, experiments, logger!, telemetryService!, notificationService);
133130
await remoteSession.initialize();
@@ -141,6 +138,11 @@ export async function activate(context: vscode.ExtensionContext) {
141138
}
142139
});
143140

141+
if (!context.globalState.get<boolean>(FIRST_INSTALL_KEY, false)) {
142+
context.globalState.update(FIRST_INSTALL_KEY, true);
143+
telemetryService.sendTelemetryEvent('gitpod_desktop_installation', { gitpodHost: hostService.gitpodHost, kind: 'install' });
144+
}
145+
144146
success = true;
145147
} finally {
146148
const rawActivateProperties = {

src/remoteConnector.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { INotificationService } from './services/notificationService';
2121
import { SSHKey } from '@gitpod/public-api/lib/gitpod/experimental/v1/user_pb';
2222
import { getAgentSock, SSHError, testSSHConnection as testSSHGatewayConnection } from './sshTestConnection';
2323
import { gatherIdentityFiles } from './ssh/identityFiles';
24-
import { isWindows } from './common/platform';
2524
import SSHDestination from './ssh/sshDestination';
2625
import { NoRunningInstanceError, NoSSHGatewayError, SSHConnectionParams, SSH_DEST_KEY, getLocalSSHDomain } from './remote';
2726
import { ISessionService } from './services/sessionService';
@@ -47,6 +46,10 @@ export class RemoteConnector extends Disposable {
4746
private readonly remoteService: IRemoteService,
4847
) {
4948
super();
49+
50+
this._register(this.hostService.onDidChangeHost(async () => {
51+
await this.updateSSHRemotePlatform()
52+
}))
5053
}
5154

5255
private async getWorkspaceSSHDestination({ workspaceId, gitpodHost, debugWorkspace }: SSHConnectionParams): Promise<{ destination: SSHDestination; password?: string }> {
@@ -361,14 +364,6 @@ export class RemoteConnector extends Disposable {
361364

362365
await this.context.globalState.update(`${SSH_DEST_KEY}${sshDestination!.toRemoteSSHString()}`, { ...params } as SSHConnectionParams);
363366

364-
// Force Linux as host platform (https://github.com/gitpod-io/gitpod/issues/16058)
365-
if (isWindows) {
366-
const existingSSHHostPlatforms = vscode.workspace.getConfiguration('remote.SSH').get<{ [host: string]: string }>('remotePlatform', {});
367-
if (!existingSSHHostPlatforms[sshDestination!.hostname]) {
368-
await vscode.workspace.getConfiguration('remote.SSH').update('remotePlatform', { ...existingSSHHostPlatforms, [sshDestination!.hostname]: 'linux' }, vscode.ConfigurationTarget.Global);
369-
}
370-
}
371-
372367
return sshDestination;
373368
}
374369
);
@@ -385,4 +380,18 @@ export class RemoteConnector extends Disposable {
385380
{ forceNewWindow }
386381
);
387382
}
383+
384+
// Force Linux as host platform (https://github.com/gitpod-io/gitpod/issues/16058)
385+
public async updateSSHRemotePlatform() {
386+
try {
387+
const existingSSHHostPlatforms = vscode.workspace.getConfiguration('remote.SSH').get<{ [host: string]: string }>('remotePlatform', {});
388+
const hostname = '*.' + (new URL(this.hostService.gitpodHost)).hostname;
389+
const targetPlatform = 'linux';
390+
if (!existingSSHHostPlatforms[hostname] || existingSSHHostPlatforms[hostname] !== targetPlatform) {
391+
await vscode.workspace.getConfiguration('remote.SSH').update('remotePlatform', { ...existingSSHHostPlatforms, [hostname]: targetPlatform }, vscode.ConfigurationTarget.Global);
392+
}
393+
} catch (e) {
394+
this.logService.error('Error updating remotePlatform configuration', e);
395+
}
396+
}
388397
}

0 commit comments

Comments
 (0)