1
1
import * as React from '@theia/core/shared/react' ;
2
- import { injectable , inject } from '@theia/core/shared/inversify' ;
2
+ import {
3
+ injectable ,
4
+ inject ,
5
+ postConstruct ,
6
+ } from '@theia/core/shared/inversify' ;
3
7
import { Emitter } from '@theia/core/lib/common/event' ;
4
8
import { Disposable } from '@theia/core/lib/common/disposable' ;
5
9
import {
@@ -19,6 +23,7 @@ import {
19
23
} from '../../../common/protocol' ;
20
24
import { MonitorModel } from '../../monitor-model' ;
21
25
import { MonitorSettings } from '../../../node/monitor-settings/monitor-settings-provider' ;
26
+ import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state' ;
22
27
23
28
@injectable ( )
24
29
export class MonitorWidget extends ReactWidget {
@@ -43,40 +48,38 @@ export class MonitorWidget extends ReactWidget {
43
48
protected closing = false ;
44
49
protected readonly clearOutputEmitter = new Emitter < void > ( ) ;
45
50
46
- constructor (
47
- @inject ( MonitorModel )
48
- protected readonly monitorModel : MonitorModel ,
49
-
50
- @inject ( MonitorManagerProxyClient )
51
- protected readonly monitorManagerProxy : MonitorManagerProxyClient ,
51
+ @inject ( MonitorModel )
52
+ private readonly monitorModel : MonitorModel ;
53
+ @inject ( MonitorManagerProxyClient )
54
+ private readonly monitorManagerProxy : MonitorManagerProxyClient ;
55
+ @inject ( BoardsServiceProvider )
56
+ private readonly boardsServiceProvider : BoardsServiceProvider ;
57
+ @inject ( FrontendApplicationStateService )
58
+ private readonly appStateService : FrontendApplicationStateService ;
52
59
53
- @inject ( BoardsServiceProvider )
54
- protected readonly boardsServiceProvider : BoardsServiceProvider
55
- ) {
60
+ constructor ( ) {
56
61
super ( ) ;
57
62
this . id = MonitorWidget . ID ;
58
63
this . title . label = MonitorWidget . LABEL ;
59
64
this . title . iconClass = 'monitor-tab-icon' ;
60
65
this . title . closable = true ;
61
66
this . scrollOptions = undefined ;
62
67
this . toDispose . push ( this . clearOutputEmitter ) ;
63
- this . toDispose . push (
64
- Disposable . create ( ( ) => this . monitorManagerProxy . disconnect ( ) )
65
- ) ;
66
68
}
67
69
68
- protected override onBeforeAttach ( msg : Message ) : void {
69
- this . update ( ) ;
70
- this . toDispose . push ( this . monitorModel . onChange ( ( ) => this . update ( ) ) ) ;
71
- this . getCurrentSettings ( ) . then ( this . onMonitorSettingsDidChange . bind ( this ) ) ;
72
- this . monitorManagerProxy . onMonitorSettingsDidChange (
73
- this . onMonitorSettingsDidChange . bind ( this )
74
- ) ;
75
-
76
- this . monitorManagerProxy . startMonitor ( ) ;
70
+ @postConstruct ( )
71
+ protected init ( ) : void {
72
+ this . toDispose . pushAll ( [
73
+ Disposable . create ( ( ) => this . monitorManagerProxy . disconnect ( ) ) ,
74
+ this . monitorModel . onChange ( ( ) => this . update ( ) ) ,
75
+ this . monitorManagerProxy . onMonitorSettingsDidChange ( ( event ) =>
76
+ this . updateSettings ( event )
77
+ ) ,
78
+ ] ) ;
79
+ this . startMonitor ( ) ;
77
80
}
78
81
79
- onMonitorSettingsDidChange ( settings : MonitorSettings ) : void {
82
+ private updateSettings ( settings : MonitorSettings ) : void {
80
83
this . settings = {
81
84
...this . settings ,
82
85
pluggableMonitorSettings : {
@@ -92,10 +95,6 @@ export class MonitorWidget extends ReactWidget {
92
95
this . update ( ) ;
93
96
}
94
97
95
- override dispose ( ) : void {
96
- super . dispose ( ) ;
97
- }
98
-
99
98
protected override onCloseRequest ( msg : Message ) : void {
100
99
this . closing = true ;
101
100
super . onCloseRequest ( msg ) ;
@@ -125,7 +124,7 @@ export class MonitorWidget extends ReactWidget {
125
124
this . update ( ) ;
126
125
}
127
126
128
- protected onFocusResolved = ( element : HTMLElement | undefined ) => {
127
+ protected onFocusResolved = ( element : HTMLElement | undefined ) : void => {
129
128
if ( this . closing || ! this . isAttached ) {
130
129
return ;
131
130
}
@@ -159,17 +158,28 @@ export class MonitorWidget extends ReactWidget {
159
158
] ;
160
159
}
161
160
162
- private getCurrentSettings ( ) : Promise < MonitorSettings > {
161
+ private async startMonitor ( ) : Promise < void > {
162
+ await this . appStateService . reachedState ( 'ready' ) ;
163
+ await this . boardsServiceProvider . reconciled ;
164
+ await this . syncSettings ( ) ;
165
+ await this . monitorManagerProxy . startMonitor ( ) ;
166
+ }
167
+
168
+ private async syncSettings ( ) : Promise < void > {
169
+ const settings = await this . getCurrentSettings ( ) ;
170
+ this . updateSettings ( settings ) ;
171
+ }
172
+
173
+ private async getCurrentSettings ( ) : Promise < MonitorSettings > {
163
174
const board = this . boardsServiceProvider . boardsConfig . selectedBoard ;
164
175
const port = this . boardsServiceProvider . boardsConfig . selectedPort ;
165
176
if ( ! board || ! port ) {
166
- return Promise . resolve ( this . settings || { } ) ;
177
+ return this . settings || { } ;
167
178
}
168
179
return this . monitorManagerProxy . getCurrentSettings ( board , port ) ;
169
180
}
170
181
171
182
protected render ( ) : React . ReactNode {
172
- debugger ;
173
183
const baudrate = this . settings ?. pluggableMonitorSettings
174
184
? this . settings . pluggableMonitorSettings . baudrate
175
185
: undefined ;
0 commit comments