mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-10 12:56:32 +00:00
Fix board options not shown for manually installed platforms (#826)
This commit is contained in:
parent
2f9bf86d75
commit
877c1a1559
@ -1,7 +1,6 @@
|
|||||||
import { injectable, inject, named } from 'inversify';
|
import { injectable, inject, named } from 'inversify';
|
||||||
import { ILogger } from '@theia/core/lib/common/logger';
|
import { ILogger } from '@theia/core/lib/common/logger';
|
||||||
import { deepClone } from '@theia/core/lib/common/objects';
|
import { deepClone } from '@theia/core/lib/common/objects';
|
||||||
import { MaybePromise } from '@theia/core/lib/common/types';
|
|
||||||
import { Event, Emitter } from '@theia/core/lib/common/event';
|
import { Event, Emitter } from '@theia/core/lib/common/event';
|
||||||
import {
|
import {
|
||||||
FrontendApplicationContribution,
|
FrontendApplicationContribution,
|
||||||
@ -11,7 +10,6 @@ import { notEmpty } from '../../common/utils';
|
|||||||
import {
|
import {
|
||||||
BoardsService,
|
BoardsService,
|
||||||
ConfigOption,
|
ConfigOption,
|
||||||
Installable,
|
|
||||||
BoardDetails,
|
BoardDetails,
|
||||||
Programmer,
|
Programmer,
|
||||||
} from '../../common/protocol';
|
} from '../../common/protocol';
|
||||||
@ -36,16 +34,12 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
|
|
||||||
onStart(): void {
|
onStart(): void {
|
||||||
this.notificationCenter.onPlatformInstalled(async ({ item }) => {
|
this.notificationCenter.onPlatformInstalled(async ({ item }) => {
|
||||||
const { installedVersion: version } = item;
|
|
||||||
if (!version) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let shouldFireChanged = false;
|
let shouldFireChanged = false;
|
||||||
for (const fqbn of item.boards
|
for (const fqbn of item.boards
|
||||||
.map(({ fqbn }) => fqbn)
|
.map(({ fqbn }) => fqbn)
|
||||||
.filter(notEmpty)
|
.filter(notEmpty)
|
||||||
.filter((fqbn) => !!fqbn)) {
|
.filter((fqbn) => !!fqbn)) {
|
||||||
const key = this.getStorageKey(fqbn, version);
|
const key = this.getStorageKey(fqbn);
|
||||||
let data = await this.storageService.getData<
|
let data = await this.storageService.getData<
|
||||||
ConfigOption[] | undefined
|
ConfigOption[] | undefined
|
||||||
>(key);
|
>(key);
|
||||||
@ -72,33 +66,20 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
|
|
||||||
async appendConfigToFqbn(
|
async appendConfigToFqbn(
|
||||||
fqbn: string | undefined,
|
fqbn: string | undefined,
|
||||||
boardsPackageVersion: MaybePromise<
|
|
||||||
Installable.Version | undefined
|
|
||||||
> = this.getBoardsPackageVersion(fqbn)
|
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
if (!fqbn) {
|
if (!fqbn) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
const { configOptions } = await this.getData(fqbn);
|
||||||
const { configOptions } = await this.getData(fqbn, boardsPackageVersion);
|
|
||||||
return ConfigOption.decorate(fqbn, configOptions);
|
return ConfigOption.decorate(fqbn, configOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getData(
|
async getData(fqbn: string | undefined): Promise<BoardsDataStore.Data> {
|
||||||
fqbn: string | undefined,
|
|
||||||
boardsPackageVersion: MaybePromise<
|
|
||||||
Installable.Version | undefined
|
|
||||||
> = this.getBoardsPackageVersion(fqbn)
|
|
||||||
): Promise<BoardsDataStore.Data> {
|
|
||||||
if (!fqbn) {
|
if (!fqbn) {
|
||||||
return BoardsDataStore.Data.EMPTY;
|
return BoardsDataStore.Data.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
const version = await boardsPackageVersion;
|
const key = this.getStorageKey(fqbn);
|
||||||
if (!version) {
|
|
||||||
return BoardsDataStore.Data.EMPTY;
|
|
||||||
}
|
|
||||||
const key = this.getStorageKey(fqbn, version);
|
|
||||||
let data = await this.storageService.getData<
|
let data = await this.storageService.getData<
|
||||||
BoardsDataStore.Data | undefined
|
BoardsDataStore.Data | undefined
|
||||||
>(key, undefined);
|
>(key, undefined);
|
||||||
@ -124,25 +105,16 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
fqbn,
|
fqbn,
|
||||||
selectedProgrammer,
|
selectedProgrammer,
|
||||||
}: { fqbn: string; selectedProgrammer: Programmer },
|
}: { fqbn: string; selectedProgrammer: Programmer },
|
||||||
boardsPackageVersion: MaybePromise<
|
|
||||||
Installable.Version | undefined
|
|
||||||
> = this.getBoardsPackageVersion(fqbn)
|
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
const data = deepClone(await this.getData(fqbn));
|
||||||
const { programmers } = data;
|
const { programmers } = data;
|
||||||
if (!programmers.find((p) => Programmer.equals(selectedProgrammer, p))) {
|
if (!programmers.find((p) => Programmer.equals(selectedProgrammer, p))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const version = await boardsPackageVersion;
|
|
||||||
if (!version) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.setData({
|
await this.setData({
|
||||||
fqbn,
|
fqbn,
|
||||||
data: { ...data, selectedProgrammer },
|
data: { ...data, selectedProgrammer },
|
||||||
version,
|
|
||||||
});
|
});
|
||||||
this.fireChanged();
|
this.fireChanged();
|
||||||
return true;
|
return true;
|
||||||
@ -153,12 +125,9 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
fqbn,
|
fqbn,
|
||||||
option,
|
option,
|
||||||
selectedValue,
|
selectedValue,
|
||||||
}: { fqbn: string; option: string; selectedValue: string },
|
}: { fqbn: string; option: string; selectedValue: string }
|
||||||
boardsPackageVersion: MaybePromise<
|
|
||||||
Installable.Version | undefined
|
|
||||||
> = this.getBoardsPackageVersion(fqbn)
|
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
const data = deepClone(await this.getData(fqbn));
|
||||||
const { configOptions } = data;
|
const { configOptions } = data;
|
||||||
const configOption = configOptions.find((c) => c.option === option);
|
const configOption = configOptions.find((c) => c.option === option);
|
||||||
if (!configOption) {
|
if (!configOption) {
|
||||||
@ -176,12 +145,7 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
if (!updated) {
|
if (!updated) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const version = await boardsPackageVersion;
|
await this.setData({ fqbn, data });
|
||||||
if (!version) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.setData({ fqbn, data, version });
|
|
||||||
this.fireChanged();
|
this.fireChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -189,18 +153,16 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
protected async setData({
|
protected async setData({
|
||||||
fqbn,
|
fqbn,
|
||||||
data,
|
data,
|
||||||
version,
|
|
||||||
}: {
|
}: {
|
||||||
fqbn: string;
|
fqbn: string;
|
||||||
data: BoardsDataStore.Data;
|
data: BoardsDataStore.Data;
|
||||||
version: Installable.Version;
|
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const key = this.getStorageKey(fqbn, version);
|
const key = this.getStorageKey(fqbn);
|
||||||
return this.storageService.setData(key, data);
|
return this.storageService.setData(key, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getStorageKey(fqbn: string, version: Installable.Version): string {
|
protected getStorageKey(fqbn: string): string {
|
||||||
return `.arduinoIDE-configOptions-${version}-${fqbn}`;
|
return `.arduinoIDE-configOptions-${fqbn}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getBoardDetailsSafe(
|
protected async getBoardDetailsSafe(
|
||||||
@ -231,21 +193,6 @@ export class BoardsDataStore implements FrontendApplicationContribution {
|
|||||||
protected fireChanged(): void {
|
protected fireChanged(): void {
|
||||||
this.onChangedEmitter.fire();
|
this.onChangedEmitter.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getBoardsPackageVersion(
|
|
||||||
fqbn: string | undefined
|
|
||||||
): Promise<Installable.Version | undefined> {
|
|
||||||
if (!fqbn) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
const boardsPackage = await this.boardsService.getContainerBoardPackage({
|
|
||||||
fqbn,
|
|
||||||
});
|
|
||||||
if (!boardsPackage) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return boardsPackage.installedVersion;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace BoardsDataStore {
|
export namespace BoardsDataStore {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user