未验证 提交 ff225b9f 编写于 作者: S SteVen Batten 提交者: GitHub

add telemetry enablement api (#117944)

上级 4de8cb29
......@@ -2708,6 +2708,10 @@ declare module 'vscode' {
namespace env {
export function openExternal(target: Uri, options?: OpenExternalOptions): Thenable<boolean>;
export const isTelemetryEnabled: boolean;
export const onDidChangeTelemetryEnabled: Event<boolean>;
}
//#endregion
......
......@@ -4,24 +4,46 @@
*--------------------------------------------------------------------------------------------*/
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { MainThreadTelemetryShape, MainContext, IExtHostContext } from '../common/extHost.protocol';
import { MainThreadTelemetryShape, MainContext, IExtHostContext, ExtHostTelemetryShape, ExtHostContext } from '../common/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { ClassifiedEvent, StrictPropertyCheck, GDPRClassification } from 'vs/platform/telemetry/common/gdprTypings';
import { Disposable } from 'vs/base/common/lifecycle';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@extHostNamedCustomer(MainContext.MainThreadTelemetry)
export class MainThreadTelemetry implements MainThreadTelemetryShape {
export class MainThreadTelemetry extends Disposable implements MainThreadTelemetryShape {
private readonly _proxy: ExtHostTelemetryShape;
private static readonly _name = 'pluginHostTelemetry';
constructor(
extHostContext: IExtHostContext,
@ITelemetryService private readonly _telemetryService: ITelemetryService
@ITelemetryService private readonly _telemetryService: ITelemetryService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IEnvironmentService private readonly _environmenService: IEnvironmentService,
) {
//
super();
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTelemetry);
if (!this._environmenService.disableTelemetry) {
this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectedKeys.includes('telemetry.enableTelemetry')) {
this._proxy.$onDidChangeTelemetryEnabled(this.telemetryEnabled);
}
}));
}
this._proxy.$initializeTelemetryEnabled(this.telemetryEnabled);
}
dispose(): void {
//
private get telemetryEnabled(): boolean {
if (this._environmenService.disableTelemetry) {
return false;
}
return !!this._configurationService.getValue('telemetry.enableTelemetry');
}
$publicLog(eventName: string, data: any = Object.create(null)): void {
......
......@@ -85,6 +85,7 @@ import { ExtHostTesting } from 'vs/workbench/api/common/extHostTesting';
import { ExtHostUriOpeners } from 'vs/workbench/api/common/extHostUriOpener';
import { IExtHostSecretState } from 'vs/workbench/api/common/exHostSecretState';
import { ExtHostEditorTabs } from 'vs/workbench/api/common/extHostEditorTabs';
import { IExtHostTelemetry } from 'vs/workbench/api/common/extHostTelemetry';
export interface IExtensionApiFactory {
(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode;
......@@ -101,6 +102,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
const extHostConsumerFileSystem = accessor.get(IExtHostConsumerFileSystem);
const extensionService = accessor.get(IExtHostExtensionService);
const extHostWorkspace = accessor.get(IExtHostWorkspace);
const extHostTelemetry = accessor.get(IExtHostTelemetry);
const extHostConfiguration = accessor.get(IExtHostConfiguration);
const uriTransformer = accessor.get(IURITransformerService);
const rpcProtocol = accessor.get(IExtHostRpcService);
......@@ -122,6 +124,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
rpcProtocol.set(ExtHostContext.ExtHostTunnelService, extHostTunnelService);
rpcProtocol.set(ExtHostContext.ExtHostWindow, extHostWindow);
rpcProtocol.set(ExtHostContext.ExtHostSecretState, extHostSecretState);
rpcProtocol.set(ExtHostContext.ExtHostTelemetry, extHostTelemetry);
// automatically create and register addressable instances
const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, accessor.get(IExtHostDecorations));
......@@ -292,6 +295,14 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
get shell() {
return extHostTerminalService.getDefaultShell(false, configProvider);
},
get isTelemetryEnabled() {
checkProposedApiEnabled(extension);
return extHostTelemetry.getTelemetryEnabled();
},
get onDidChangeTelemetryEnabled(): Event<boolean> {
checkProposedApiEnabled(extension);
return extHostTelemetry.onDidChangeTelemetryEnabled;
},
openExternal(uri: URI, options?: { allowContributedOpeners?: boolean | string; }) {
return extHostWindow.openUri(uri, {
allowTunneling: !!initData.remote.authority,
......
......@@ -22,6 +22,7 @@ import { IExtHostWindow, ExtHostWindow } from 'vs/workbench/api/common/extHostWi
import { IExtHostConsumerFileSystem, ExtHostConsumerFileSystem } from 'vs/workbench/api/common/extHostFileSystemConsumer';
import { IExtHostFileSystemInfo, ExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo';
import { IExtHostSecretState, ExtHostSecretState } from 'vs/workbench/api/common/exHostSecretState';
import { ExtHostTelemetry, IExtHostTelemetry } from 'vs/workbench/api/common/extHostTelemetry';
registerSingleton(IExtensionStoragePaths, ExtensionStoragePaths);
registerSingleton(IExtHostApiDeprecationService, ExtHostApiDeprecationService);
......@@ -41,3 +42,4 @@ registerSingleton(IExtHostTunnelService, ExtHostTunnelService);
registerSingleton(IExtHostWindow, ExtHostWindow);
registerSingleton(IExtHostWorkspace, ExtHostWorkspace);
registerSingleton(IExtHostSecretState, ExtHostSecretState);
registerSingleton(IExtHostTelemetry, ExtHostTelemetry);
......@@ -1536,6 +1536,11 @@ export interface ExtHostQuickOpenShape {
$onDidHide(sessionId: number): void;
}
export interface ExtHostTelemetryShape {
$initializeTelemetryEnabled(enabled: boolean): void;
$onDidChangeTelemetryEnabled(enabled: boolean): void;
}
export interface IShellLaunchConfigDto {
name?: string;
executable?: string;
......@@ -1962,4 +1967,5 @@ export const ExtHostContext = {
ExtHostAuthentication: createMainId<ExtHostAuthenticationShape>('ExtHostAuthentication'),
ExtHostTimeline: createMainId<ExtHostTimelineShape>('ExtHostTimeline'),
ExtHostTesting: createMainId<ExtHostTestingShape>('ExtHostTesting'),
ExtHostTelemetry: createMainId<ExtHostTelemetryShape>('ExtHostTelemetry'),
};
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { Event, Emitter } from 'vs/base/common/event';
import { ExtHostTelemetryShape } from 'vs/workbench/api/common/extHost.protocol';
export class ExtHostTelemetry implements ExtHostTelemetryShape {
private readonly _onDidChangeTelemetryEnabled = new Emitter<boolean>();
readonly onDidChangeTelemetryEnabled: Event<boolean> = this._onDidChangeTelemetryEnabled.event;
private _enabled: boolean = false;
getTelemetryEnabled(): boolean {
return this._enabled;
}
$initializeTelemetryEnabled(enabled: boolean): void {
this._enabled = enabled;
}
$onDidChangeTelemetryEnabled(enabled: boolean): void {
this._enabled = enabled;
this._onDidChangeTelemetryEnabled.fire(enabled);
}
}
export const IExtHostTelemetry = createDecorator<IExtHostTelemetry>('IExtHostTelemetry');
export interface IExtHostTelemetry extends ExtHostTelemetry, ExtHostTelemetryShape { }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册