From a7b1c1d0d5c24662795321ff4dc31db129f77ac0 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Tue, 2 Jul 2019 18:54:58 +0000 Subject: [PATCH] Initial Live Share support --- src/services/liveShare.ts | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/services/liveShare.ts diff --git a/src/services/liveShare.ts b/src/services/liveShare.ts new file mode 100644 index 0000000..bcbaa78 --- /dev/null +++ b/src/services/liveShare.ts @@ -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); +} \ No newline at end of file