queued the menu updates.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-08-04 15:07:16 +02:00
parent f0015e3fb4
commit 3806d56e94

View File

@ -1,3 +1,4 @@
import * as PQueue from 'p-queue';
import { inject, injectable } from 'inversify'; import { inject, injectable } from 'inversify';
import { CommandRegistry } from '@theia/core/lib/common/command'; import { CommandRegistry } from '@theia/core/lib/common/command';
import { MenuModelRegistry, MenuNode } from '@theia/core/lib/common/menu'; import { MenuModelRegistry, MenuNode } from '@theia/core/lib/common/menu';
@ -27,18 +28,20 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
@inject(BoardsServiceClientImpl) @inject(BoardsServiceClientImpl)
protected readonly boardsServiceClient: BoardsServiceClientImpl; protected readonly boardsServiceClient: BoardsServiceClientImpl;
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
protected readonly toDisposeOnBoardChange = new DisposableCollection(); protected readonly toDisposeOnBoardChange = new DisposableCollection();
async onStart(): Promise<void> { async onStart(): Promise<void> {
await this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard); this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard);
this.boardsDataStore.onChanged(async () => await this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard)); this.boardsDataStore.onChanged(() => this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard));
this.boardsServiceClient.onBoardsConfigChanged(async ({ selectedBoard }) => await this.updateMenuActions(selectedBoard)); this.boardsServiceClient.onBoardsConfigChanged(({ selectedBoard }) => this.updateMenuActions(selectedBoard));
} }
protected async updateMenuActions(selectedBoard: Board | undefined): Promise<void> { protected async updateMenuActions(selectedBoard: Board | undefined): Promise<void> {
if (selectedBoard) { return this.queue.add(async () => {
this.toDisposeOnBoardChange.dispose(); this.toDisposeOnBoardChange.dispose();
this.mainMenuManager.update(); this.mainMenuManager.update();
if (selectedBoard) {
const { fqbn } = selectedBoard; const { fqbn } = selectedBoard;
if (fqbn) { if (fqbn) {
const { configOptions, programmers, selectedProgrammer } = await this.boardsDataStore.getData(fqbn); const { configOptions, programmers, selectedProgrammer } = await this.boardsDataStore.getData(fqbn);
@ -92,6 +95,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
this.mainMenuManager.update(); this.mainMenuManager.update();
} }
} }
});
} }
protected unregisterSubmenu(menuPath: string[]): void { protected unregisterSubmenu(menuPath: string[]): void {