This repository has been archived by the owner on Jul 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba4288d
commit a7b1c1d
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |