|
6 | 6 | import { inject, injectable } from 'inversify'; |
7 | 7 | import { IExtensionSingleActivationService } from '../../activation/types'; |
8 | 8 | import { IApplicationShell } from '../../common/application/types'; |
9 | | -import { IPersistentState, IPersistentStateFactory } from '../../common/types'; |
| 9 | +import { SurveyAndInterpreterTipNotification } from '../../common/experiments/groups'; |
| 10 | +import { IBrowserService, IExperimentService, IPersistentState, IPersistentStateFactory } from '../../common/types'; |
10 | 11 | import { swallowExceptions } from '../../common/utils/decorators'; |
11 | | -import { Common, Interpreters } from '../../common/utils/localize'; |
| 12 | +import { Common } from '../../common/utils/localize'; |
| 13 | +import { sendTelemetryEvent } from '../../telemetry'; |
| 14 | +import { EventName } from '../../telemetry/constants'; |
| 15 | + |
| 16 | +enum NotificationType { |
| 17 | + Tip, |
| 18 | + Survey, |
| 19 | + NoPrompt |
| 20 | +} |
12 | 21 |
|
13 | 22 | @injectable() |
14 | 23 | export class InterpreterSelectionTip implements IExtensionSingleActivationService { |
15 | 24 | private readonly storage: IPersistentState<boolean>; |
| 25 | + private notificationType: NotificationType; |
| 26 | + private notificationContent: string | undefined; |
| 27 | + |
16 | 28 | constructor( |
17 | 29 | @inject(IApplicationShell) private readonly shell: IApplicationShell, |
18 | | - @inject(IPersistentStateFactory) private readonly factory: IPersistentStateFactory |
| 30 | + @inject(IPersistentStateFactory) private readonly factory: IPersistentStateFactory, |
| 31 | + @inject(IExperimentService) private readonly experiments: IExperimentService, |
| 32 | + @inject(IBrowserService) private browserService: IBrowserService |
19 | 33 | ) { |
20 | 34 | this.storage = this.factory.createGlobalPersistentState('InterpreterSelectionTip', false); |
| 35 | + this.notificationType = NotificationType.NoPrompt; |
21 | 36 | } |
| 37 | + |
22 | 38 | public async activate(): Promise<void> { |
23 | 39 | if (this.storage.value) { |
24 | 40 | return; |
25 | 41 | } |
| 42 | + |
| 43 | + if (await this.experiments.inExperiment(SurveyAndInterpreterTipNotification.surveyExperiment)) { |
| 44 | + this.notificationType = NotificationType.Survey; |
| 45 | + this.notificationContent = await this.experiments.getExperimentValue( |
| 46 | + SurveyAndInterpreterTipNotification.surveyExperiment |
| 47 | + ); |
| 48 | + } else if (await this.experiments.inExperiment(SurveyAndInterpreterTipNotification.tipExperiment)) { |
| 49 | + this.notificationType = NotificationType.Tip; |
| 50 | + this.notificationContent = await this.experiments.getExperimentValue( |
| 51 | + SurveyAndInterpreterTipNotification.tipExperiment |
| 52 | + ); |
| 53 | + } |
| 54 | + |
26 | 55 | this.showTip().ignoreErrors(); |
27 | 56 | } |
28 | 57 | @swallowExceptions('Failed to display tip') |
29 | 58 | private async showTip() { |
30 | | - const selection = await this.shell.showInformationMessage(Interpreters.selectInterpreterTip(), Common.gotIt()); |
31 | | - if (selection !== Common.gotIt()) { |
32 | | - return; |
| 59 | + if (this.notificationType === NotificationType.Tip) { |
| 60 | + await this.shell.showInformationMessage(this.notificationContent!, Common.gotIt()); |
| 61 | + sendTelemetryEvent(EventName.ACTIVATION_TIP_PROMPT, undefined); |
| 62 | + } else if (this.notificationType === NotificationType.Survey) { |
| 63 | + const selection = await this.shell.showInformationMessage( |
| 64 | + this.notificationContent!, |
| 65 | + Common.bannerLabelYes(), |
| 66 | + Common.bannerLabelNo() |
| 67 | + ); |
| 68 | + |
| 69 | + if (selection === Common.bannerLabelYes()) { |
| 70 | + sendTelemetryEvent(EventName.ACTIVATION_SURVEY_PROMPT, undefined); |
| 71 | + this.browserService.launch('https://aka.ms/mailingListSurvey'); |
| 72 | + } |
33 | 73 | } |
| 74 | + |
34 | 75 | await this.storage.updateValue(true); |
35 | 76 | } |
36 | 77 | } |
0 commit comments