/
liveshare.ts
46 lines (39 loc) · 1.7 KB
/
liveshare.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import * as vsls from 'vsls/vscode';
import { ILiveShareApi, IWorkspaceService } from '../application/types';
import { IConfigurationService, IDisposableRegistry } from '../types';
// tslint:disable:no-any unified-signatures
@injectable()
export class LiveShareApi implements ILiveShareApi {
private supported : boolean = false;
private apiPromise : Promise<vsls.LiveShare | null> | undefined;
constructor(
@inject(IDisposableRegistry) disposableRegistry : IDisposableRegistry,
@inject(IWorkspaceService) workspace : IWorkspaceService,
@inject(IConfigurationService) private configService : IConfigurationService
) {
const disposable = workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('python.dataScience', undefined)) {
// When config changes happen, recreate our commands.
this.onSettingsChanged();
}
});
disposableRegistry.push(disposable);
this.onSettingsChanged();
}
public getApi(): Promise<vsls.LiveShare | null> {
return this.apiPromise!;
}
private onSettingsChanged() {
const supported = this.configService.getSettings().datascience.allowLiveShare;
if (supported !== this.supported) {
this.supported = supported ? true : false;
this.apiPromise = supported ? vsls.getApi() : Promise.resolve(null);
} else if (!this.apiPromise) {
this.apiPromise = Promise.resolve(null);
}
}
}