Skip to content

Commit

Permalink
Disable contributions when in gp next remote window (#109)
Browse files Browse the repository at this point in the history
* Disable contributions when in gpnext remote window

* 🆙 bump version
  • Loading branch information
jeanp413 authored Aug 22, 2024
1 parent 116e4a6 commit 4b58838
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Gitpod",
"description": "Gitpod Support",
"publisher": "gitpod",
"version": "0.0.172",
"version": "0.0.173",
"license": "MIT",
"icon": "resources/gitpod.png",
"repository": {
Expand Down Expand Up @@ -270,24 +270,28 @@
],
"commandPalette": [
{
"command": "gitpod.workspaces.refresh",
"when": "false"
"command": "gitpod.signIn",
"when": "!gitpod.inGpNextRemoteWindow"
},
{
"command": "gitpod.exportLogs",
"when": "!gitpod.inGpNextRemoteWindow"
},
{
"command": "gitpod.workspaces.refresh",
"when": "gitpod.authenticated == true"
"when": "gitpod.authenticated == true && !gitpod.inGpNextRemoteWindow"
},
{
"command": "gitpod.workspaces.connectInNewWindow",
"when": "gitpod.authenticated == true"
"when": "gitpod.authenticated == true && !gitpod.inGpNextRemoteWindow"
},
{
"command": "gitpod.workspaces.connectInNewWindow_context",
"when": "false"
},
{
"command": "gitpod.workspaces.connectInCurrentWindow",
"when": "gitpod.authenticated == true"
"when": "gitpod.authenticated == true && !gitpod.inGpNextRemoteWindow"
},
{
"command": "gitpod.workspaces.connectInCurrentWindow_context",
Expand All @@ -307,7 +311,7 @@
},
{
"command": "gitpod.workspaces.stopWorkspace",
"when": "gitpod.authenticated == true && gitpod.inWorkspace != true"
"when": "gitpod.authenticated == true && gitpod.inWorkspace != true && !gitpod.inGpNextRemoteWindow"
},
{
"command": "gitpod.workspaces.stopWorkspace_context",
Expand Down Expand Up @@ -335,7 +339,7 @@
},
{
"command": "gitpod.workspaces.deleteWorkspace",
"when": "gitpod.authenticated == true && gitpod.inWorkspace != true"
"when": "gitpod.authenticated == true && gitpod.inWorkspace != true && !gitpod.inGpNextRemoteWindow"
},
{
"command": "gitpod.workspaces.deleteWorkspace_context",
Expand All @@ -362,13 +366,13 @@
"id": "gitpod-login",
"name": "Login",
"icon": "$(squirrel)",
"when": "gitpod.authenticated != true"
"when": "gitpod.authenticated != true && !gitpod.inGpNextRemoteWindow"
},
{
"id": "gitpod-workspaces",
"name": "Workspaces",
"icon": "$(squirrel)",
"when": "gitpod.authenticated == true"
"when": "gitpod.authenticated == true && !gitpod.inGpNextRemoteWindow"
},
{
"id": "gitpod-workspace",
Expand All @@ -381,7 +385,7 @@
"viewsWelcome": [
{
"view": "gitpod-login",
"when": "gitpod.authenticated != true",
"when": "gitpod.authenticated != true && !gitpod.inGpNextRemoteWindow",
"contents": "You have not yet signed in with Gitpod\n[Sign in](command:gitpod.signIn)"
}
]
Expand Down
7 changes: 6 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NotificationService } from './services/notificationService';
import { RemoteConnector } from './remoteConnector';
import { TelemetryService } from './services/telemetryService';
import { RemoteSession } from './remoteSession';
import { SSHConnectionParams, getGitpodRemoteWindowConnectionInfo } from './remote';
import { SSHConnectionParams, getGitpodRemoteWindowConnectionInfo, isGitpodNextRemoteWindow } from './remote';
import { HostService } from './services/hostService';
import { SessionService } from './services/sessionService';
import { CommandManager } from './commandManager';
Expand Down Expand Up @@ -45,6 +45,11 @@ export async function activate(context: vscode.ExtensionContext) {
const extensionId = context.extension.id;
const packageJSON = context.extension.packageJSON;

if (isGitpodNextRemoteWindow()) {
vscode.commands.executeCommand('setContext', 'gitpod.inGpNextRemoteWindow', true);
return;
}

let remoteConnectionInfo: { connectionInfo: SSHConnectionParams; remoteUri: vscode.Uri; sshDestStr: string } | undefined;
let success = false;
try {
Expand Down
30 changes: 30 additions & 0 deletions src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import SSHDestination from './ssh/sshDestination';

export interface SSHConnectionParams {
workspaceId: string;
Expand Down Expand Up @@ -69,6 +70,35 @@ export function getGitpodRemoteWindowConnectionInfo(context: vscode.ExtensionCon
return undefined;
}

export function isGitpodNextRemoteWindow() {
const remoteUri = vscode.workspace.workspaceFile?.scheme !== 'untitled'
? vscode.workspace.workspaceFile || vscode.workspace.workspaceFolders?.[0].uri
: vscode.workspace.workspaceFolders?.[0].uri;
if (!remoteUri) {
return false;
}
if (vscode.env.remoteName === 'dev-container') {
const authorities = remoteUri.authority.split('@');
const sshAuthority = authorities.find((str) => str.includes('ssh-remote'));
const containerAuthority = authorities.find((str) => str.includes('dev-container'));
if (!sshAuthority || !containerAuthority) {
return false;
}
const [, sshEncoded] = sshAuthority.split('+');
if (!sshEncoded) {
return false;
}
const [, containerEncoded] = containerAuthority.split('+');
if (!containerEncoded) {
return false;
}
const sshDest = SSHDestination.fromRemoteSSHString(sshEncoded);

return /gitpod\.(local|remote)$/.test(sshDest.hostname);
}
return false;
}

export function getLocalSSHDomain(gitpodHost: string): string {
const scope = vscode.env.appName.includes('Insiders') ? 'vsi' : 'vss';
return `${scope}.` + (new URL(gitpodHost)).hostname;
Expand Down

0 comments on commit 4b58838

Please sign in to comment.