Skip to content

Commit 9db3cf3

Browse files
survey notification implementation
1 parent fd5154a commit 9db3cf3

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ import { SaveAsSketch } from './contributions/save-as-sketch';
121121
import { SaveSketch } from './contributions/save-sketch';
122122
import { VerifySketch } from './contributions/verify-sketch';
123123
import { UploadSketch } from './contributions/upload-sketch';
124+
import { SurveyNotification } from './contributions/survey-notification';
125+
import { SurveyRetriever } from './survey/survey-retriever';
124126
import { CommonFrontendContribution } from './theia/core/common-frontend-contribution';
125127
import { EditContributions } from './contributions/edit-contributions';
126128
import { OpenSketchExternal } from './contributions/open-sketch-external';
@@ -475,6 +477,12 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
475477
bind(EditorMode).toSelf().inSingletonScope();
476478
bind(FrontendApplicationContribution).toService(EditorMode);
477479

480+
// Survey notification
481+
bind(SurveyRetriever).toSelf().inSingletonScope();
482+
483+
bind(SurveyNotification).toSelf().inSingletonScope();
484+
bind(FrontendApplicationContribution).toService(SurveyNotification);
485+
478486
// Layout and shell customizations.
479487
rebind(TheiaOutlineViewContribution)
480488
.to(OutlineViewContribution)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 { shell } from '@theia/electron/shared/electron';
5+
import { LocalStorageService } from '@theia/core/lib/browser';
6+
import { SurveyRetriever } from '../survey/survey-retriever';
7+
import { nls } from '@theia/core/lib/common';
8+
9+
const SURVEY_MESSAGE = nls.localize(
10+
'arduino/survey/surveyMessage',
11+
'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.'
12+
);
13+
const DO_NOT_SHOW_AGAIN = nls.localize(
14+
'arduino/survey/dismissSurvey',
15+
'DON’T SHOW ANYMORE'
16+
);
17+
const GO_TO_SURVEY = nls.localize(
18+
'arduino/survey/answerSurvey',
19+
'ANSWER SURVEY'
20+
);
21+
22+
@injectable()
23+
export class SurveyNotification implements FrontendApplicationContribution {
24+
@inject(MessageService)
25+
protected readonly messageService: MessageService;
26+
27+
@inject(LocalStorageService)
28+
protected readonly localStorageService: LocalStorageService;
29+
30+
@inject(SurveyRetriever)
31+
protected readonly surveyRetriever: SurveyRetriever;
32+
33+
async onStart(): Promise<void> {
34+
const survey = await this.surveyRetriever.getSurvey();
35+
const surveyAnswered = await this.localStorageService.getData(
36+
this.surveyKey(survey.id),
37+
'notAnswered'
38+
);
39+
40+
if (surveyAnswered !== 'notAnswered') {
41+
return;
42+
}
43+
44+
this.messageService
45+
.info(SURVEY_MESSAGE, DO_NOT_SHOW_AGAIN, GO_TO_SURVEY)
46+
.then(async (answer) => {
47+
switch (answer) {
48+
case GO_TO_SURVEY:
49+
shell.openExternal(survey.url.href);
50+
this.localStorageService.setData(this.surveyKey(survey.id), true);
51+
break;
52+
case DO_NOT_SHOW_AGAIN:
53+
this.localStorageService.setData(this.surveyKey(survey.id), false);
54+
break;
55+
}
56+
});
57+
}
58+
59+
private surveyKey(id: string): string {
60+
return `answered_survey:${id}`;
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { injectable } from '@theia/core/shared/inversify';
2+
3+
export type Survey = {
4+
url: URL;
5+
id: string;
6+
};
7+
8+
const SURVEY_BASE_URL = 'https://surveys.hotjar.com/';
9+
const surveyId = '17887b40-e1f0-4bd6-b9f0-a37f229ccd8b';
10+
11+
@injectable()
12+
export class SurveyRetriever {
13+
public async getSurvey(): Promise<Survey> {
14+
const survey: Survey = {
15+
url: new URL(SURVEY_BASE_URL + surveyId),
16+
id: surveyId,
17+
};
18+
return new Promise((resolve) => setTimeout(() => resolve(survey), 1000));
19+
}
20+
}

0 commit comments

Comments
 (0)