Skip to content

Commit

Permalink
Fix board options not shown for manually installed platforms (arduino…
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza authored Feb 14, 2022
1 parent 2f9bf86 commit 877c1a1
Showing 1 changed file with 11 additions and 64 deletions.
75 changes: 11 additions & 64 deletions arduino-ide-extension/src/browser/boards/boards-data-store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { injectable, inject, named } from 'inversify';
import { ILogger } from '@theia/core/lib/common/logger';
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 {
FrontendApplicationContribution,
Expand All @@ -11,7 +10,6 @@ import { notEmpty } from '../../common/utils';
import {
BoardsService,
ConfigOption,
Installable,
BoardDetails,
Programmer,
} from '../../common/protocol';
Expand All @@ -36,16 +34,12 @@ export class BoardsDataStore implements FrontendApplicationContribution {

onStart(): void {
this.notificationCenter.onPlatformInstalled(async ({ item }) => {
const { installedVersion: version } = item;
if (!version) {
return;
}
let shouldFireChanged = false;
for (const fqbn of item.boards
.map(({ fqbn }) => fqbn)
.filter(notEmpty)
.filter((fqbn) => !!fqbn)) {
const key = this.getStorageKey(fqbn, version);
const key = this.getStorageKey(fqbn);
let data = await this.storageService.getData<
ConfigOption[] | undefined
>(key);
Expand All @@ -72,33 +66,20 @@ export class BoardsDataStore implements FrontendApplicationContribution {

async appendConfigToFqbn(
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);
const { configOptions } = await this.getData(fqbn);
return ConfigOption.decorate(fqbn, configOptions);
}

async getData(
fqbn: string | undefined,
boardsPackageVersion: MaybePromise<
Installable.Version | undefined
> = this.getBoardsPackageVersion(fqbn)
): Promise<BoardsDataStore.Data> {
async getData(fqbn: string | undefined): Promise<BoardsDataStore.Data> {
if (!fqbn) {
return BoardsDataStore.Data.EMPTY;
}

const version = await boardsPackageVersion;
if (!version) {
return BoardsDataStore.Data.EMPTY;
}
const key = this.getStorageKey(fqbn, version);
const key = this.getStorageKey(fqbn);
let data = await this.storageService.getData<
BoardsDataStore.Data | undefined
>(key, undefined);
Expand All @@ -124,25 +105,16 @@ export class BoardsDataStore implements FrontendApplicationContribution {
fqbn,
selectedProgrammer,
}: { fqbn: string; selectedProgrammer: Programmer },
boardsPackageVersion: MaybePromise<
Installable.Version | undefined
> = this.getBoardsPackageVersion(fqbn)
): Promise<boolean> {
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
const data = deepClone(await this.getData(fqbn));
const { programmers } = data;
if (!programmers.find((p) => Programmer.equals(selectedProgrammer, p))) {
return false;
}

const version = await boardsPackageVersion;
if (!version) {
return false;
}

await this.setData({
fqbn,
data: { ...data, selectedProgrammer },
version,
});
this.fireChanged();
return true;
Expand All @@ -153,12 +125,9 @@ export class BoardsDataStore implements FrontendApplicationContribution {
fqbn,
option,
selectedValue,
}: { fqbn: string; option: string; selectedValue: string },
boardsPackageVersion: MaybePromise<
Installable.Version | undefined
> = this.getBoardsPackageVersion(fqbn)
}: { fqbn: string; option: string; selectedValue: string }
): Promise<boolean> {
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
const data = deepClone(await this.getData(fqbn));
const { configOptions } = data;
const configOption = configOptions.find((c) => c.option === option);
if (!configOption) {
Expand All @@ -176,31 +145,24 @@ export class BoardsDataStore implements FrontendApplicationContribution {
if (!updated) {
return false;
}
const version = await boardsPackageVersion;
if (!version) {
return false;
}

await this.setData({ fqbn, data, version });
await this.setData({ fqbn, data });
this.fireChanged();
return true;
}

protected async setData({
fqbn,
data,
version,
}: {
fqbn: string;
data: BoardsDataStore.Data;
version: Installable.Version;
}): Promise<void> {
const key = this.getStorageKey(fqbn, version);
const key = this.getStorageKey(fqbn);
return this.storageService.setData(key, data);
}

protected getStorageKey(fqbn: string, version: Installable.Version): string {
return `.arduinoIDE-configOptions-${version}-${fqbn}`;
protected getStorageKey(fqbn: string): string {
return `.arduinoIDE-configOptions-${fqbn}`;
}

protected async getBoardDetailsSafe(
Expand Down Expand Up @@ -231,21 +193,6 @@ export class BoardsDataStore implements FrontendApplicationContribution {
protected fireChanged(): void {
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 {
Expand Down

0 comments on commit 877c1a1

Please sign in to comment.