Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async initialize() {
try {
// If we have a vsls: workspace open, we might be a guest, so wait until live share transitions into a mode
if (
workspace.workspaceFolders !== undefined &&
workspace.workspaceFolders.some(f => f.uri.scheme === DocumentSchemes.Vsls)
) {
this.setReadonly(true);
this._waitForReady = new Promise(resolve => (this._onReady = resolve));
}
this._api = getApi();
const api = await this._api;
if (api == null) {
setCommandContext(CommandContext.Vsls, false);
// Tear it down if we can't talk to live share
if (this._onReady !== undefined) {
this._onReady();
this._waitForReady = undefined;
}
return;
}
setCommandContext(CommandContext.Vsls, true);
this._disposable = Disposable.from(
api.onDidChangeSession(e => this.onLiveShareSessionChanged(api, e), this)
export async function activate(context: vscode.ExtensionContext) {
const vslsApi = (await vsls.getApi())!;
const treeDataProvider = registerTreeDataProvider(vslsApi);
let webviewPanel: vscode.WebviewPanel | null;
context.subscriptions.push(
vscode.commands.registerCommand("liveshare.openWhiteboard", async () => {
if (webviewPanel) {
return webviewPanel.reveal();
} else {
webviewPanel = createWebView(context);
// If the end-user closes the whiteboard, then we
// need to ensure we re-created it on the next click.
webviewPanel.onDidDispose(() => (webviewPanel = null));
}
let { default: initializeService } =
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 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;
}
export async function addLiveShareIntegration(context: vscode.ExtensionContext) {
State.extensionContext = context;
registerLiveShareIntegrationCommands();
const vslsApi = await vsls.getApi();
await vscode.commands.executeCommand('setContext', 'peacock:liveshare', !!vslsApi);
if (!vslsApi) {
return;
}
vslsApi!.onDidChangeSession(async e => {
// If there isn't a session ID, then that
// means the session has been ended.
if (!e.session.id) {
return await revertLiveShareWorkspaceColors();
}
// we need to update `peacockColorCustomizations` only when it is `undefined`
// to prevent the case of multiple color changes during live share session
peacockColorCustomizations = await getColorCustomizationConfigFromWorkspace();
export async function refreshLiveShareSessionColor(isHostRole: boolean): Promise {
const vslsApi = await vsls.getApi();
// not in Live Share session, no need to update
if (!vslsApi || !vslsApi.session.id) {
const verb = isHostRole ? 'host and share' : 'join';
notify(`The selected color will be applied every time you ${verb} a Live Share session.`, true);
return false;
}
const isHost = vslsApi.session.role === vsls.Role.Host;
await setLiveShareSessionWorkspaceColors(isHost);
return true;
}
async register() {
const liveshare: any = await vsls.getApi();
if (!!liveshare) {
this._disposables.push(
liveshare.registerTreeDataProvider(LIVE_SHARE_VIEW_ID, this)
);
this._disposables.push(
liveshare.registerTreeDataProvider(LIVE_SHARE_EXPLORER_VIEW_ID, this)
);
}
}