@@ -3,9 +3,13 @@ import { FrontendApplicationStateService } from '@theia/core/lib/browser/fronten
3
3
import { DisposableCollection } from '@theia/core/lib/common/disposable' ;
4
4
import { Emitter , Event } from '@theia/core/lib/common/event' ;
5
5
import { MessageService } from '@theia/core/lib/common/message-service' ;
6
- import { Deferred } from '@theia/core/lib/common/promise-util ' ;
6
+ import { deepClone } from '@theia/core/lib/common/objects ' ;
7
7
import URI from '@theia/core/lib/common/uri' ;
8
- import { inject , injectable } from '@theia/core/shared/inversify' ;
8
+ import {
9
+ inject ,
10
+ injectable ,
11
+ postConstruct ,
12
+ } from '@theia/core/shared/inversify' ;
9
13
import { Config , ConfigService , ConfigState } from '../../common/protocol' ;
10
14
import { NotificationCenter } from '../notification-center' ;
11
15
@@ -29,16 +33,17 @@ export class ConfigServiceClient implements FrontendApplicationContribution {
29
33
this . didChangeDataDirUriEmitter
30
34
) ;
31
35
32
- private configFileUri : Deferred < URI > | undefined ;
33
36
private _config : ConfigState | undefined ;
34
- private _dataDirUri : string | undefined ;
35
- private _sketchDirUri : string | undefined ;
36
37
37
- onStart ( ) : void {
38
+ @postConstruct ( )
39
+ protected init ( ) : void {
38
40
this . appStateService . reachedState ( 'ready' ) . then ( async ( ) => {
39
41
const config = await this . fetchConfig ( ) ;
40
42
this . use ( config ) ;
41
43
} ) ;
44
+ }
45
+
46
+ onStart ( ) : void {
42
47
this . notificationCenter . onConfigDidChange ( ( config ) => this . use ( config ) ) ;
43
48
}
44
49
@@ -54,26 +59,6 @@ export class ConfigServiceClient implements FrontendApplicationContribution {
54
59
return this . didChangeSketchDirUriEmitter . event ;
55
60
}
56
61
57
- async getCliConfigFileUri ( ) : Promise < URI > {
58
- if ( ! this . configFileUri ) {
59
- this . configFileUri = new Deferred ( ) ;
60
- setTimeout ( async ( ) => {
61
- try {
62
- const uri = await this . delegate . getCliConfigFileUri ( ) ;
63
- this . configFileUri ?. resolve ( new URI ( uri ) ) ;
64
- } catch ( err ) {
65
- console . error (
66
- `Could not retrieve the URI of the CLI configuration file` ,
67
- err
68
- ) ;
69
- this . configFileUri ?. reject ( err ) ;
70
- this . configFileUri = undefined ;
71
- }
72
- } ) ;
73
- }
74
- return this . configFileUri . promise ;
75
- }
76
-
77
62
async fetchConfig ( ) : Promise < ConfigState > {
78
63
return this . delegate . getConfiguration ( ) ;
79
64
}
@@ -90,32 +75,43 @@ export class ConfigServiceClient implements FrontendApplicationContribution {
90
75
* `directories.user`
91
76
*/
92
77
tryGetSketchDirUri ( ) : URI | undefined {
93
- return this . _sketchDirUri ? new URI ( this . _sketchDirUri ) : undefined ;
78
+ return this . _config ?. config ?. sketchDirUri
79
+ ? new URI ( this . _config ?. config ?. sketchDirUri )
80
+ : undefined ;
94
81
}
95
82
96
83
/**
97
84
* `directories.data`
98
85
*/
99
86
tryGetDataDirUri ( ) : URI | undefined {
100
- return this . _dataDirUri ? new URI ( this . _dataDirUri ) : undefined ;
87
+ return this . _config ?. config ?. dataDirUri
88
+ ? new URI ( this . _config ?. config ?. dataDirUri )
89
+ : undefined ;
101
90
}
102
91
103
92
private use ( config : ConfigState ) : void {
93
+ const oldConfig = deepClone ( this . _config ) ;
104
94
this . _config = config ;
105
- if ( this . _dataDirUri !== this . _config ?. config ?. dataDirUri ) {
106
- this . _dataDirUri = this . _config ?. config ?. dataDirUri ;
95
+ if ( oldConfig ?. config ?. dataDirUri !== this . _config ?. config ?. dataDirUri ) {
107
96
this . didChangeDataDirUriEmitter . fire (
108
- this . _dataDirUri ? new URI ( this . _dataDirUri ) : undefined
97
+ this . _config . config ?. dataDirUri
98
+ ? new URI ( this . _config . config . dataDirUri )
99
+ : undefined
109
100
) ;
110
101
}
111
- if ( this . _sketchDirUri !== this . _config ?. config ?. sketchDirUri ) {
112
- this . _sketchDirUri = this . _config ?. config ?. sketchDirUri ;
102
+ if (
103
+ oldConfig ?. config ?. sketchDirUri !== this . _config ?. config ?. sketchDirUri
104
+ ) {
113
105
this . didChangeSketchDirUriEmitter . fire (
114
- this . _sketchDirUri ? new URI ( this . _sketchDirUri ) : undefined
106
+ this . _config . config ?. sketchDirUri
107
+ ? new URI ( this . _config . config . sketchDirUri )
108
+ : undefined
115
109
) ;
116
110
}
117
111
if ( this . _config . messages ?. length ) {
118
- this . messageService . error ( this . _config . messages . join ( ' ' ) ) ;
112
+ const message = this . _config . messages . join ( ' ' ) ;
113
+ // toast the error later otherwise it might not show up in IDE2
114
+ setTimeout ( ( ) => this . messageService . error ( message ) , 1_000 ) ;
119
115
}
120
116
}
121
117
}
0 commit comments