1
- import { injectable , inject , postConstruct } from 'inversify' ;
1
+ import { injectable , inject } from 'inversify' ;
2
2
import { deepClone } from '@theia/core/lib/common/objects' ;
3
3
import { Emitter , Event } from '@theia/core/lib/common/event' ;
4
4
import { MessageService } from '@theia/core/lib/common/message-service' ;
@@ -24,31 +24,13 @@ import { nls } from '@theia/core/lib/browser/nls';
24
24
25
25
@injectable ( )
26
26
export class SerialConnectionManager {
27
- @inject ( MonitorModel )
28
- protected readonly monitorModel : MonitorModel ;
29
-
30
- @inject ( MonitorService )
31
- protected readonly monitorService : MonitorService ;
32
-
33
- @inject ( MonitorServiceClient )
34
- protected readonly monitorServiceClient : MonitorServiceClient ;
35
-
36
- @inject ( BoardsService )
37
- protected readonly boardsService : BoardsService ;
38
-
39
- @inject ( BoardsServiceProvider )
40
- protected readonly boardsServiceProvider : BoardsServiceProvider ;
41
-
42
- @inject ( NotificationCenter )
43
- protected readonly notificationCenter : NotificationCenter ;
44
-
45
- @inject ( MessageService )
46
- protected messageService : MessageService ;
47
-
48
- @inject ( ThemeService )
49
- protected readonly themeService : ThemeService ;
50
27
protected _state : Serial . State = [ ] ;
51
- protected _connected : boolean ;
28
+ protected _connected = false ;
29
+ protected config : Partial < MonitorConfig > = {
30
+ board : undefined ,
31
+ port : undefined ,
32
+ baudRate : undefined ,
33
+ } ;
52
34
53
35
/**
54
36
* Note: The idea is to toggle this property from the UI (`Monitor` view)
@@ -73,17 +55,21 @@ export class SerialConnectionManager {
73
55
* When the websocket server is up on the backend, we save the port here, so that the client knows how to connect to it
74
56
* */
75
57
protected wsPort ?: number ;
76
-
77
58
protected webSocket ?: WebSocket ;
78
59
79
- protected config : Partial < MonitorConfig > = {
80
- board : undefined ,
81
- port : undefined ,
82
- baudRate : undefined ,
83
- } ;
84
-
85
- @postConstruct ( )
86
- protected init ( ) : void {
60
+ constructor (
61
+ @inject ( MonitorModel ) protected readonly monitorModel : MonitorModel ,
62
+ @inject ( MonitorService ) protected readonly monitorService : MonitorService ,
63
+ @inject ( MonitorServiceClient )
64
+ protected readonly monitorServiceClient : MonitorServiceClient ,
65
+ @inject ( BoardsService ) protected readonly boardsService : BoardsService ,
66
+ @inject ( BoardsServiceProvider )
67
+ protected readonly boardsServiceProvider : BoardsServiceProvider ,
68
+ @inject ( NotificationCenter )
69
+ protected readonly notificationCenter : NotificationCenter ,
70
+ @inject ( MessageService ) protected messageService : MessageService ,
71
+ @inject ( ThemeService ) protected readonly themeService : ThemeService
72
+ ) {
87
73
this . monitorServiceClient . onWebSocketChanged (
88
74
this . handleWebSocketChanged . bind ( this )
89
75
) ;
@@ -136,7 +122,7 @@ export class SerialConnectionManager {
136
122
*
137
123
* @param newConfig the porperties of the config that has changed
138
124
*/
139
- protected setConfig ( newConfig : Partial < MonitorConfig > ) : void {
125
+ setConfig ( newConfig : Partial < MonitorConfig > ) : void {
140
126
let configHasChanged = false ;
141
127
Object . keys ( this . config ) . forEach ( ( key : keyof MonitorConfig ) => {
142
128
if ( newConfig [ key ] && newConfig [ key ] !== this . config [ key ] ) {
@@ -149,10 +135,18 @@ export class SerialConnectionManager {
149
135
}
150
136
}
151
137
138
+ getConfig ( ) : Partial < MonitorConfig > {
139
+ return this . config ;
140
+ }
141
+
152
142
getWsPort ( ) : number | undefined {
153
143
return this . wsPort ;
154
144
}
155
145
146
+ isWebSocketConnected ( ) : boolean {
147
+ return ! ! this . webSocket ?. url ;
148
+ }
149
+
156
150
protected handleWebSocketChanged ( wsPort : number ) : void {
157
151
this . wsPort = wsPort ;
158
152
}
0 commit comments