Skip to content

Survey notification implementation #1035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
survey implementation improvements
  • Loading branch information
francescospissu committed Jun 16, 2022
commit f215547a7bb5ff76d29aa64b80040d75ff6402ff
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ import { SaveSketch } from './contributions/save-sketch';
import { VerifySketch } from './contributions/verify-sketch';
import { UploadSketch } from './contributions/upload-sketch';
import { SurveyNotification } from './contributions/survey-notification';
import { SurveyRetriever } from './survey/survey-retriever';
import { CommonFrontendContribution } from './theia/core/common-frontend-contribution';
import { EditContributions } from './contributions/edit-contributions';
import { OpenSketchExternal } from './contributions/open-sketch-external';
Expand Down Expand Up @@ -478,8 +477,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(FrontendApplicationContribution).toService(EditorMode);

// Survey notification
bind(SurveyRetriever).toSelf().inSingletonScope();

bind(SurveyNotification).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(SurveyNotification);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { MessageService } from '@theia/core';
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
import { inject, injectable } from '@theia/core/shared/inversify';
import { shell } from '@theia/electron/shared/electron';
import { LocalStorageService } from '@theia/core/lib/browser';
import { SurveyRetriever } from '../survey/survey-retriever';
import { nls } from '@theia/core/lib/common';
import { WindowService } from '@theia/core/lib/browser/window/window-service';

export type Survey = {
url: URL;
id: string;
};

const SURVEY_MESSAGE = nls.localize(
'arduino/survey/surveyMessage',
Expand All @@ -19,6 +23,9 @@ const GO_TO_SURVEY = nls.localize(
'ANSWER SURVEY'
);

const SURVEY_BASE_URL = 'https://surveys.hotjar.com/';
const surveyId = '17887b40-e1f0-4bd6-b9f0-a37f229ccd8b';

@injectable()
export class SurveyNotification implements FrontendApplicationContribution {
@inject(MessageService)
Expand All @@ -27,30 +34,32 @@ export class SurveyNotification implements FrontendApplicationContribution {
@inject(LocalStorageService)
protected readonly localStorageService: LocalStorageService;

@inject(SurveyRetriever)
protected readonly surveyRetriever: SurveyRetriever;
@inject(WindowService)
protected readonly windowService: WindowService;

async onStart(): Promise<void> {
const survey = await this.surveyRetriever.getSurvey();
const surveyAnswered = await this.localStorageService.getData(
this.surveyKey(survey.id),
'notAnswered'
);

if (surveyAnswered !== 'notAnswered') {
return;
}

this.messageService
.info(SURVEY_MESSAGE, DO_NOT_SHOW_AGAIN, GO_TO_SURVEY)
.then(async (answer) => {
this.localStorageService
.getData(this.surveyKey(surveyId), undefined)
.then((surveyAnswered) => {
if (surveyAnswered !== undefined) {
return;
}
return this.messageService.info(
SURVEY_MESSAGE,
DO_NOT_SHOW_AGAIN,
GO_TO_SURVEY
);
})
.then((answer) => {
switch (answer) {
case GO_TO_SURVEY:
shell.openExternal(survey.url.href);
this.localStorageService.setData(this.surveyKey(survey.id), true);
this.windowService.openNewWindow(SURVEY_BASE_URL + surveyId, {
external: true,
});
this.localStorageService.setData(this.surveyKey(surveyId), true);
break;
case DO_NOT_SHOW_AGAIN:
this.localStorageService.setData(this.surveyKey(survey.id), false);
this.localStorageService.setData(this.surveyKey(surveyId), false);
break;
}
});
Expand Down
20 changes: 0 additions & 20 deletions arduino-ide-extension/src/browser/survey/survey-retriever.ts

This file was deleted.