fix: use board+port at startup if it's restored (#2242)

- update status bar if board+port is restored,
 - refresh the debug toolbar if board+port is restored,
 - init `Include Library` if board+port is ready, and
 - init library examples if board+port is ready

Closes #2237
Closes #2239

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta 2023-10-05 14:41:14 +02:00 committed by GitHub
parent 8f4bcc83ec
commit 57975f8d91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 26 deletions

View File

@ -19,7 +19,7 @@ import {
SketchContribution, SketchContribution,
TabBarToolbarRegistry, TabBarToolbarRegistry,
} from './contribution'; } from './contribution';
import { MaybePromise, MenuModelRegistry, nls } from '@theia/core/lib/common'; import { MenuModelRegistry, nls } from '@theia/core/lib/common';
import { CurrentSketch } from '../sketches-service-client-impl'; import { CurrentSketch } from '../sketches-service-client-impl';
import { ArduinoMenus } from '../menu/arduino-menus'; import { ArduinoMenus } from '../menu/arduino-menus';
@ -99,8 +99,8 @@ export class Debug extends SketchContribution {
this.notificationCenter.onPlatformDidUninstall(() => this.refreshState()); this.notificationCenter.onPlatformDidUninstall(() => this.refreshState());
} }
override onReady(): MaybePromise<void> { override onReady(): void {
this.refreshState(); this.boardsServiceProvider.ready.then(() => this.refreshState());
} }
override registerCommands(registry: CommandRegistry): void { override registerCommands(registry: CommandRegistry): void {

View File

@ -300,8 +300,8 @@ export class LibraryExamples extends Examples {
this.notificationCenter.onLibraryDidUninstall(() => this.update()); this.notificationCenter.onLibraryDidUninstall(() => this.update());
} }
override async onReady(): Promise<void> { override onReady(): void {
this.update(); // no `await` this.boardsServiceProvider.ready.then(() => this.update());
} }
protected override handleBoardChanged(board: Board | undefined): void { protected override handleBoardChanged(board: Board | undefined): void {

View File

@ -2,7 +2,6 @@ import PQueue from 'p-queue';
import { inject, injectable } from '@theia/core/shared/inversify'; import { inject, injectable } from '@theia/core/shared/inversify';
import URI from '@theia/core/lib/common/uri'; import URI from '@theia/core/lib/common/uri';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
import { EditorManager } from '@theia/editor/lib/browser';
import { MenuModelRegistry, MenuPath } from '@theia/core/lib/common/menu'; import { MenuModelRegistry, MenuPath } from '@theia/core/lib/common/menu';
import { import {
Disposable, Disposable,
@ -22,28 +21,25 @@ import { CurrentSketch } from '../sketches-service-client-impl';
@injectable() @injectable()
export class IncludeLibrary extends SketchContribution { export class IncludeLibrary extends SketchContribution {
@inject(CommandRegistry) @inject(CommandRegistry)
protected readonly commandRegistry: CommandRegistry; private readonly commandRegistry: CommandRegistry;
@inject(MenuModelRegistry) @inject(MenuModelRegistry)
protected readonly menuRegistry: MenuModelRegistry; private readonly menuRegistry: MenuModelRegistry;
@inject(MainMenuManager) @inject(MainMenuManager)
protected readonly mainMenuManager: MainMenuManager; private readonly mainMenuManager: MainMenuManager;
@inject(EditorManager)
protected override readonly editorManager: EditorManager;
@inject(NotificationCenter) @inject(NotificationCenter)
protected readonly notificationCenter: NotificationCenter; private readonly notificationCenter: NotificationCenter;
@inject(BoardsServiceProvider) @inject(BoardsServiceProvider)
protected readonly boardsServiceProvider: BoardsServiceProvider; private readonly boardsServiceProvider: BoardsServiceProvider;
@inject(LibraryService) @inject(LibraryService)
protected readonly libraryService: LibraryService; private readonly libraryService: LibraryService;
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 }); private readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
protected readonly toDispose = new DisposableCollection(); private readonly toDispose = new DisposableCollection();
override onStart(): void { override onStart(): void {
this.boardsServiceProvider.onBoardsConfigDidChange(() => this.boardsServiceProvider.onBoardsConfigDidChange(() =>
@ -56,8 +52,8 @@ export class IncludeLibrary extends SketchContribution {
this.notificationCenter.onDidReinitialize(() => this.updateMenuActions()); this.notificationCenter.onDidReinitialize(() => this.updateMenuActions());
} }
override async onReady(): Promise<void> { override onReady(): void {
this.updateMenuActions(); this.boardsServiceProvider.ready.then(() => this.updateMenuActions());
} }
override registerMenus(registry: MenuModelRegistry): void { override registerMenus(registry: MenuModelRegistry): void {
@ -93,7 +89,7 @@ export class IncludeLibrary extends SketchContribution {
}); });
} }
protected async updateMenuActions(): Promise<void> { private async updateMenuActions(): Promise<void> {
return this.queue.add(async () => { return this.queue.add(async () => {
this.toDispose.dispose(); this.toDispose.dispose();
this.mainMenuManager.update(); this.mainMenuManager.update();
@ -139,7 +135,7 @@ export class IncludeLibrary extends SketchContribution {
}); });
} }
protected registerLibrary( private registerLibrary(
libraryOrPlaceholder: LibraryPackage | string, libraryOrPlaceholder: LibraryPackage | string,
menuPath: MenuPath menuPath: MenuPath
): Disposable { ): Disposable {
@ -172,7 +168,7 @@ export class IncludeLibrary extends SketchContribution {
); );
} }
protected async includeLibrary(library: LibraryPackage): Promise<void> { private async includeLibrary(library: LibraryPackage): Promise<void> {
const sketch = await this.sketchServiceClient.currentSketch(); const sketch = await this.sketchServiceClient.currentSketch();
if (!CurrentSketch.isValid(sketch)) { if (!CurrentSketch.isValid(sketch)) {
return; return;

View File

@ -19,16 +19,18 @@ export class SelectedBoard extends Contribution {
private readonly boardsServiceProvider: BoardsServiceProvider; private readonly boardsServiceProvider: BoardsServiceProvider;
override onStart(): void { override onStart(): void {
this.boardsServiceProvider.onBoardListDidChange(() => this.boardsServiceProvider.onBoardListDidChange((boardList) =>
this.update(this.boardsServiceProvider.boardList) this.update(boardList)
); );
} }
override onReady(): void { override onReady(): void {
this.update(this.boardsServiceProvider.boardList); this.boardsServiceProvider.ready.then(() => this.update());
} }
private update(boardList: BoardList): void { private update(
boardList: BoardList = this.boardsServiceProvider.boardList
): void {
const { selectedBoard, selectedPort } = boardList.boardsConfig; const { selectedBoard, selectedPort } = boardList.boardsConfig;
this.statusBar.setElement('arduino-selected-board', { this.statusBar.setElement('arduino-selected-board', {
alignment: StatusBarAlignment.RIGHT, alignment: StatusBarAlignment.RIGHT,