Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
Initial Live Share support
Browse files Browse the repository at this point in the history
  • Loading branch information
lostintangent committed Jul 2, 2019
1 parent ba4288d commit a7b1c1d
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/services/liveShare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as vscode from "vscode";
import * as vsls from "vsls";
import Config from "./config";

export async function initialize(
context: vscode.ExtensionContext,
config: Config,
activateProfileHandler: (profile: string) => void
) {
const liveShare = await vsls.getApi();
if (!liveShare) {
return;
}

const liveShareProfile = config.getLiveShareProfile();
if (!liveShareProfile) {
return;
}

// Check to see whether there was a lingering profile set
// (e.g. because the user closed VS Code while in a Live Share
// session), and if so, restore the right profile.
restorePreviousProfile(config, activateProfileHandler);

liveShare.onDidChangeSession(e => {
if (e.session.id) {
activateProfileHandler(liveShareProfile);
} else {
restorePreviousProfile(config, activateProfileHandler);
}
})
}

function restorePreviousProfile(
config: Config,
activateProfileHandler: (profile: string) => void
) {
const previousProfile = config.getPreviousProfile();
if (!previousProfile) {
return;
}

config.setPreviousProfile(undefined);
activateProfileHandler(previousProfile);
}

0 comments on commit a7b1c1d

Please # to comment.