mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-12-10 17:17:18 +00:00
slightly better reconnecting experience.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
@@ -47,8 +47,8 @@ export class MonitorConnection {
|
||||
break;
|
||||
}
|
||||
case MonitorError.ErrorCodes.DEVICE_NOT_CONFIGURED: {
|
||||
const { port } = config;
|
||||
this.messageService.info(`Disconnected from ${Port.toString(port)}.`);
|
||||
const { port, board } = config;
|
||||
this.messageService.info(`Disconnected ${Board.toString(board, { useFqbn: false })} from ${Port.toString(port)}.`);
|
||||
break;
|
||||
}
|
||||
case undefined: {
|
||||
@@ -77,19 +77,22 @@ export class MonitorConnection {
|
||||
|
||||
async connect(config: MonitorConfig): Promise<Status> {
|
||||
if (this.state) {
|
||||
throw new Error(`Already connected to ${MonitorConnection.State.toString(this.state)}.`);
|
||||
const disconnectStatus = await this.disconnect();
|
||||
if (!Status.isOK(disconnectStatus)) {
|
||||
return disconnectStatus;
|
||||
}
|
||||
}
|
||||
const status = await this.monitorService.connect(config);
|
||||
if (Status.isOK(status)) {
|
||||
const connectStatus = await this.monitorService.connect(config);
|
||||
if (Status.isOK(connectStatus)) {
|
||||
this.state = { config };
|
||||
this.onConnectionChangedEmitter.fire(true);
|
||||
}
|
||||
return Status.isOK(status);
|
||||
return Status.isOK(connectStatus);
|
||||
}
|
||||
|
||||
async disconnect(): Promise<Status> {
|
||||
if (!this.state) {
|
||||
throw new Error('Not connected. Nothing to disconnect.');
|
||||
return Status.OK;
|
||||
}
|
||||
console.log('>>> Disposing existing monitor connection before establishing a new one...');
|
||||
const status = await this.monitorService.disconnect();
|
||||
|
||||
@@ -9,7 +9,7 @@ import { MessageService } from '@theia/core/lib/common/message-service';
|
||||
import { ReactWidget, Message, Widget } from '@theia/core/lib/browser';
|
||||
import { MonitorServiceClientImpl } from './monitor-service-client-impl';
|
||||
import { MonitorConfig, MonitorService } from '../../common/protocol/monitor-service';
|
||||
import { AttachedSerialBoard, BoardsService } from '../../common/protocol/boards-service';
|
||||
import { AttachedSerialBoard, BoardsService, AttachedBoardsChangeEvent } from '../../common/protocol/boards-service';
|
||||
import { BoardsConfig } from '../boards/boards-config';
|
||||
import { BoardsServiceClientImpl } from '../boards/boards-service-client-impl';
|
||||
import { MonitorModel } from './monitor-model';
|
||||
@@ -171,16 +171,24 @@ export class MonitorWidget extends ReactWidget {
|
||||
}
|
||||
}),
|
||||
this.boardsServiceClient.onBoardsConfigChanged(config => {
|
||||
const { selectedBoard, selectedPort } = config;
|
||||
if (selectedBoard && selectedPort) {
|
||||
if (this.boardsServiceClient.canUploadTo(config)) {
|
||||
this.boardsService.getAttachedBoards().then(({ boards }) => {
|
||||
if (boards.filter(AttachedSerialBoard.is).some(board => BoardsConfig.Config.sameAs(config, board))) {
|
||||
this.clearConsole();
|
||||
this.connect();
|
||||
}
|
||||
});
|
||||
}
|
||||
})]);
|
||||
}),
|
||||
this.boardsServiceClient.onBoardsChanged(event => {
|
||||
const { attached } = AttachedBoardsChangeEvent.diff(event);
|
||||
if (!this.connection.connected && this.boardsServiceClient.canUploadTo()) {
|
||||
const { boardsConfig } = this.boardsServiceClient;
|
||||
if (attached.boards.filter(AttachedSerialBoard.is).some(board => BoardsConfig.Config.sameAs(boardsConfig, board))) {
|
||||
this.connect();
|
||||
}
|
||||
}
|
||||
})
|
||||
]);
|
||||
this.update();
|
||||
}
|
||||
|
||||
@@ -214,6 +222,7 @@ export class MonitorWidget extends ReactWidget {
|
||||
}
|
||||
|
||||
protected async connect(): Promise<void> {
|
||||
this.clearConsole();
|
||||
const config = await this.getConnectionConfig();
|
||||
if (config) {
|
||||
this.connection.connect(config);
|
||||
|
||||
Reference in New Issue
Block a user