#1089: IDE2 falls back to new sketch if opening failed. (#1152)

IDE2 falls back to a new sketch if the opening fails.

Closes #1089

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta
2022-07-18 11:10:33 +02:00
committed by GitHub
parent fe31d15b9f
commit 8ad10b5adf
35 changed files with 881 additions and 659 deletions

View File

@@ -17,10 +17,10 @@ import {
import { BoardsConfig } from './boards-config';
import { naturalCompare } from '../../common/utils';
import { NotificationCenter } from '../notification-center';
import { ArduinoCommands } from '../arduino-commands';
import { StorageWrapper } from '../storage-wrapper';
import { nls } from '@theia/core/lib/common';
import { Deferred } from '@theia/core/lib/common/promise-util';
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
@injectable()
export class BoardsServiceProvider implements FrontendApplicationContribution {
@@ -39,6 +39,9 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
@inject(NotificationCenter)
protected notificationCenter: NotificationCenter;
@inject(FrontendApplicationStateService)
private readonly appStateService: FrontendApplicationStateService;
protected readonly onBoardsConfigChangedEmitter =
new Emitter<BoardsConfig.Config>();
protected readonly onAvailableBoardsChangedEmitter = new Emitter<
@@ -87,11 +90,12 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
this.notifyPlatformUninstalled.bind(this)
);
Promise.all([
this.boardsService.getAttachedBoards(),
this.boardsService.getAvailablePorts(),
this.loadState(),
]).then(async ([attachedBoards, availablePorts]) => {
this.appStateService.reachedState('ready').then(async () => {
const [attachedBoards, availablePorts] = await Promise.all([
this.boardsService.getAttachedBoards(),
this.boardsService.getAvailablePorts(),
this.loadState(),
]);
this._attachedBoards = attachedBoards;
this._availablePorts = availablePorts;
this.onAvailablePortsChangedEmitter.fire(this._availablePorts);
@@ -166,7 +170,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
.then(async (answer) => {
if (answer === yes) {
this.commandService.executeCommand(
ArduinoCommands.OPEN_BOARDS_DIALOG.id,
'arduino-open-boards-dialog',
selectedBoard.name
);
}

View File

@@ -3,7 +3,7 @@ import * as ReactDOM from '@theia/core/shared/react-dom';
import { CommandRegistry } from '@theia/core/lib/common/command';
import { DisposableCollection } from '@theia/core/lib/common/disposable';
import { Port } from '../../common/protocol';
import { ArduinoCommands } from '../arduino-commands';
import { OpenBoardsConfig } from '../contributions/open-boards-config';
import {
BoardsServiceProvider,
AvailableBoard,
@@ -155,7 +155,7 @@ export class BoardsToolBarItem extends React.Component<
constructor(props: BoardsToolBarItem.Props) {
super(props);
const { availableBoards } = props.boardsServiceClient;
const { availableBoards } = props.boardsServiceProvider;
this.state = {
availableBoards,
coords: 'hidden',
@@ -167,8 +167,8 @@ export class BoardsToolBarItem extends React.Component<
}
override componentDidMount(): void {
this.props.boardsServiceClient.onAvailableBoardsChanged((availableBoards) =>
this.setState({ availableBoards })
this.props.boardsServiceProvider.onAvailableBoardsChanged(
(availableBoards) => this.setState({ availableBoards })
);
}
@@ -176,7 +176,7 @@ export class BoardsToolBarItem extends React.Component<
this.toDispose.dispose();
}
protected readonly show = (event: React.MouseEvent<HTMLElement>) => {
protected readonly show = (event: React.MouseEvent<HTMLElement>): void => {
const { currentTarget: element } = event;
if (element instanceof HTMLElement) {
if (this.state.coords === 'hidden') {
@@ -212,7 +212,7 @@ export class BoardsToolBarItem extends React.Component<
const protocolIcon = isConnected
? iconNameFromProtocol(selectedBoard?.port?.protocol || '')
: null;
const procolIconClassNames = classNames(
const protocolIconClassNames = classNames(
'arduino-boards-toolbar-item--protocol',
'fa',
protocolIcon
@@ -225,7 +225,7 @@ export class BoardsToolBarItem extends React.Component<
title={selectedPortLabel}
onClick={this.show}
>
{protocolIcon && <div className={procolIconClassNames} />}
{protocolIcon && <div className={protocolIconClassNames} />}
<div
className={classNames(
'arduino-boards-toolbar-item--label',
@@ -245,12 +245,12 @@ export class BoardsToolBarItem extends React.Component<
...board,
onClick: () => {
if (board.state === AvailableBoard.State.incomplete) {
this.props.boardsServiceClient.boardsConfig = {
this.props.boardsServiceProvider.boardsConfig = {
selectedPort: board.port,
};
this.openDialog();
} else {
this.props.boardsServiceClient.boardsConfig = {
this.props.boardsServiceProvider.boardsConfig = {
selectedBoard: board,
selectedPort: board.port,
};
@@ -264,13 +264,15 @@ export class BoardsToolBarItem extends React.Component<
);
}
protected openDialog = () => {
this.props.commands.executeCommand(ArduinoCommands.OPEN_BOARDS_DIALOG.id);
protected openDialog = (): void => {
this.props.commands.executeCommand(
OpenBoardsConfig.Commands.OPEN_DIALOG.id
);
};
}
export namespace BoardsToolBarItem {
export interface Props {
readonly boardsServiceClient: BoardsServiceProvider;
readonly boardsServiceProvider: BoardsServiceProvider;
readonly commands: CommandRegistry;
}