ATL-530: No checks before upload/verify/burn

Made the port/fqbn/programmer optional for upload, verify,
and burn bootloader. From now on, the IDE does not warn the user before
performing the desired CLI command.

Closes arduino/arduino-pro-ide#364

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2020-11-05 09:16:49 +01:00
committed by Akos Kitta
parent acbb7d32b2
commit 2831acc5b5
8 changed files with 87 additions and 116 deletions

View File

@@ -58,17 +58,25 @@ export class BoardsDataStore implements FrontendApplicationContribution {
}
async appendConfigToFqbn(
fqbn: string,
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<string> {
fqbn: string | undefined,
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<string | undefined> {
if (!fqbn) {
return undefined;
}
const { configOptions } = await this.getData(fqbn, boardsPackageVersion);
return ConfigOption.decorate(fqbn, configOptions);
}
async getData(
fqbn: string,
fqbn: string | undefined,
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<BoardsDataStore.Data> {
if (!fqbn) {
return BoardsDataStore.Data.EMPTY;
}
const version = await boardsPackageVersion;
if (!version) {
return BoardsDataStore.Data.EMPTY;
@@ -76,10 +84,7 @@ export class BoardsDataStore implements FrontendApplicationContribution {
const key = this.getStorageKey(fqbn, version);
let data = await this.storageService.getData<BoardsDataStore.Data | undefined>(key, undefined);
if (data) {
// If `configOptions` is empty we rather reload the data. See arduino/arduino-cli#954 and arduino/arduino-cli#955.
if (data.configOptions.length && data.programmers !== undefined) { // to be backward compatible. We did not save the `programmers` into the `localStorage`.
return data;
}
return data;
}
const boardDetails = await this.getBoardDetailsSafe(fqbn);
@@ -173,7 +178,7 @@ export class BoardsDataStore implements FrontendApplicationContribution {
this.onChangedEmitter.fire();
}
protected async getBoardsPackageVersion(fqbn: string): Promise<Installable.Version | undefined> {
protected async getBoardsPackageVersion(fqbn: string | undefined): Promise<Installable.Version | undefined> {
if (!fqbn) {
return undefined;
}

View File

@@ -46,27 +46,11 @@ export class BurnBootloader extends SketchContribution {
}
try {
const { boardsConfig } = this.boardsServiceClientImpl;
if (!boardsConfig || !boardsConfig.selectedBoard) {
throw new Error('No boards selected. Please select a board.');
}
if (!boardsConfig.selectedBoard.fqbn) {
throw new Error(`No core is installed for the '${boardsConfig.selectedBoard.name}' board. Please install the core.`);
}
const { selectedPort } = boardsConfig;
if (!selectedPort) {
throw new Error('No ports selected. Please select a port.');
}
const port = selectedPort.address;
const port = boardsConfig.selectedPort?.address;
const [fqbn, { selectedProgrammer: programmer }] = await Promise.all([
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn),
this.boardsDataStore.getData(boardsConfig.selectedBoard.fqbn)
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard?.fqbn),
this.boardsDataStore.getData(boardsConfig.selectedBoard?.fqbn)
]);
if (!programmer) {
throw new Error('Programmer is not selected. Please select a programmer from the `Tools` > `Programmer` menu.');
}
this.outputChannelManager.getChannel('Arduino: bootloader').clear();
await this.coreService.burnBootloader({
fqbn,

View File

@@ -83,34 +83,19 @@ export class UploadSketch extends SketchContribution {
}
try {
const { boardsConfig } = this.boardsServiceClientImpl;
if (!boardsConfig || !boardsConfig.selectedBoard) {
throw new Error('No boards selected. Please select a board.');
}
if (!boardsConfig.selectedBoard.fqbn) {
throw new Error(`No core is installed for the '${boardsConfig.selectedBoard.name}' board. Please install the core.`);
}
const [fqbn, { selectedProgrammer }] = await Promise.all([
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn),
this.boardsDataStore.getData(boardsConfig.selectedBoard.fqbn)
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard?.fqbn),
this.boardsDataStore.getData(boardsConfig.selectedBoard?.fqbn)
]);
let options: CoreService.Upload.Options | undefined = undefined;
const sketchUri = uri;
const optimizeForDebug = this.editorMode.compileForDebug;
const { selectedPort } = boardsConfig;
const port = selectedPort?.address;
if (usingProgrammer) {
const programmer = selectedProgrammer;
if (!programmer) {
throw new Error('Programmer is not selected. Please select a programmer from the `Tools` > `Programmer` menu.');
}
let port: undefined | string = undefined;
// If the port is set by the user, we pass it to the CLI as it might be required.
// If it is not set but the CLI requires it, we let the CLI to complain.
if (selectedPort) {
port = selectedPort.address;
}
options = {
sketchUri,
fqbn,
@@ -119,10 +104,6 @@ export class UploadSketch extends SketchContribution {
port
};
} else {
if (!selectedPort) {
throw new Error('No ports selected. Please select a port.');
}
const port = selectedPort.address;
options = {
sketchUri,
fqbn,
@@ -131,7 +112,11 @@ export class UploadSketch extends SketchContribution {
};
}
this.outputChannelManager.getChannel('Arduino: upload').clear();
await this.coreService.upload(options);
if (usingProgrammer) {
await this.coreService.uploadUsingProgrammer(options);
} else {
await this.coreService.upload(options);
}
this.messageService.info('Done uploading.', { timeout: 1000 });
} catch (e) {
this.messageService.error(e.toString());

View File

@@ -63,13 +63,7 @@ export class VerifySketch extends SketchContribution {
}
try {
const { boardsConfig } = this.boardsServiceClientImpl;
if (!boardsConfig || !boardsConfig.selectedBoard) {
throw new Error('No boards selected. Please select a board.');
}
if (!boardsConfig.selectedBoard.fqbn) {
throw new Error(`No core is installed for the '${boardsConfig.selectedBoard.name}' board. Please install the core.`);
}
const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn);
const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard?.fqbn);
this.outputChannelManager.getChannel('Arduino: compile').clear();
await this.coreService.compile({
sketchUri: uri,

View File

@@ -1,6 +1,6 @@
import { inject, injectable } from 'inversify';
import { OutputContribution } from '@theia/output/lib/browser/output-contribution';
import { OutputChannelManager, OutputChannelSeverity } from '@theia/output/lib/common/output-channel';
import { OutputChannelManager } from '@theia/output/lib/common/output-channel';
import { OutputService, OutputMessage } from '../common/protocol/output-service';
@injectable()
@@ -22,19 +22,7 @@ export class OutputServiceImpl implements OutputService {
// This will open, reveal but do not activate the Output view.
: Promise.resolve(channel.show({ preserveFocus: true }));
show.then(() => channel.append(chunk, this.toOutputSeverity(message)));
}
protected toOutputSeverity(message: OutputMessage): OutputChannelSeverity {
if (message.severity) {
switch (message.severity) {
case 'error': return OutputChannelSeverity.Error
case 'warning': return OutputChannelSeverity.Warning
case 'info': return OutputChannelSeverity.Info
default: return OutputChannelSeverity.Info
}
}
return OutputChannelSeverity.Info
show.then(() => channel.append(chunk));
}
}