Skip to content

Commit

Permalink
Fix web extension connection issue (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored Aug 28, 2024
1 parent 0bd4032 commit a015928
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/open-collaboration-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "open-collaboration-tools",
"displayName": "Open Collaboration Tools",
"description": "Connect with others and live-share your code in real-time collaboration sessions",
"version": "0.2.0",
"version": "0.2.1",
"publisher": "typefox",
"categories": [
"Other"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { inject, injectable } from 'inversify';
import { ExtensionContext } from './inversify';
import { CollaborationConnectionProvider, OCT_USER_TOKEN } from './collaboration-connection-provider';
import { localizeInfo } from './utils/l10n';
import { isWeb } from './utils/system';

export const OCT_ROOM_DATA = 'oct.roomData';

Expand Down Expand Up @@ -103,7 +104,7 @@ export class CollaborationRoomService {
}
this.tokenSource.cancel();
this.tokenSource = new vscode.CancellationTokenSource();
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: vscode.l10n.t('Joining Session'), cancellable: true }, async (progress, cancelToken) => {
const success = await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: vscode.l10n.t('Joining Session'), cancellable: true }, async (progress, cancelToken) => {
if (roomId) {
const outerToken = this.tokenSource.token;
try {
Expand All @@ -129,12 +130,21 @@ export class CollaborationRoomService {
name: folder,
uri: CollaborationUri.create(workspace.name, folder)
}));
vscode.workspace.updateWorkspaceFolders(0, workspaceFolders.length, ...newFolders);
return vscode.workspace.updateWorkspaceFolders(0, workspaceFolders.length, ...newFolders);
} catch (error) {
this.showError(false, error, outerToken, cancelToken);
}
}
return false;
});
if (success && isWeb) {
// It seems like the web extension mode doesn't restart the extension host upon changing workspace folders
// However, force restarting the extension host by reloading the window removes the current workspace folders
// Therefore, we simply attempt to connect after a short delay after receiving the success signal
setTimeout(() => {
this.tryConnect();
}, 500);
}
}

private showError(create: boolean, error: unknown, outerToken: vscode.CancellationToken, innerToken: vscode.CancellationToken): void {
Expand Down
9 changes: 0 additions & 9 deletions packages/open-collaboration-vscode/src/extension-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import * as vscode from 'vscode';
import 'reflect-metadata';
import { CollaborationInstance } from './collaboration-instance';
import { CollaborationRoomService } from './collaboration-room-service';
import { closeSharedEditors, removeWorkspaceFolders } from './utils/workspace';
import { createContainer } from './inversify';
import { Commands } from './commands';
Expand All @@ -18,14 +17,6 @@ export async function activate(context: vscode.ExtensionContext) {
container.bind(Fetch).toConstantValue(fetch);
const commands = container.get(Commands);
commands.initialize();
const roomService = container.get(CollaborationRoomService);

roomService.tryConnect().then(value => {
if (!value) {
closeSharedEditors();
removeWorkspaceFolders();
}
});
}

export async function deactivate(): Promise<void> {
Expand Down

0 comments on commit a015928

Please sign in to comment.