|
| 1 | +import { MessageService } from '@theia/core'; |
| 2 | +import { FrontendApplicationContribution } from '@theia/core/lib/browser'; |
| 3 | +import { inject, injectable } from '@theia/core/shared/inversify'; |
| 4 | +import { LocalStorageService } from '@theia/core/lib/browser'; |
| 5 | +import { nls } from '@theia/core/lib/common'; |
| 6 | +import { WindowService } from '@theia/core/lib/browser/window/window-service'; |
| 7 | +import { ArduinoPreferences } from '../arduino-preferences'; |
| 8 | +import { SurveyNotificationService } from '../../common/protocol/survey-service'; |
| 9 | + |
| 10 | +const SURVEY_MESSAGE = nls.localize( |
| 11 | + 'arduino/survey/surveyMessage', |
| 12 | + 'Please help us improve by answering this super short survey. We value our community and would like to get to know our supporters a little better.' |
| 13 | +); |
| 14 | +const DO_NOT_SHOW_AGAIN = nls.localize( |
| 15 | + 'arduino/survey/dismissSurvey', |
| 16 | + "Don't show again" |
| 17 | +); |
| 18 | +const GO_TO_SURVEY = nls.localize( |
| 19 | + 'arduino/survey/answerSurvey', |
| 20 | + 'Answer survey' |
| 21 | +); |
| 22 | + |
| 23 | +const SURVEY_BASE_URL = 'https://surveys.hotjar.com/'; |
| 24 | +const surveyId = '17887b40-e1f0-4bd6-b9f0-a37f229ccd8b'; |
| 25 | + |
| 26 | +@injectable() |
| 27 | +export class SurveyNotification implements FrontendApplicationContribution { |
| 28 | + @inject(MessageService) |
| 29 | + private readonly messageService: MessageService; |
| 30 | + |
| 31 | + @inject(LocalStorageService) |
| 32 | + private readonly localStorageService: LocalStorageService; |
| 33 | + |
| 34 | + @inject(WindowService) |
| 35 | + private readonly windowService: WindowService; |
| 36 | + |
| 37 | + @inject(ArduinoPreferences) |
| 38 | + private readonly arduinoPreferences: ArduinoPreferences; |
| 39 | + |
| 40 | + @inject(SurveyNotificationService) |
| 41 | + private readonly surveyNotificationService: SurveyNotificationService; |
| 42 | + |
| 43 | + onStart(): void { |
| 44 | + this.arduinoPreferences.ready.then(async () => { |
| 45 | + if ( |
| 46 | + (await this.surveyNotificationService.isFirstInstance()) && |
| 47 | + this.arduinoPreferences.get('arduino.survey.notification') |
| 48 | + ) { |
| 49 | + const surveyAnswered = await this.localStorageService.getData( |
| 50 | + this.surveyKey(surveyId) |
| 51 | + ); |
| 52 | + if (surveyAnswered !== undefined) { |
| 53 | + return; |
| 54 | + } |
| 55 | + const answer = await this.messageService.info( |
| 56 | + SURVEY_MESSAGE, |
| 57 | + DO_NOT_SHOW_AGAIN, |
| 58 | + GO_TO_SURVEY |
| 59 | + ); |
| 60 | + switch (answer) { |
| 61 | + case GO_TO_SURVEY: |
| 62 | + this.windowService.openNewWindow(SURVEY_BASE_URL + surveyId, { |
| 63 | + external: true, |
| 64 | + }); |
| 65 | + this.localStorageService.setData(this.surveyKey(surveyId), true); |
| 66 | + break; |
| 67 | + case DO_NOT_SHOW_AGAIN: |
| 68 | + this.localStorageService.setData(this.surveyKey(surveyId), false); |
| 69 | + break; |
| 70 | + } |
| 71 | + } |
| 72 | + }); |
| 73 | + } |
| 74 | + |
| 75 | + private surveyKey(id: string): string { |
| 76 | + return `answered_survey:${id}`; |
| 77 | + } |
| 78 | +} |
0 commit comments