@@ -4,7 +4,14 @@ import {
44 LocalStorageService ,
55} from '@theia/core/lib/browser' ;
66import { 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' ;
815import { isNullOrUndefined } from '../common/utils' ;
916import { MonitorSettings } from '../node/monitor-settings/monitor-settings-provider' ;
1017
@@ -19,48 +26,48 @@ export class MonitorModel implements FrontendApplicationContribution {
1926 protected readonly monitorManagerProxy : MonitorManagerProxyClient ;
2027
2128 protected readonly onChangeEmitter : Emitter <
22- MonitorModel . State . Change < keyof MonitorModel . State >
29+ MonitorState . Change < keyof MonitorState >
2330 > ;
2431
2532 protected _autoscroll : boolean ;
2633 protected _timestamp : boolean ;
27- protected _lineEnding : MonitorModel . EOL ;
34+ protected _lineEnding : MonitorEOL ;
2835 protected _interpolate : boolean ;
2936 protected _darkTheme : boolean ;
3037 protected _wsPort : number ;
3138 protected _serialPort : string ;
32- protected _connected : boolean ;
39+ protected _connectionStatus : MonitorConnectionStatus ;
3340
3441 constructor ( ) {
3542 this . _autoscroll = true ;
3643 this . _timestamp = false ;
3744 this . _interpolate = false ;
38- this . _lineEnding = MonitorModel . EOL . DEFAULT ;
45+ this . _lineEnding = MonitorEOL . DEFAULT ;
3946 this . _darkTheme = false ;
4047 this . _wsPort = 0 ;
4148 this . _serialPort = '' ;
42- this . _connected = true ;
49+ this . _connectionStatus = 'not-connected' ;
4350
4451 this . onChangeEmitter = new Emitter <
45- MonitorModel . State . Change < keyof MonitorModel . State >
52+ MonitorState . Change < keyof MonitorState >
4653 > ( ) ;
4754 }
4855
4956 onStart ( ) : void {
5057 this . localStorageService
51- . getData < MonitorModel . State > ( MonitorModel . STORAGE_ID )
58+ . getData < MonitorState > ( MonitorModel . STORAGE_ID )
5259 . then ( this . restoreState . bind ( this ) ) ;
5360
5461 this . monitorManagerProxy . onMonitorSettingsDidChange (
5562 this . onMonitorSettingsDidChange . bind ( this )
5663 ) ;
5764 }
5865
59- get onChange ( ) : Event < MonitorModel . State . Change < keyof MonitorModel . State > > {
66+ get onChange ( ) : Event < MonitorState . Change < keyof MonitorState > > {
6067 return this . onChangeEmitter . event ;
6168 }
6269
63- protected restoreState ( state : MonitorModel . State ) : void {
70+ protected restoreState ( state : MonitorState ) : void {
6471 if ( ! state ) {
6572 return ;
6673 }
@@ -125,11 +132,11 @@ export class MonitorModel implements FrontendApplicationContribution {
125132 this . timestamp = ! this . _timestamp ;
126133 }
127134
128- get lineEnding ( ) : MonitorModel . EOL {
135+ get lineEnding ( ) : MonitorEOL {
129136 return this . _lineEnding ;
130137 }
131138
132- set lineEnding ( lineEnding : MonitorModel . EOL ) {
139+ set lineEnding ( lineEnding : MonitorEOL ) {
133140 if ( lineEnding === this . _lineEnding ) return ;
134141 this . _lineEnding = lineEnding ;
135142 this . monitorManagerProxy . changeSettings ( {
@@ -211,19 +218,26 @@ export class MonitorModel implements FrontendApplicationContribution {
211218 ) ;
212219 }
213220
214- get connected ( ) : boolean {
215- return this . _connected ;
221+ get connectionStatus ( ) : MonitorConnectionStatus {
222+ return this . _connectionStatus ;
216223 }
217224
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 ;
221232 this . monitorManagerProxy . changeSettings ( {
222- monitorUISettings : { connected } ,
233+ monitorUISettings : {
234+ connectionStatus,
235+ connected : isMonitorConnected ( connectionStatus ) ,
236+ } ,
223237 } ) ;
224238 this . onChangeEmitter . fire ( {
225- property : 'connected ' ,
226- value : this . _connected ,
239+ property : 'connectionStatus ' ,
240+ value : this . _connectionStatus ,
227241 } ) ;
228242 }
229243
@@ -238,7 +252,7 @@ export class MonitorModel implements FrontendApplicationContribution {
238252 darkTheme,
239253 wsPort,
240254 serialPort,
241- connected ,
255+ connectionStatus ,
242256 } = monitorUISettings ;
243257
244258 if ( ! isNullOrUndefined ( autoscroll ) ) this . autoscroll = autoscroll ;
@@ -248,31 +262,7 @@ export class MonitorModel implements FrontendApplicationContribution {
248262 if ( ! isNullOrUndefined ( darkTheme ) ) this . darkTheme = darkTheme ;
249263 if ( ! isNullOrUndefined ( wsPort ) ) this . wsPort = wsPort ;
250264 if ( ! isNullOrUndefined ( serialPort ) ) this . serialPort = serialPort ;
251- if ( ! isNullOrUndefined ( connected ) ) this . connected = connected ;
265+ if ( ! isNullOrUndefined ( connectionStatus ) )
266+ this . connectionStatus = connectionStatus ;
252267 } ;
253268}
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