From 877c1a15591d0568fa0908c07edf375ce11c3f97 Mon Sep 17 00:00:00 2001 From: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com> Date: Mon, 14 Feb 2022 10:12:18 +0100 Subject: [PATCH] Fix board options not shown for manually installed platforms (#826) --- .../src/browser/boards/boards-data-store.ts | 75 +++---------------- 1 file changed, 11 insertions(+), 64 deletions(-) diff --git a/arduino-ide-extension/src/browser/boards/boards-data-store.ts b/arduino-ide-extension/src/browser/boards/boards-data-store.ts index fea413eb0..d1a9de5d0 100644 --- a/arduino-ide-extension/src/browser/boards/boards-data-store.ts +++ b/arduino-ide-extension/src/browser/boards/boards-data-store.ts @@ -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, @@ -11,7 +10,6 @@ import { notEmpty } from '../../common/utils'; import { BoardsService, ConfigOption, - Installable, BoardDetails, Programmer, } from '../../common/protocol'; @@ -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); @@ -72,33 +66,20 @@ export class BoardsDataStore implements FrontendApplicationContribution { async appendConfigToFqbn( fqbn: string | undefined, - boardsPackageVersion: MaybePromise< - Installable.Version | undefined - > = this.getBoardsPackageVersion(fqbn) ): Promise { 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 { + async getData(fqbn: string | undefined): Promise { 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); @@ -124,25 +105,16 @@ export class BoardsDataStore implements FrontendApplicationContribution { fqbn, selectedProgrammer, }: { fqbn: string; selectedProgrammer: Programmer }, - boardsPackageVersion: MaybePromise< - Installable.Version | undefined - > = this.getBoardsPackageVersion(fqbn) ): Promise { - 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; @@ -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 { - 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) { @@ -176,12 +145,7 @@ 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; } @@ -189,18 +153,16 @@ export class BoardsDataStore implements FrontendApplicationContribution { protected async setData({ fqbn, data, - version, }: { fqbn: string; data: BoardsDataStore.Data; - version: Installable.Version; }): Promise { - 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( @@ -231,21 +193,6 @@ export class BoardsDataStore implements FrontendApplicationContribution { protected fireChanged(): void { this.onChangedEmitter.fire(); } - - protected async getBoardsPackageVersion( - fqbn: string | undefined - ): Promise { - if (!fqbn) { - return undefined; - } - const boardsPackage = await this.boardsService.getContainerBoardPackage({ - fqbn, - }); - if (!boardsPackage) { - return undefined; - } - return boardsPackage.installedVersion; - } } export namespace BoardsDataStore {