Skip to content

Commit 57975f8

Browse files
authored
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 <[email protected]>
1 parent 8f4bcc8 commit 57975f8

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/debug.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
SketchContribution,
2020
TabBarToolbarRegistry,
2121
} from './contribution';
22-
import { MaybePromise, MenuModelRegistry, nls } from '@theia/core/lib/common';
22+
import { MenuModelRegistry, nls } from '@theia/core/lib/common';
2323
import { CurrentSketch } from '../sketches-service-client-impl';
2424
import { ArduinoMenus } from '../menu/arduino-menus';
2525

@@ -99,8 +99,8 @@ export class Debug extends SketchContribution {
9999
this.notificationCenter.onPlatformDidUninstall(() => this.refreshState());
100100
}
101101

102-
override onReady(): MaybePromise<void> {
103-
this.refreshState();
102+
override onReady(): void {
103+
this.boardsServiceProvider.ready.then(() => this.refreshState());
104104
}
105105

106106
override registerCommands(registry: CommandRegistry): void {

Diff for: arduino-ide-extension/src/browser/contributions/examples.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ export class LibraryExamples extends Examples {
300300
this.notificationCenter.onLibraryDidUninstall(() => this.update());
301301
}
302302

303-
override async onReady(): Promise<void> {
304-
this.update(); // no `await`
303+
override onReady(): void {
304+
this.boardsServiceProvider.ready.then(() => this.update());
305305
}
306306

307307
protected override handleBoardChanged(board: Board | undefined): void {

Diff for: arduino-ide-extension/src/browser/contributions/include-library.ts

+13-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import PQueue from 'p-queue';
22
import { inject, injectable } from '@theia/core/shared/inversify';
33
import URI from '@theia/core/lib/common/uri';
44
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
5-
import { EditorManager } from '@theia/editor/lib/browser';
65
import { MenuModelRegistry, MenuPath } from '@theia/core/lib/common/menu';
76
import {
87
Disposable,
@@ -22,28 +21,25 @@ import { CurrentSketch } from '../sketches-service-client-impl';
2221
@injectable()
2322
export class IncludeLibrary extends SketchContribution {
2423
@inject(CommandRegistry)
25-
protected readonly commandRegistry: CommandRegistry;
24+
private readonly commandRegistry: CommandRegistry;
2625

2726
@inject(MenuModelRegistry)
28-
protected readonly menuRegistry: MenuModelRegistry;
27+
private readonly menuRegistry: MenuModelRegistry;
2928

3029
@inject(MainMenuManager)
31-
protected readonly mainMenuManager: MainMenuManager;
32-
33-
@inject(EditorManager)
34-
protected override readonly editorManager: EditorManager;
30+
private readonly mainMenuManager: MainMenuManager;
3531

3632
@inject(NotificationCenter)
37-
protected readonly notificationCenter: NotificationCenter;
33+
private readonly notificationCenter: NotificationCenter;
3834

3935
@inject(BoardsServiceProvider)
40-
protected readonly boardsServiceProvider: BoardsServiceProvider;
36+
private readonly boardsServiceProvider: BoardsServiceProvider;
4137

4238
@inject(LibraryService)
43-
protected readonly libraryService: LibraryService;
39+
private readonly libraryService: LibraryService;
4440

45-
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
46-
protected readonly toDispose = new DisposableCollection();
41+
private readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
42+
private readonly toDispose = new DisposableCollection();
4743

4844
override onStart(): void {
4945
this.boardsServiceProvider.onBoardsConfigDidChange(() =>
@@ -56,8 +52,8 @@ export class IncludeLibrary extends SketchContribution {
5652
this.notificationCenter.onDidReinitialize(() => this.updateMenuActions());
5753
}
5854

59-
override async onReady(): Promise<void> {
60-
this.updateMenuActions();
55+
override onReady(): void {
56+
this.boardsServiceProvider.ready.then(() => this.updateMenuActions());
6157
}
6258

6359
override registerMenus(registry: MenuModelRegistry): void {
@@ -93,7 +89,7 @@ export class IncludeLibrary extends SketchContribution {
9389
});
9490
}
9591

96-
protected async updateMenuActions(): Promise<void> {
92+
private async updateMenuActions(): Promise<void> {
9793
return this.queue.add(async () => {
9894
this.toDispose.dispose();
9995
this.mainMenuManager.update();
@@ -139,7 +135,7 @@ export class IncludeLibrary extends SketchContribution {
139135
});
140136
}
141137

142-
protected registerLibrary(
138+
private registerLibrary(
143139
libraryOrPlaceholder: LibraryPackage | string,
144140
menuPath: MenuPath
145141
): Disposable {
@@ -172,7 +168,7 @@ export class IncludeLibrary extends SketchContribution {
172168
);
173169
}
174170

175-
protected async includeLibrary(library: LibraryPackage): Promise<void> {
171+
private async includeLibrary(library: LibraryPackage): Promise<void> {
176172
const sketch = await this.sketchServiceClient.currentSketch();
177173
if (!CurrentSketch.isValid(sketch)) {
178174
return;

Diff for: arduino-ide-extension/src/browser/contributions/selected-board.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ export class SelectedBoard extends Contribution {
1919
private readonly boardsServiceProvider: BoardsServiceProvider;
2020

2121
override onStart(): void {
22-
this.boardsServiceProvider.onBoardListDidChange(() =>
23-
this.update(this.boardsServiceProvider.boardList)
22+
this.boardsServiceProvider.onBoardListDidChange((boardList) =>
23+
this.update(boardList)
2424
);
2525
}
2626

2727
override onReady(): void {
28-
this.update(this.boardsServiceProvider.boardList);
28+
this.boardsServiceProvider.ready.then(() => this.update());
2929
}
3030

31-
private update(boardList: BoardList): void {
31+
private update(
32+
boardList: BoardList = this.boardsServiceProvider.boardList
33+
): void {
3234
const { selectedBoard, selectedPort } = boardList.boardsConfig;
3335
this.statusBar.setElement('arduino-selected-board', {
3436
alignment: StatusBarAlignment.RIGHT,

0 commit comments

Comments
 (0)