@@ -4,7 +4,14 @@ import {
4
4
LocalStorageService ,
5
5
} from '@theia/core/lib/browser' ;
6
6
import { inject , injectable } from '@theia/core/shared/inversify' ;
7
- import { MonitorManagerProxyClient } from '../common/protocol' ;
7
+ import {
8
+ isMonitorConnected ,
9
+ MonitorConnectionStatus ,
10
+ monitorConnectionStatusEquals ,
11
+ MonitorEOL ,
12
+ MonitorManagerProxyClient ,
13
+ MonitorState ,
14
+ } from '../common/protocol' ;
8
15
import { isNullOrUndefined } from '../common/utils' ;
9
16
import { MonitorSettings } from '../node/monitor-settings/monitor-settings-provider' ;
10
17
@@ -19,48 +26,48 @@ export class MonitorModel implements FrontendApplicationContribution {
19
26
protected readonly monitorManagerProxy : MonitorManagerProxyClient ;
20
27
21
28
protected readonly onChangeEmitter : Emitter <
22
- MonitorModel . State . Change < keyof MonitorModel . State >
29
+ MonitorState . Change < keyof MonitorState >
23
30
> ;
24
31
25
32
protected _autoscroll : boolean ;
26
33
protected _timestamp : boolean ;
27
- protected _lineEnding : MonitorModel . EOL ;
34
+ protected _lineEnding : MonitorEOL ;
28
35
protected _interpolate : boolean ;
29
36
protected _darkTheme : boolean ;
30
37
protected _wsPort : number ;
31
38
protected _serialPort : string ;
32
- protected _connected : boolean ;
39
+ protected _connectionStatus : MonitorConnectionStatus ;
33
40
34
41
constructor ( ) {
35
42
this . _autoscroll = true ;
36
43
this . _timestamp = false ;
37
44
this . _interpolate = false ;
38
- this . _lineEnding = MonitorModel . EOL . DEFAULT ;
45
+ this . _lineEnding = MonitorEOL . DEFAULT ;
39
46
this . _darkTheme = false ;
40
47
this . _wsPort = 0 ;
41
48
this . _serialPort = '' ;
42
- this . _connected = true ;
49
+ this . _connectionStatus = 'not-connected' ;
43
50
44
51
this . onChangeEmitter = new Emitter <
45
- MonitorModel . State . Change < keyof MonitorModel . State >
52
+ MonitorState . Change < keyof MonitorState >
46
53
> ( ) ;
47
54
}
48
55
49
56
onStart ( ) : void {
50
57
this . localStorageService
51
- . getData < MonitorModel . State > ( MonitorModel . STORAGE_ID )
58
+ . getData < MonitorState > ( MonitorModel . STORAGE_ID )
52
59
. then ( this . restoreState . bind ( this ) ) ;
53
60
54
61
this . monitorManagerProxy . onMonitorSettingsDidChange (
55
62
this . onMonitorSettingsDidChange . bind ( this )
56
63
) ;
57
64
}
58
65
59
- get onChange ( ) : Event < MonitorModel . State . Change < keyof MonitorModel . State > > {
66
+ get onChange ( ) : Event < MonitorState . Change < keyof MonitorState > > {
60
67
return this . onChangeEmitter . event ;
61
68
}
62
69
63
- protected restoreState ( state : MonitorModel . State ) : void {
70
+ protected restoreState ( state : MonitorState ) : void {
64
71
if ( ! state ) {
65
72
return ;
66
73
}
@@ -125,11 +132,11 @@ export class MonitorModel implements FrontendApplicationContribution {
125
132
this . timestamp = ! this . _timestamp ;
126
133
}
127
134
128
- get lineEnding ( ) : MonitorModel . EOL {
135
+ get lineEnding ( ) : MonitorEOL {
129
136
return this . _lineEnding ;
130
137
}
131
138
132
- set lineEnding ( lineEnding : MonitorModel . EOL ) {
139
+ set lineEnding ( lineEnding : MonitorEOL ) {
133
140
if ( lineEnding === this . _lineEnding ) return ;
134
141
this . _lineEnding = lineEnding ;
135
142
this . monitorManagerProxy . changeSettings ( {
@@ -211,19 +218,26 @@ export class MonitorModel implements FrontendApplicationContribution {
211
218
) ;
212
219
}
213
220
214
- get connected ( ) : boolean {
215
- return this . _connected ;
221
+ get connectionStatus ( ) : MonitorConnectionStatus {
222
+ return this . _connectionStatus ;
216
223
}
217
224
218
- set connected ( connected : boolean ) {
219
- if ( connected === this . _connected ) return ;
220
- this . _connected = connected ;
225
+ set connectionStatus ( connectionStatus : MonitorConnectionStatus ) {
226
+ if (
227
+ monitorConnectionStatusEquals ( connectionStatus , this . connectionStatus )
228
+ ) {
229
+ return ;
230
+ }
231
+ this . _connectionStatus = connectionStatus ;
221
232
this . monitorManagerProxy . changeSettings ( {
222
- monitorUISettings : { connected } ,
233
+ monitorUISettings : {
234
+ connectionStatus,
235
+ connected : isMonitorConnected ( connectionStatus ) ,
236
+ } ,
223
237
} ) ;
224
238
this . onChangeEmitter . fire ( {
225
- property : 'connected ' ,
226
- value : this . _connected ,
239
+ property : 'connectionStatus ' ,
240
+ value : this . _connectionStatus ,
227
241
} ) ;
228
242
}
229
243
@@ -238,7 +252,7 @@ export class MonitorModel implements FrontendApplicationContribution {
238
252
darkTheme,
239
253
wsPort,
240
254
serialPort,
241
- connected ,
255
+ connectionStatus ,
242
256
} = monitorUISettings ;
243
257
244
258
if ( ! isNullOrUndefined ( autoscroll ) ) this . autoscroll = autoscroll ;
@@ -248,31 +262,7 @@ export class MonitorModel implements FrontendApplicationContribution {
248
262
if ( ! isNullOrUndefined ( darkTheme ) ) this . darkTheme = darkTheme ;
249
263
if ( ! isNullOrUndefined ( wsPort ) ) this . wsPort = wsPort ;
250
264
if ( ! isNullOrUndefined ( serialPort ) ) this . serialPort = serialPort ;
251
- if ( ! isNullOrUndefined ( connected ) ) this . connected = connected ;
265
+ if ( ! isNullOrUndefined ( connectionStatus ) )
266
+ this . connectionStatus = connectionStatus ;
252
267
} ;
253
268
}
254
-
255
- // TODO: Move this to /common
256
- export namespace MonitorModel {
257
- export interface State {
258
- autoscroll : boolean ;
259
- timestamp : boolean ;
260
- lineEnding : EOL ;
261
- interpolate : boolean ;
262
- darkTheme : boolean ;
263
- wsPort : number ;
264
- serialPort : string ;
265
- connected : boolean ;
266
- }
267
- export namespace State {
268
- export interface Change < K extends keyof State > {
269
- readonly property : K ;
270
- readonly value : State [ K ] ;
271
- }
272
- }
273
-
274
- export type EOL = '' | '\n' | '\r' | '\r\n' ;
275
- export namespace EOL {
276
- export const DEFAULT : EOL = '\n' ;
277
- }
278
- }
0 commit comments