@@ -14,11 +14,9 @@ import {
14
14
Port ,
15
15
Board ,
16
16
BoardsService ,
17
- AttachedBoardsChangeEvent ,
18
17
} from '../../common/protocol/boards-service' ;
19
18
import { BoardsConfig } from '../boards/boards-config' ;
20
19
import { MonitorModel } from './monitor-model' ;
21
- import { NotificationCenter } from '../notification-center' ;
22
20
import { ThemeService } from '@theia/core/lib/browser/theming' ;
23
21
import { nls } from '@theia/core/lib/browser/nls' ;
24
22
@@ -65,8 +63,6 @@ export class SerialConnectionManager {
65
63
@inject ( BoardsService ) protected readonly boardsService : BoardsService ,
66
64
@inject ( BoardsServiceProvider )
67
65
protected readonly boardsServiceProvider : BoardsServiceProvider ,
68
- @inject ( NotificationCenter )
69
- protected readonly notificationCenter : NotificationCenter ,
70
66
@inject ( MessageService ) protected messageService : MessageService ,
71
67
@inject ( ThemeService ) protected readonly themeService : ThemeService
72
68
) {
@@ -93,9 +89,7 @@ export class SerialConnectionManager {
93
89
this . boardsServiceProvider . onBoardsConfigChanged (
94
90
this . handleBoardConfigChange . bind ( this )
95
91
) ;
96
- this . notificationCenter . onAttachedBoardsChanged (
97
- this . handleAttachedBoardsChanged . bind ( this )
98
- ) ;
92
+
99
93
// Handles the `baudRate` changes by reconnecting if required.
100
94
this . monitorModel . onChange ( ( { property } ) => {
101
95
if ( property === 'baudRate' && this . connected ) {
@@ -130,7 +124,7 @@ export class SerialConnectionManager {
130
124
setConfig ( newConfig : Partial < MonitorConfig > ) : void {
131
125
let configHasChanged = false ;
132
126
Object . keys ( this . config ) . forEach ( ( key : keyof MonitorConfig ) => {
133
- if ( newConfig [ key ] && newConfig [ key ] !== this . config [ key ] ) {
127
+ if ( newConfig [ key ] !== this . config [ key ] ) {
134
128
configHasChanged = true ;
135
129
this . config = { ...this . config , [ key ] : newConfig [ key ] } ;
136
130
}
@@ -222,7 +216,6 @@ export class SerialConnectionManager {
222
216
set connected ( c : boolean ) {
223
217
this . _connected = c ;
224
218
this . monitorService . updateWsConfigParam ( { connected : c } ) ;
225
-
226
219
this . onConnectionChangedEmitter . fire ( this . _connected ) ;
227
220
}
228
221
/**
@@ -365,28 +358,6 @@ export class SerialConnectionManager {
365
358
}
366
359
}
367
360
368
- handleAttachedBoardsChanged ( event : AttachedBoardsChangeEvent ) : void {
369
- const { boardsConfig } = this . boardsServiceProvider ;
370
- if (
371
- this . boardsServiceProvider . canUploadTo ( boardsConfig , {
372
- silent : false ,
373
- } )
374
- ) {
375
- const { attached } = AttachedBoardsChangeEvent . diff ( event ) ;
376
- if (
377
- attached . boards . some (
378
- ( board ) =>
379
- ! ! board . port && BoardsConfig . Config . sameAs ( boardsConfig , board )
380
- )
381
- ) {
382
- const { selectedBoard : board , selectedPort : port } = boardsConfig ;
383
- const { baudRate } = this . monitorModel ;
384
- const newConfig = { board, port, baudRate } ;
385
- this . setConfig ( newConfig ) ;
386
- }
387
- }
388
- }
389
-
390
361
async connect ( ) : Promise < Status > {
391
362
if ( this . connected ) return Status . ALREADY_CONNECTED ;
392
363
if ( ! isMonitorConfig ( this . config ) ) {
@@ -467,21 +438,10 @@ export class SerialConnectionManager {
467
438
protected async handleBoardConfigChange (
468
439
boardsConfig : BoardsConfig . Config
469
440
) : Promise < void > {
470
- if (
471
- this . boardsServiceProvider . canUploadTo ( boardsConfig , {
472
- silent : false ,
473
- } )
474
- ) {
475
- // Instead of calling `getAttachedBoards` and filtering for `AttachedSerialBoard` we have to check the available ports.
476
- // The connected board might be unknown. See: https://github.com/arduino/arduino-pro-ide/issues/127#issuecomment-563251881
477
- const ports = await this . boardsService . getAvailablePorts ( ) ;
478
- if ( ports . some ( ( port ) => Port . equals ( port , boardsConfig . selectedPort ) ) ) {
479
- const { selectedBoard : board , selectedPort : port } = boardsConfig ;
480
- const { baudRate } = this . monitorModel ;
481
- const newConfig : MonitorConfig = { board, port, baudRate } ;
482
- this . setConfig ( newConfig ) ;
483
- }
484
- }
441
+ const { selectedBoard : board , selectedPort : port } = boardsConfig ;
442
+ const { baudRate } = this . monitorModel ;
443
+ const newConfig : Partial < MonitorConfig > = { board, port, baudRate } ;
444
+ this . setConfig ( newConfig ) ;
485
445
}
486
446
}
487
447
0 commit comments