Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 committed Jul 12, 2023
1 parent 43fe16a commit ea354fe
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
27 changes: 27 additions & 0 deletions src/common/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,30 @@ export async function retryWithStop<T>(task: (stop: () => void) => Promise<T>, d
}
throw lastError;
}

export class Barrier {

private _isOpen: boolean;
private _promise: Promise<boolean>;
private _completePromise!: (v: boolean) => void;

constructor() {
this._isOpen = false;
this._promise = new Promise<boolean>((c, _) => {
this._completePromise = c;
});
}

isOpen(): boolean {
return this._isOpen;
}

open(): void {
this._isOpen = true;
this._completePromise(true);
}

wait(): Promise<boolean> {
return this._promise;
}
}
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ export async function activate(context: vscode.ExtensionContext) {
remoteSession = new RemoteSession(remoteConnectionInfo.connectionInfo, context, remoteService, hostService, sessionService, settingsSync, experiments, logger!, telemetryService!, notificationService);
await remoteSession.initialize();
} else if (sessionService.isSignedIn()) {
remoteService.checkForStoppedWorkspaces(wsInfo => {
remoteService.checkForStoppedWorkspaces(async wsInfo => {
if (!workspacesExplorerView.isVisible()) {
workspacesExplorerView.reveal(wsInfo.workspaceId);
await vscode.commands.executeCommand('gitpod-workspaces.focus');
await workspacesExplorerView.reveal(wsInfo.workspaceId, { select: true });
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/services/remoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface IRemoteService {
setupSSHProxy: () => Promise<boolean>;
extensionServerReady: () => Promise<boolean>;
saveRestartInfo: () => Promise<void>;
checkForStoppedWorkspaces: (cb: (info: WorkspaceRestartInfo) => void) => void;
checkForStoppedWorkspaces: (cb: (info: WorkspaceRestartInfo) => Promise<void>) => Promise<void>;
}

type FailedToInitializeCode = 'Unknown' | 'LockFailed' | string;
Expand Down Expand Up @@ -189,18 +189,18 @@ export class RemoteService extends Disposable implements IRemoteService {
await this.context.globalState.update(`${WORKSPACE_STOPPED_PREFIX}${connInfo.sshDestStr}`, { workspaceId: connInfo.connectionInfo.workspaceId, gitpodHost: connInfo.connectionInfo.gitpodHost, remoteUri: connInfo.remoteUri.toString() } as WorkspaceRestartInfo);
}

checkForStoppedWorkspaces(cb: (info: WorkspaceRestartInfo) => void) {
async checkForStoppedWorkspaces(cb: (info: WorkspaceRestartInfo) => Promise<void>) {
const keys = this.context.globalState.keys();
const stopped_ws_keys = keys.filter(k => k.startsWith(WORKSPACE_STOPPED_PREFIX));
for (const k of stopped_ws_keys) {
const ws = this.context.globalState.get<WorkspaceRestartInfo>(k)!;
if (new URL(this.hostService.gitpodHost).host === new URL(ws.gitpodHost).host) {
try {
cb(ws);
await cb(ws);
} catch {
}
}
this.context.globalState.update(k, undefined);
await this.context.globalState.update(k, undefined);
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/workspacesExplorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CommandManager } from './commandManager';
import { rawWorkspaceToWorkspaceData } from './publicApi';
import { IHostService } from './services/hostService';
import { getGitpodRemoteWindowConnectionInfo } from './remote';
import { Barrier } from './common/async';

class RepoOwnerTreeItem {
constructor(
Expand Down Expand Up @@ -75,6 +76,8 @@ export class WorkspacesExplorerView extends Disposable implements vscode.TreeDat

private treeView: vscode.TreeView<DataTreeItem>;

private workspacesBarrier = new Barrier();

constructor(
readonly context: vscode.ExtensionContext,
readonly commandManager: CommandManager,
Expand Down Expand Up @@ -132,6 +135,8 @@ export class WorkspacesExplorerView extends Disposable implements vscode.TreeDat
}
}

this.workspacesBarrier.open();

return this.workspaces;
}
if (element instanceof RepoOwnerTreeItem) {
Expand All @@ -141,18 +146,19 @@ export class WorkspacesExplorerView extends Disposable implements vscode.TreeDat
}

getParent(element: DataTreeItem): vscode.ProviderResult<DataTreeItem> {
if (element instanceof RepoOwnerTreeItem) {
if (element instanceof WorkspaceTreeItem) {
return;
}

return element.getParent();
return;
}

private refresh() {
this._onDidChangeTreeData.fire();
}

async reveal(workspaceId: string, options?: { select?: boolean; focus?: boolean; }) {
await this.workspacesBarrier.wait();
const element = this.workspaces.find(w => w.id === workspaceId);
if (element) {
return this.treeView.reveal(element, options);
Expand Down

0 comments on commit ea354fe

Please sign in to comment.