From 83980b3337fc701a179aea26b7a3b9dbf1f35427 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Thu, 21 Sep 2023 15:32:36 +0200 Subject: [PATCH] fix: refresh the user-fields at app startup Ref: arduino/arduino-ide#2165 Closes arduino/arduino-ide#2230 Signed-off-by: Akos Kitta --- .../src/browser/contributions/user-fields.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/user-fields.ts b/arduino-ide-extension/src/browser/contributions/user-fields.ts index 14a4e55a8..00f2817c6 100644 --- a/arduino-ide-extension/src/browser/contributions/user-fields.ts +++ b/arduino-ide-extension/src/browser/contributions/user-fields.ts @@ -1,10 +1,10 @@ +import { nls } from '@theia/core/lib/common/nls'; import { inject, injectable } from '@theia/core/shared/inversify'; -import { nls } from '@theia/core/lib/common'; import { BoardUserField, CoreError } from '../../common/protocol'; import { BoardsServiceProvider } from '../boards/boards-service-provider'; import { UserFieldsDialog } from '../dialogs/user-fields/user-fields-dialog'; import { ArduinoMenus } from '../menu/arduino-menus'; -import { MenuModelRegistry, Contribution } from './contribution'; +import { Contribution, MenuModelRegistry } from './contribution'; import { UploadSketch } from './upload-sketch'; @injectable() @@ -21,12 +21,11 @@ export class UserFields extends Contribution { protected override init(): void { super.init(); - this.boardsServiceProvider.onBoardsConfigDidChange(async () => { - const userFields = - await this.boardsServiceProvider.selectedBoardUserFields(); - this.boardRequiresUserFields = userFields.length > 0; - this.menuManager.update(); - }); + this.boardsServiceProvider.onBoardsConfigDidChange(() => this.refresh()); + } + + override onReady(): void { + this.boardsServiceProvider.ready.then(() => this.refresh()); } override registerMenus(registry: MenuModelRegistry): void { @@ -37,6 +36,13 @@ export class UserFields extends Contribution { }); } + private async refresh(): Promise { + const userFields = + await this.boardsServiceProvider.selectedBoardUserFields(); + this.boardRequiresUserFields = userFields.length > 0; + this.menuManager.update(); + } + private selectedFqbnAddress(): string | undefined { const { boardsConfig } = this.boardsServiceProvider; const fqbn = boardsConfig.selectedBoard?.fqbn;