1
1
import { MessageService } from '@theia/core' ;
2
2
import { FrontendApplicationContribution } from '@theia/core/lib/browser' ;
3
3
import { inject , injectable } from '@theia/core/shared/inversify' ;
4
- import { shell } from '@theia/electron/shared/electron' ;
5
4
import { LocalStorageService } from '@theia/core/lib/browser' ;
6
- import { SurveyRetriever } from '../survey/survey-retriever' ;
7
5
import { nls } from '@theia/core/lib/common' ;
6
+ import { WindowService } from '@theia/core/lib/browser/window/window-service' ;
7
+
8
+ export type Survey = {
9
+ url : URL ;
10
+ id : string ;
11
+ } ;
8
12
9
13
const SURVEY_MESSAGE = nls . localize (
10
14
'arduino/survey/surveyMessage' ,
@@ -19,6 +23,9 @@ const GO_TO_SURVEY = nls.localize(
19
23
'ANSWER SURVEY'
20
24
) ;
21
25
26
+ const SURVEY_BASE_URL = 'https://surveys.hotjar.com/' ;
27
+ const surveyId = '17887b40-e1f0-4bd6-b9f0-a37f229ccd8b' ;
28
+
22
29
@injectable ( )
23
30
export class SurveyNotification implements FrontendApplicationContribution {
24
31
@inject ( MessageService )
@@ -27,30 +34,32 @@ export class SurveyNotification implements FrontendApplicationContribution {
27
34
@inject ( LocalStorageService )
28
35
protected readonly localStorageService : LocalStorageService ;
29
36
30
- @inject ( SurveyRetriever )
31
- protected readonly surveyRetriever : SurveyRetriever ;
37
+ @inject ( WindowService )
38
+ protected readonly windowService : WindowService ;
32
39
33
40
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 ) => {
41
+ this . localStorageService
42
+ . getData ( this . surveyKey ( surveyId ) , undefined )
43
+ . then ( ( surveyAnswered ) => {
44
+ if ( surveyAnswered !== undefined ) {
45
+ return ;
46
+ }
47
+ return this . messageService . info (
48
+ SURVEY_MESSAGE ,
49
+ DO_NOT_SHOW_AGAIN ,
50
+ GO_TO_SURVEY
51
+ ) ;
52
+ } )
53
+ . then ( ( answer ) => {
47
54
switch ( answer ) {
48
55
case GO_TO_SURVEY :
49
- shell . openExternal ( survey . url . href ) ;
50
- this . localStorageService . setData ( this . surveyKey ( survey . id ) , true ) ;
56
+ this . windowService . openNewWindow ( SURVEY_BASE_URL + surveyId , {
57
+ external : true ,
58
+ } ) ;
59
+ this . localStorageService . setData ( this . surveyKey ( surveyId ) , true ) ;
51
60
break ;
52
61
case DO_NOT_SHOW_AGAIN :
53
- this . localStorageService . setData ( this . surveyKey ( survey . id ) , false ) ;
62
+ this . localStorageService . setData ( this . surveyKey ( surveyId ) , false ) ;
54
63
break ;
55
64
}
56
65
} ) ;
0 commit comments