Skip to content

Commit

Permalink
Fix commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 committed Sep 8, 2023
1 parent b77dc90 commit 51cbec1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@
},
{
"command": "gitpod.workspaces.openContext",
"when": "false"
"when": "gitpod.authenticated == true && gitpod.inWorkspace == true"
},
{
"command": "gitpod.workspaces.deleteWorkspace",
"when": "gitpod.authenticated == true"
"when": "gitpod.authenticated == true && gitpod.inWorkspace != true"
},
{
"command": "gitpod.workspaces.deleteWorkspace_context",
Expand Down
38 changes: 19 additions & 19 deletions src/commands/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import { Command } from '../commandManager';
import { ISessionService } from '../services/sessionService';
import { WorkspaceData, rawWorkspaceToWorkspaceData } from '../publicApi';
import { SSHConnectionParams, SSH_DEST_KEY, getLocalSSHDomain } from '../remote';
import { SSHConnectionParams, SSH_DEST_KEY, getGitpodRemoteWindowConnectionInfo, getLocalSSHDomain } from '../remote';
import SSHDestination from '../ssh/sshDestination';
import { IHostService } from '../services/hostService';
import { WorkspaceState } from '../workspaceState';
Expand Down Expand Up @@ -493,25 +493,26 @@ export class StopCurrentWorkspaceCommand implements Command {
readonly id: string = 'gitpod.workspaces.stopCurrentWorkspace';

constructor(
private readonly workspaceId: string | undefined,
private readonly context: vscode.ExtensionContext,
private readonly sessionService: ISessionService,
private readonly hostService: IHostService,
private readonly telemetryService: ITelemetryService,
) { }

async execute() {
if (!this.workspaceId) {
const workspaceId = getGitpodRemoteWindowConnectionInfo(this.context)?.connectionInfo.workspaceId;
if (!workspaceId) {
return;
}

this.telemetryService.sendTelemetryEvent('vscode_desktop_view_command', {
name: getCommandName(this.id),
gitpodHost: this.hostService.gitpodHost,
workspaceId: this.workspaceId,
workspaceId: workspaceId,
location: 'commandPalette'
});

await this.sessionService.getAPI().stopWorkspace(this.workspaceId);
await this.sessionService.getAPI().stopWorkspace(workspaceId);
await vscode.commands.executeCommand('workbench.action.remote.close');
}
}
Expand All @@ -520,36 +521,33 @@ export class StopCurrentWorkspaceCommandInline extends StopCurrentWorkspaceComma
override readonly id = 'gitpod.workspaces.stopCurrentWorkspace_inline';

constructor(
workspaceId: string | undefined,
context: vscode.ExtensionContext,
sessionService: ISessionService,
hostService: IHostService,
telemetryService: ITelemetryService,
) {
super(workspaceId, sessionService, hostService, telemetryService);
super(context, sessionService, hostService, telemetryService);
}
}

export class OpenInBrowserCommand implements Command {
readonly id = 'gitpod.workspaces.openInBrowser';

constructor(
private readonly context: vscode.ExtensionContext,
private readonly sessionService: ISessionService,
private readonly hostService: IHostService,
private readonly telemetryService: ITelemetryService,
) { }

async execute(treeItem?: { id: string }) {
let wsData: WorkspaceData | undefined;
if (!treeItem?.id) {
wsData = (await showWorkspacesPicker(this.sessionService, 'Select a workspace to connect...'));
} else {
wsData = rawWorkspaceToWorkspaceData(await this.sessionService.getAPI().getWorkspace(treeItem.id));
}

if (!wsData) {
let workspaceId = treeItem?.id || getGitpodRemoteWindowConnectionInfo(this.context)?.connectionInfo.workspaceId;
if (!workspaceId) {
return;
}

const wsData = rawWorkspaceToWorkspaceData(await this.sessionService.getAPI().getWorkspace(workspaceId));

this.telemetryService.sendTelemetryEvent('vscode_desktop_view_command', {
name: getCommandName(this.id),
gitpodHost: this.hostService.gitpodHost,
Expand Down Expand Up @@ -616,18 +614,20 @@ export class OpenWorkspaceContextCommand implements Command {
readonly id = 'gitpod.workspaces.openContext';

constructor(
private readonly context: vscode.ExtensionContext,
private readonly sessionService: ISessionService,
private readonly hostService: IHostService,
private readonly telemetryService: ITelemetryService,
) { }

async execute(treeItem: { id: string }) {
if (!treeItem?.id) {
async execute(treeItem?: { id: string }) {
let workspaceId = treeItem?.id || getGitpodRemoteWindowConnectionInfo(this.context)?.connectionInfo.workspaceId;
if (!workspaceId) {
return;
}

const rawWsData = await this.sessionService.getAPI().getWorkspace(treeItem.id);
const wsData = rawWorkspaceToWorkspaceData(await this.sessionService.getAPI().getWorkspace(treeItem.id));
const rawWsData = await this.sessionService.getAPI().getWorkspace(workspaceId);
const wsData = rawWorkspaceToWorkspaceData(await this.sessionService.getAPI().getWorkspace(workspaceId));

// Report if we couldn't parse contextUrl
if (!wsData.contextUrl) {
Expand Down
8 changes: 4 additions & 4 deletions src/workspacesExplorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ export class WorkspacesExplorerView extends Disposable implements vscode.TreeDat
commandManager.register(new StopWorkspaceCommand(sessionService, hostService, telemetryService));
commandManager.register(new StopWorkspaceCommandContext(sessionService, hostService, telemetryService));
commandManager.register(new StopWorkspaceCommandInline(sessionService, hostService, telemetryService));
commandManager.register(new StopCurrentWorkspaceCommand(this.connectedWorkspaceId, sessionService, hostService, telemetryService));
commandManager.register(new StopCurrentWorkspaceCommandInline(this.connectedWorkspaceId, sessionService, hostService, telemetryService));
commandManager.register(new OpenInBrowserCommand(sessionService, hostService, telemetryService));
commandManager.register(new StopCurrentWorkspaceCommand(context, sessionService, hostService, telemetryService));
commandManager.register(new StopCurrentWorkspaceCommandInline(context, sessionService, hostService, telemetryService));
commandManager.register(new OpenInBrowserCommand(context, sessionService, hostService, telemetryService));
commandManager.register(new DeleteWorkspaceCommand(sessionService, hostService, telemetryService));
commandManager.register(new DeleteWorkspaceCommandContext(sessionService, hostService, telemetryService));
commandManager.register(new OpenWorkspaceContextCommand(sessionService, hostService, telemetryService));
commandManager.register(new OpenWorkspaceContextCommand(context, sessionService, hostService, telemetryService));
commandManager.register(new DisconnectWorkspaceCommand());

this._register(this.hostService.onDidChangeHost(() => this.refresh()));
Expand Down

0 comments on commit 51cbec1

Please sign in to comment.