|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; |
| 7 | +import { INotificationService, Severity, IPromptChoice } from 'vs/platform/notification/common/notification'; |
| 8 | +import { IExperimentService, IExperiment, ExperimentActionType, IExperimentActionPromptProperties, ExperimentState } from 'vs/workbench/parts/experiments/node/experimentService'; |
| 9 | +import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; |
| 10 | +import { IExtensionsViewlet } from 'vs/workbench/parts/extensions/common/extensions'; |
| 11 | +import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; |
| 12 | +import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; |
| 13 | + |
| 14 | +export class ExperimentalPrompts extends Disposable implements IWorkbenchContribution { |
| 15 | + private _disposables: IDisposable[] = []; |
| 16 | + |
| 17 | + constructor( |
| 18 | + @IExperimentService private experimentService: IExperimentService, |
| 19 | + @IViewletService private viewletService: IViewletService, |
| 20 | + @INotificationService private notificationService: INotificationService, |
| 21 | + @ITelemetryService private telemetryService: ITelemetryService |
| 22 | + |
| 23 | + ) { |
| 24 | + super(); |
| 25 | + this.experimentService.onExperimentEnabled(e => { |
| 26 | + if (e.action && e.action.type === ExperimentActionType.Prompt && e.state === ExperimentState.Run) { |
| 27 | + this.showExperimentalPrompts(e); |
| 28 | + } |
| 29 | + }, this, this._disposables); |
| 30 | + } |
| 31 | + |
| 32 | + private showExperimentalPrompts(experiment: IExperiment): void { |
| 33 | + if (!experiment || !experiment.enabled || !experiment.action || experiment.state !== ExperimentState.Run) { |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + const logTelemetry = (commandText?: string) => { |
| 38 | + /* __GDPR__ |
| 39 | + "experimentalPrompts" : { |
| 40 | + "experimentId": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, |
| 41 | + "commandText": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, |
| 42 | + "cancelled": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true } |
| 43 | + } |
| 44 | + */ |
| 45 | + this.telemetryService.publicLog('experimentalPrompts', { |
| 46 | + experimentId: experiment.id, |
| 47 | + commandText, |
| 48 | + cancelled: !commandText |
| 49 | + }); |
| 50 | + }; |
| 51 | + |
| 52 | + const actionProperties = (<IExperimentActionPromptProperties>experiment.action.properties); |
| 53 | + if (!actionProperties || !actionProperties.promptText) { |
| 54 | + return; |
| 55 | + } |
| 56 | + if (!actionProperties.commands) { |
| 57 | + actionProperties.commands = []; |
| 58 | + } |
| 59 | + |
| 60 | + const choices: IPromptChoice[] = actionProperties.commands.map(command => { |
| 61 | + return { |
| 62 | + label: command.text, |
| 63 | + run: () => { |
| 64 | + logTelemetry(command.text); |
| 65 | + if (command.externalLink) { |
| 66 | + window.open(command.externalLink); |
| 67 | + return; |
| 68 | + } |
| 69 | + if (command.curatedExtensionsKey && Array.isArray(command.curatedExtensionsList)) { |
| 70 | + this.viewletService.openViewlet('workbench.view.extensions', true) |
| 71 | + .then(viewlet => viewlet as IExtensionsViewlet) |
| 72 | + .then(viewlet => { |
| 73 | + if (viewlet) { |
| 74 | + viewlet.search('curated:' + command.curatedExtensionsKey); |
| 75 | + } |
| 76 | + }); |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + this.experimentService.markAsCompleted(experiment.id); |
| 81 | + |
| 82 | + } |
| 83 | + }; |
| 84 | + }); |
| 85 | + |
| 86 | + this.notificationService.prompt(Severity.Info, actionProperties.promptText, choices, logTelemetry); |
| 87 | + } |
| 88 | + |
| 89 | + dispose() { |
| 90 | + this._disposables = dispose(this._disposables); |
| 91 | + } |
| 92 | +} |
0 commit comments