Skip to content

Commit c3caab6

Browse files
Alberto Iannacconefstasi
Alberto Iannaccone
authored andcommitted
fix reconnecting issues
1 parent a3a22e5 commit c3caab6

File tree

2 files changed

+6
-50
lines changed

2 files changed

+6
-50
lines changed

arduino-ide-extension/src/browser/monitor/monitor-connection.ts

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ import {
1414
Port,
1515
Board,
1616
BoardsService,
17-
AttachedBoardsChangeEvent,
1817
} from '../../common/protocol/boards-service';
1918
import { BoardsConfig } from '../boards/boards-config';
2019
import { MonitorModel } from './monitor-model';
21-
import { NotificationCenter } from '../notification-center';
2220
import { ThemeService } from '@theia/core/lib/browser/theming';
2321
import { nls } from '@theia/core/lib/browser/nls';
2422

@@ -65,8 +63,6 @@ export class SerialConnectionManager {
6563
@inject(BoardsService) protected readonly boardsService: BoardsService,
6664
@inject(BoardsServiceProvider)
6765
protected readonly boardsServiceProvider: BoardsServiceProvider,
68-
@inject(NotificationCenter)
69-
protected readonly notificationCenter: NotificationCenter,
7066
@inject(MessageService) protected messageService: MessageService,
7167
@inject(ThemeService) protected readonly themeService: ThemeService
7268
) {
@@ -93,9 +89,7 @@ export class SerialConnectionManager {
9389
this.boardsServiceProvider.onBoardsConfigChanged(
9490
this.handleBoardConfigChange.bind(this)
9591
);
96-
this.notificationCenter.onAttachedBoardsChanged(
97-
this.handleAttachedBoardsChanged.bind(this)
98-
);
92+
9993
// Handles the `baudRate` changes by reconnecting if required.
10094
this.monitorModel.onChange(({ property }) => {
10195
if (property === 'baudRate' && this.connected) {
@@ -130,7 +124,7 @@ export class SerialConnectionManager {
130124
setConfig(newConfig: Partial<MonitorConfig>): void {
131125
let configHasChanged = false;
132126
Object.keys(this.config).forEach((key: keyof MonitorConfig) => {
133-
if (newConfig[key] && newConfig[key] !== this.config[key]) {
127+
if (newConfig[key] !== this.config[key]) {
134128
configHasChanged = true;
135129
this.config = { ...this.config, [key]: newConfig[key] };
136130
}
@@ -222,7 +216,6 @@ export class SerialConnectionManager {
222216
set connected(c: boolean) {
223217
this._connected = c;
224218
this.monitorService.updateWsConfigParam({ connected: c });
225-
226219
this.onConnectionChangedEmitter.fire(this._connected);
227220
}
228221
/**
@@ -365,28 +358,6 @@ export class SerialConnectionManager {
365358
}
366359
}
367360

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-
390361
async connect(): Promise<Status> {
391362
if (this.connected) return Status.ALREADY_CONNECTED;
392363
if (!isMonitorConfig(this.config)) {
@@ -467,21 +438,10 @@ export class SerialConnectionManager {
467438
protected async handleBoardConfigChange(
468439
boardsConfig: BoardsConfig.Config
469440
): 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);
485445
}
486446
}
487447

arduino-ide-extension/src/test/browser/serial-connection-manager.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
} from '../../browser/monitor/monitor-connection';
2323
import { ThemeService } from '@theia/core/lib/browser/theming';
2424
import { MonitorModel } from '../../browser/monitor/monitor-model';
25-
import { NotificationCenter } from '../../browser/notification-center';
2625
import {
2726
aBoardConfig,
2827
anotherBoardConfig,
@@ -50,7 +49,6 @@ describe.only('SerialConnectionManager', () => {
5049
let monitorServiceClient: IMock<MonitorServiceClient>;
5150
let boardsService: IMock<BoardsService>;
5251
let boardsServiceProvider: IMock<BoardsServiceProvider>;
53-
let notificationCenter: IMock<NotificationCenter>;
5452
let messageService: IMock<MessageService>;
5553
let themeService: IMock<ThemeService>;
5654

@@ -68,7 +66,6 @@ describe.only('SerialConnectionManager', () => {
6866
monitorServiceClient = Mock.ofType<MonitorServiceClient>();
6967
boardsService = Mock.ofType<BoardsService>();
7068
boardsServiceProvider = Mock.ofType<BoardsServiceProvider>();
71-
notificationCenter = Mock.ofType<NotificationCenter>();
7269
messageService = Mock.ofType<MessageService>();
7370
themeService = Mock.ofType<ThemeService>();
7471

@@ -112,7 +109,6 @@ describe.only('SerialConnectionManager', () => {
112109
monitorServiceClient.object,
113110
boardsService.object,
114111
boardsServiceProvider.object,
115-
notificationCenter.object,
116112
messageService.object,
117113
themeService.object
118114
);

0 commit comments

Comments
 (0)