mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-14 04:39:28 +00:00
@@ -0,0 +1,22 @@
|
||||
import { injectable, inject } from "inversify";
|
||||
import { BoardsService, Board } from "../../common/protocol/boards-service";
|
||||
|
||||
@injectable()
|
||||
export class BoardFrontendService {
|
||||
@inject(BoardsService) protected readonly boardService: BoardsService;
|
||||
|
||||
protected attachedBoards: Board[];
|
||||
|
||||
async getAttachedBoards(): Promise<Board[]> {
|
||||
if (this.attachedBoards) {
|
||||
return this.attachedBoards;
|
||||
}
|
||||
await this.refreshAttachedBoards();
|
||||
return this.attachedBoards;
|
||||
}
|
||||
|
||||
async refreshAttachedBoards(): Promise<void> {
|
||||
const { boards } = await this.boardService.getAttachedBoards();
|
||||
this.attachedBoards = boards;
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,14 @@ import { BoardsService, Board } from '../../common/protocol/boards-service';
|
||||
import { ContextMenuRenderer } from '@theia/core/lib/browser';
|
||||
import { ArduinoToolbarContextMenu } from '../arduino-file-menu';
|
||||
import { BoardsNotificationService } from '../boards-notification-service';
|
||||
import { BoardFrontendService } from './board-frontend-service';
|
||||
|
||||
export namespace BoardsToolBarItem {
|
||||
export interface Props {
|
||||
readonly contextMenuRenderer: ContextMenuRenderer;
|
||||
readonly boardsNotificationService: BoardsNotificationService;
|
||||
readonly boardService: BoardsService;
|
||||
readonly boardFrontendService: BoardFrontendService;
|
||||
}
|
||||
|
||||
export interface State {
|
||||
@@ -35,9 +37,9 @@ export class BoardsToolBarItem extends React.Component<BoardsToolBarItem.Props,
|
||||
}
|
||||
|
||||
protected async setAttachedBoards() {
|
||||
const { boards } = await this.props.boardService.getAttachedBoards();
|
||||
const boards = await this.props.boardFrontendService.getAttachedBoards();
|
||||
this.attachedBoards = boards;
|
||||
if(this.attachedBoards.length){
|
||||
if (this.attachedBoards.length) {
|
||||
await this.props.boardService.selectBoard(this.attachedBoards[0]);
|
||||
this.setSelectedBoard(this.attachedBoards[0]);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { injectable, inject } from 'inversify';
|
||||
import { BoardsService, Board, BoardPackage, AttachedSerialBoard } from '../../common/protocol/boards-service';
|
||||
import { BoardsNotificationService } from '../boards-notification-service';
|
||||
import { Emitter, Event } from '@theia/core';
|
||||
import { BoardFrontendService } from './board-frontend-service';
|
||||
|
||||
export interface BoardAndPortSelection {
|
||||
board?: Board;
|
||||
@@ -93,6 +94,7 @@ export class BoardAndPortSelectionList extends React.Component<BoardAndPortSelec
|
||||
export namespace BoardAndPortSelectionComponent {
|
||||
export interface Props {
|
||||
boardsService: BoardsService;
|
||||
boardFrontendService: BoardFrontendService;
|
||||
onSelect: (selection: BoardAndPortSelection) => void;
|
||||
}
|
||||
|
||||
@@ -131,7 +133,7 @@ export class BoardAndPortSelectionComponent extends React.Component<BoardAndPort
|
||||
if (this.portListComponent) {
|
||||
this.portListComponent.reset();
|
||||
}
|
||||
this.setState({selection: {}});
|
||||
this.setState({ selection: {} });
|
||||
}
|
||||
|
||||
render(): React.ReactNode {
|
||||
@@ -207,8 +209,8 @@ export class BoardAndPortSelectionComponent extends React.Component<BoardAndPort
|
||||
|
||||
protected async setPorts() {
|
||||
const ports: string[] = [];
|
||||
const attached = await this.props.boardsService.getAttachedBoards();
|
||||
attached.boards.forEach(board => {
|
||||
const boards = await this.props.boardFrontendService.getAttachedBoards();
|
||||
boards.forEach(board => {
|
||||
if (AttachedSerialBoard.is(board)) {
|
||||
ports.push(board.port);
|
||||
}
|
||||
@@ -222,6 +224,8 @@ export class SelectBoardDialogWidget extends ReactWidget {
|
||||
|
||||
@inject(BoardsService)
|
||||
protected readonly boardsService: BoardsService;
|
||||
@inject(BoardFrontendService)
|
||||
protected readonly boardFrontendService: BoardFrontendService;
|
||||
@inject(BoardsNotificationService)
|
||||
protected readonly boardsNotificationService: BoardsNotificationService;
|
||||
|
||||
@@ -279,7 +283,11 @@ export class SelectBoardDialogWidget extends ReactWidget {
|
||||
<p>but not to upload your sketch.</p>
|
||||
</div>
|
||||
</div>
|
||||
<BoardAndPortSelectionComponent ref={ref => this.boardAndPortSelectionComponent = ref} boardsService={boardsService} onSelect={this.onSelect} />
|
||||
<BoardAndPortSelectionComponent
|
||||
ref={ref => this.boardAndPortSelectionComponent = ref}
|
||||
boardFrontendService={this.boardFrontendService}
|
||||
boardsService={boardsService}
|
||||
onSelect={this.onSelect} />
|
||||
</div>
|
||||
</React.Fragment>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user