Skip to content

Commit

Permalink
Always update remotePlatform for gitpodHost's wildcard (#103)
Browse files Browse the repository at this point in the history
* Always update remotePlatform for gitpodHost's wildcard

* address feedback

* 💄

---------

Co-authored-by: jeanp413 <jeanp413@hotmail.com>
  • Loading branch information
mustard-mh and jeanp413 authored Jun 12, 2024
1 parent edbfdcf commit 384c515
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
34 changes: 18 additions & 16 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,6 @@ export async function activate(context: vscode.ExtensionContext) {
const remoteConnector = new RemoteConnector(context, sessionService, hostService, experiments, logger, telemetryService, notificationService, remoteService);
context.subscriptions.push(remoteConnector);

context.subscriptions.push(vscode.window.registerUriHandler({
handleUri(uri: vscode.Uri) {
// logger.trace('Handling Uri...', uri.toString());
if (uri.path === GitpodServer.AUTH_COMPLETE_PATH) {
authProvider.handleUri(uri);
} else {
remoteConnector.handleUri(uri);
}
}
}));

remoteConnectionInfo = getGitpodRemoteWindowConnectionInfo(context);
vscode.commands.executeCommand('setContext', 'gitpod.remoteConnection', !!remoteConnectionInfo);

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

if (!context.globalState.get<boolean>(FIRST_INSTALL_KEY, false)) {
context.globalState.update(FIRST_INSTALL_KEY, true);
telemetryService.sendTelemetryEvent('gitpod_desktop_installation', { gitpodHost: hostService.gitpodHost, kind: 'install' });
}
const firstLoadPromise = sessionService.didFirstLoad.then(() => remoteConnector.updateSSHRemotePlatform());

context.subscriptions.push(vscode.window.registerUriHandler({
handleUri(uri: vscode.Uri) {
// logger.trace('Handling Uri...', uri.toString());
if (uri.path === GitpodServer.AUTH_COMPLETE_PATH) {
authProvider.handleUri(uri);
} else {
firstLoadPromise.then(() => remoteConnector.handleUri(uri));
}
}
}));

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

if (!context.globalState.get<boolean>(FIRST_INSTALL_KEY, false)) {
context.globalState.update(FIRST_INSTALL_KEY, true);
telemetryService.sendTelemetryEvent('gitpod_desktop_installation', { gitpodHost: hostService.gitpodHost, kind: 'install' });
}

success = true;
} finally {
const rawActivateProperties = {
Expand Down
27 changes: 18 additions & 9 deletions src/remoteConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { INotificationService } from './services/notificationService';
import { SSHKey } from '@gitpod/public-api/lib/gitpod/experimental/v1/user_pb';
import { getAgentSock, SSHError, testSSHConnection as testSSHGatewayConnection } from './sshTestConnection';
import { gatherIdentityFiles } from './ssh/identityFiles';
import { isWindows } from './common/platform';
import SSHDestination from './ssh/sshDestination';
import { NoRunningInstanceError, NoSSHGatewayError, SSHConnectionParams, SSH_DEST_KEY, getLocalSSHDomain } from './remote';
import { ISessionService } from './services/sessionService';
Expand All @@ -47,6 +46,10 @@ export class RemoteConnector extends Disposable {
private readonly remoteService: IRemoteService,
) {
super();

this._register(this.hostService.onDidChangeHost(async () => {
await this.updateSSHRemotePlatform()
}))
}

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

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

// Force Linux as host platform (https://github.com/gitpod-io/gitpod/issues/16058)
if (isWindows) {
const existingSSHHostPlatforms = vscode.workspace.getConfiguration('remote.SSH').get<{ [host: string]: string }>('remotePlatform', {});
if (!existingSSHHostPlatforms[sshDestination!.hostname]) {
await vscode.workspace.getConfiguration('remote.SSH').update('remotePlatform', { ...existingSSHHostPlatforms, [sshDestination!.hostname]: 'linux' }, vscode.ConfigurationTarget.Global);
}
}

return sshDestination;
}
);
Expand All @@ -385,4 +380,18 @@ export class RemoteConnector extends Disposable {
{ forceNewWindow }
);
}

// Force Linux as host platform (https://github.com/gitpod-io/gitpod/issues/16058)
public async updateSSHRemotePlatform() {
try {
const existingSSHHostPlatforms = vscode.workspace.getConfiguration('remote.SSH').get<{ [host: string]: string }>('remotePlatform', {});
const hostname = '*.' + (new URL(this.hostService.gitpodHost)).hostname;
const targetPlatform = 'linux';
if (!existingSSHHostPlatforms[hostname] || existingSSHHostPlatforms[hostname] !== targetPlatform) {
await vscode.workspace.getConfiguration('remote.SSH').update('remotePlatform', { ...existingSSHHostPlatforms, [hostname]: targetPlatform }, vscode.ConfigurationTarget.Global);
}
} catch (e) {
this.logService.error('Error updating remotePlatform configuration', e);
}
}
}

0 comments on commit 384c515

Please sign in to comment.