@@ -63,14 +63,11 @@ export class MonitorService extends CoreClientAware implements Disposable {
63
63
64
64
private readonly board : Board ,
65
65
private readonly port : Port ,
66
+ private readonly monitorID : string ,
66
67
protected readonly coreClientProvider : CoreClientProvider
67
68
) {
68
69
super ( ) ;
69
70
70
- this . monitorSettingsProvider = {
71
- getSettings : ( ) => ( { } as Promise < PluggableMonitorSettings > ) ,
72
- setSettings : ( ) => ( { } as Promise < PluggableMonitorSettings > ) ,
73
- } ;
74
71
this . onWSClientsNumberChanged =
75
72
this . webSocketProvider . onClientsNumberChanged ( async ( clients : number ) => {
76
73
if ( clients === 0 ) {
@@ -81,13 +78,19 @@ export class MonitorService extends CoreClientAware implements Disposable {
81
78
}
82
79
} ) ;
83
80
84
- this . portMonitorSettings ( port . protocol , board . fqbn ! ) . then ( ( settings ) => {
85
- this . settings = {
86
- ...this . settings ,
87
- pluggableMonitorSettings : settings ,
88
- } ;
89
- this . _initialized . resolve ( ) ;
90
- } ) ;
81
+ this . portMonitorSettings ( port . protocol , board . fqbn ! ) . then (
82
+ async ( settings ) => {
83
+ this . settings = {
84
+ ...this . settings ,
85
+ pluggableMonitorSettings :
86
+ await this . monitorSettingsProvider . getSettings (
87
+ this . monitorID ,
88
+ settings
89
+ ) ,
90
+ } ;
91
+ this . _initialized . resolve ( ) ;
92
+ }
93
+ ) ;
91
94
}
92
95
93
96
get initialized ( ) : Promise < void > {
@@ -368,22 +371,27 @@ export class MonitorService extends CoreClientAware implements Disposable {
368
371
async changeSettings ( settings : MonitorSettings ) : Promise < Status > {
369
372
const config = new MonitorPortConfiguration ( ) ;
370
373
const { pluggableMonitorSettings } = settings ;
374
+ const reconciledSettings = await this . monitorSettingsProvider . setSettings (
375
+ this . monitorID ,
376
+ pluggableMonitorSettings || { }
377
+ ) ;
371
378
372
- this . webSocketProvider . sendMessage ( JSON . stringify ( settings ) ) ;
373
-
374
- if ( pluggableMonitorSettings ) {
375
- for ( const id in pluggableMonitorSettings ) {
379
+ if ( reconciledSettings ) {
380
+ for ( const id in reconciledSettings ) {
376
381
const s = new MonitorPortSetting ( ) ;
377
382
s . setSettingId ( id ) ;
378
- s . setValue ( pluggableMonitorSettings [ id ] . selectedValue ) ;
383
+ s . setValue ( reconciledSettings [ id ] . selectedValue ) ;
379
384
config . addSettings ( s ) ;
380
- this . settings . pluggableMonitorSettings = {
381
- ...this . settings . pluggableMonitorSettings ,
382
- [ id ] : pluggableMonitorSettings [ id ] ,
383
- } ;
384
385
}
385
386
}
386
387
388
+ const command : Monitor . Message = {
389
+ command : Monitor . MiddlewareCommand . ON_SETTINGS_DID_CHANGE ,
390
+ data : { ...settings , pluggableMonitorSettings : reconciledSettings } ,
391
+ } ;
392
+
393
+ this . webSocketProvider . sendMessage ( JSON . stringify ( command ) ) ;
394
+
387
395
if ( ! this . duplex ) {
388
396
return Status . NOT_CONNECTED ;
389
397
}
0 commit comments