diff --git a/arduino-ide-extension/src/browser/arduino-file-menu.ts b/arduino-ide-extension/src/browser/arduino-file-menu.ts index a33dd454..30598267 100644 --- a/arduino-ide-extension/src/browser/arduino-file-menu.ts +++ b/arduino-ide-extension/src/browser/arduino-file-menu.ts @@ -5,6 +5,7 @@ import { ArduinoCommands } from "./arduino-commands"; import { SketchesService, Sketch } from "../common/protocol/sketches-service"; import { AWorkspaceService } from "./arduino-workspace-service"; import { BoardsService, Board, AttachedSerialBoard, AttachedNetworkBoard } from "../common/protocol/boards-service"; +import { BoardFrontendService } from "./boards/board-frontend-service"; export namespace ArduinoToolbarContextMenu { export const OPEN_SKETCH_PATH: MenuPath = ['arduino-open-sketch-context-menu']; @@ -29,6 +30,9 @@ export class ArduinoToolbarMenuContribution implements MenuContribution { @inject(BoardsService) protected readonly boardsService: BoardsService; + @inject(BoardFrontendService) + protected readonly boardFrontendService: BoardFrontendService; + constructor( @inject(AWorkspaceService) protected readonly workspaceService: AWorkspaceService, @inject(MenuModelRegistry) protected readonly menuRegistry: MenuModelRegistry) { @@ -41,7 +45,7 @@ export class ArduinoToolbarMenuContribution implements MenuContribution { } protected async registerConnectedBoardsInMenu(registry: MenuModelRegistry) { - const { boards } = await this.boardsService.getAttachedBoards(); + const boards = await this.boardFrontendService.getAttachedBoards(); const selectedBoard = await this.boardsService.getSelectBoard(); const selectedPort = selectedBoard ? this.getPort(selectedBoard) : ''; boards.forEach(board => { diff --git a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx index 0d228020..0dd0f38e 100644 --- a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx +++ b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx @@ -29,6 +29,7 @@ import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution' import { BoardsToolBarItem } from './boards/boards-toolbar-item'; import { SelectBoardsDialog } from './boards/select-board-dialog'; +import { BoardFrontendService } from './boards/board-frontend-service'; @injectable() export class ArduinoFrontendContribution implements TabBarToolbarContribution, CommandContribution { @@ -39,6 +40,9 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C @inject(BoardsService) protected readonly boardService: BoardsService; + @inject(BoardFrontendService) + protected readonly boardFrontendService: BoardFrontendService; + @inject(CoreService) protected readonly coreService: CoreService; @@ -129,6 +133,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C ref={ref => this.boardsToolbarItem = ref} contextMenuRenderer={this.contextMenuRenderer} boardsNotificationService={this.boardsNotificationService} + boardFrontendService={this.boardFrontendService} boardService={this.boardService} />, isVisible: widget => this.isArduinoToolbar(widget) }) @@ -248,9 +253,9 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C } protected async selectBoard(board: Board) { - const attached = await this.boardService.getAttachedBoards(); - if(attached.boards.length) { - board = attached.boards.find(b => b.name === board.name && b.fqbn === board.fqbn) || board; + const boards = await this.boardFrontendService.getAttachedBoards(); + if (boards.length) { + board = boards.find(b => b.name === board.name && b.fqbn === board.fqbn) || board; } await this.boardService.selectBoard(board) if (this.boardsToolbarItem) { diff --git a/arduino-ide-extension/src/browser/arduino-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-frontend-module.ts index 7cec9282..dc7317d8 100644 --- a/arduino-ide-extension/src/browser/arduino-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-frontend-module.ts @@ -50,6 +50,7 @@ import { EditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-fac import { CustomEditorWidgetFactory } from './customization/custom-editor-widget-factory'; import { SelectBoardsDialog, SelectBoardsDialogProps } from './boards/select-board-dialog'; import { SelectBoardDialogWidget } from './boards/select-board-dialog-widget'; +import { BoardFrontendService } from './boards/board-frontend-service'; export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => { // Commands and toolbar items @@ -86,6 +87,7 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un // Boards service bind(BoardsService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, BoardsServicePath)).inSingletonScope(); + bind(BoardFrontendService).toSelf().inSingletonScope(); // Boards list widget bind(BoardsListWidget).toSelf(); diff --git a/arduino-ide-extension/src/browser/boards/board-frontend-service.ts b/arduino-ide-extension/src/browser/boards/board-frontend-service.ts new file mode 100644 index 00000000..edacf39c --- /dev/null +++ b/arduino-ide-extension/src/browser/boards/board-frontend-service.ts @@ -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 { + if (this.attachedBoards) { + return this.attachedBoards; + } + await this.refreshAttachedBoards(); + return this.attachedBoards; + } + + async refreshAttachedBoards(): Promise { + const { boards } = await this.boardService.getAttachedBoards(); + this.attachedBoards = boards; + } +} \ No newline at end of file diff --git a/arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx b/arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx index 859410d0..01c8e9eb 100644 --- a/arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx +++ b/arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx @@ -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 void; } @@ -131,7 +133,7 @@ export class BoardAndPortSelectionComponent extends React.Component { + 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 {

but not to upload your sketch.

- this.boardAndPortSelectionComponent = ref} boardsService={boardsService} onSelect={this.onSelect} /> + this.boardAndPortSelectionComponent = ref} + boardFrontendService={this.boardFrontendService} + boardsService={boardsService} + onSelect={this.onSelect} />