From 96f090607e0596b7c68100f2969e780b070dedca Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Tue, 2 Jul 2019 13:07:55 -0700 Subject: [PATCH] Add documentation --- src/services/liveShare.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/services/liveShare.ts b/src/services/liveShare.ts index 6fee8d9..3768a9c 100644 --- a/src/services/liveShare.ts +++ b/src/services/liveShare.ts @@ -7,18 +7,27 @@ export async function initialize( config: Config, activateProfileHandler: (profile: string) => void ) { + // Check to see if the end-user has the Live Share + // extension installed, and if not, exit early. const liveShare = await vsls.getApi(); if (!liveShare) { return; } + // Begin listening for the beginning and end of Live + // Share sessions, in case we need to switch profiles. liveShare.onDidChangeSession(e => { - if (e.session.id) { - const liveShareProfile = config.getLiveShareProfile(); - if (!liveShareProfile) { - return; - } + // If the end-user never set a Live Share profile, then + // there's nothing we need to do. Note that we're calling + // this here, instead of as part of the activation flow, + // so that the end-user can set their profile any time + // and have it take effect immediately. + const liveShareProfile = config.getLiveShareProfile(); + if (!liveShareProfile) { + return; + } + if (e.session.id) { activateProfileHandler(liveShareProfile); } else { const previousProfile = config.getPreviousProfile();