Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b5d758

Browse files
author
Akos Kitta
committed
deferred contributions to start on app ready.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent f007b0e commit 5b5d758

File tree

10 files changed

+140
-83
lines changed

10 files changed

+140
-83
lines changed

‎arduino-ide-extension/src/browser/contributions/board-selection.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ PID: ${PID}`;
101101
}
102102

103103
override onStart(): void {
104-
this.updateMenus();
105104
this.notificationCenter.onPlatformInstalled(this.updateMenus.bind(this));
106105
this.notificationCenter.onPlatformUninstalled(this.updateMenus.bind(this));
107106
this.boardsServiceProvider.onBoardsConfigChanged(
@@ -115,6 +114,10 @@ PID: ${PID}`;
115114
);
116115
}
117116

117+
override async onReady(): Promise<void> {
118+
this.updateMenus();
119+
}
120+
118121
protected async updateMenus(): Promise<void> {
119122
const [installedBoards, availablePorts, config] = await Promise.all([
120123
this.installedBoards(),

‎arduino-ide-extension/src/browser/contributions/contribution.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { inject, injectable, interfaces } from '@theia/core/shared/inversify';
1+
import {
2+
inject,
3+
injectable,
4+
interfaces,
5+
postConstruct,
6+
} from '@theia/core/shared/inversify';
27
import URI from '@theia/core/lib/common/uri';
38
import { ILogger } from '@theia/core/lib/common/logger';
49
import { Saveable } from '@theia/core/lib/browser/saveable';
@@ -42,6 +47,7 @@ import {
4247
Sketch,
4348
} from '../../common/protocol';
4449
import { ArduinoPreferences } from '../arduino-preferences';
50+
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
4551

4652
export {
4753
Command,
@@ -84,15 +90,31 @@ export abstract class Contribution
8490
@inject(SettingsService)
8591
protected readonly settingsService: SettingsService;
8692

93+
@inject(FrontendApplicationStateService)
94+
protected readonly appStateService: FrontendApplicationStateService;
95+
96+
@postConstruct()
97+
protected init(): void {
98+
this.appStateService.reachedState('ready').then(() => this.onReady());
99+
}
100+
101+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function, unused-imports/no-unused-vars
87102
onStart(app: FrontendApplication): MaybePromise<void> {}
88103

104+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function, unused-imports/no-unused-vars
89105
registerCommands(registry: CommandRegistry): void {}
90106

107+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function, unused-imports/no-unused-vars
91108
registerMenus(registry: MenuModelRegistry): void {}
92109

110+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function, unused-imports/no-unused-vars
93111
registerKeybindings(registry: KeybindingRegistry): void {}
94112

113+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function, unused-imports/no-unused-vars
95114
registerToolbarItems(registry: TabBarToolbarRegistry): void {}
115+
116+
// eslint-disable-next-line @typescript-eslint/no-empty-function
117+
onReady(): MaybePromise<void> {}
96118
}
97119

98120
@injectable()
@@ -140,7 +162,7 @@ export abstract class SketchContribution extends Contribution {
140162
}
141163

142164
export namespace Contribution {
143-
export function configure<T>(
165+
export function configure(
144166
bind: interfaces.Bind,
145167
serviceIdentifier: typeof Contribution
146168
): void {

‎arduino-ide-extension/src/browser/contributions/debug.ts‎

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
SketchContribution,
1313
TabBarToolbarRegistry,
1414
} from './contribution';
15-
import { nls } from '@theia/core/lib/common';
15+
import { MaybePromise,nls } from '@theia/core/lib/common';
1616

1717
@injectable()
1818
export class Debug extends SketchContribution {
@@ -79,52 +79,15 @@ export class Debug extends SketchContribution {
7979
: Debug.Commands.START_DEBUGGING.label
8080
}`)
8181
);
82-
const refreshState = async (
83-
board: Board | undefined = this.boardsServiceProvider.boardsConfig
84-
.selectedBoard
85-
) => {
86-
if (!board) {
87-
this.disabledMessage = nls.localize(
88-
'arduino/common/noBoardSelected',
89-
'No board selected'
90-
);
91-
return;
92-
}
93-
const fqbn = board.fqbn;
94-
if (!fqbn) {
95-
this.disabledMessage = nls.localize(
96-
'arduino/debug/noPlatformInstalledFor',
97-
"Platform is not installed for '{0}'",
98-
board.name
99-
);
100-
return;
101-
}
102-
const details = await this.boardService.getBoardDetails({ fqbn });
103-
if (!details) {
104-
this.disabledMessage = nls.localize(
105-
'arduino/debug/noPlatformInstalledFor',
106-
"Platform is not installed for '{0}'",
107-
board.name
108-
);
109-
return;
110-
}
111-
const { debuggingSupported } = details;
112-
if (!debuggingSupported) {
113-
this.disabledMessage = nls.localize(
114-
'arduino/debug/debuggingNotSupported',
115-
"Debugging is not supported by '{0}'",
116-
board.name
117-
);
118-
} else {
119-
this.disabledMessage = undefined;
120-
}
121-
};
12282
this.boardsServiceProvider.onBoardsConfigChanged(({ selectedBoard }) =>
123-
refreshState(selectedBoard)
83+
this.refreshState(selectedBoard)
12484
);
125-
this.notificationCenter.onPlatformInstalled(() => refreshState());
126-
this.notificationCenter.onPlatformUninstalled(() => refreshState());
127-
refreshState();
85+
this.notificationCenter.onPlatformInstalled(() => this.refreshState());
86+
this.notificationCenter.onPlatformUninstalled(() => this.refreshState());
87+
}
88+
89+
override onReady(): MaybePromise<void> {
90+
this.refreshState();
12891
}
12992

13093
override registerCommands(registry: CommandRegistry): void {
@@ -140,6 +103,47 @@ export class Debug extends SketchContribution {
140103
registry.registerItem(this.debugToolbarItem);
141104
}
142105

106+
private async refreshState(
107+
board: Board | undefined = this.boardsServiceProvider.boardsConfig
108+
.selectedBoard
109+
): Promise<void> {
110+
if (!board) {
111+
this.disabledMessage = nls.localize(
112+
'arduino/common/noBoardSelected',
113+
'No board selected'
114+
);
115+
return;
116+
}
117+
const fqbn = board.fqbn;
118+
if (!fqbn) {
119+
this.disabledMessage = nls.localize(
120+
'arduino/debug/noPlatformInstalledFor',
121+
"Platform is not installed for '{0}'",
122+
board.name
123+
);
124+
return;
125+
}
126+
const details = await this.boardService.getBoardDetails({ fqbn });
127+
if (!details) {
128+
this.disabledMessage = nls.localize(
129+
'arduino/debug/noPlatformInstalledFor',
130+
"Platform is not installed for '{0}'",
131+
board.name
132+
);
133+
return;
134+
}
135+
const { debuggingSupported } = details;
136+
if (!debuggingSupported) {
137+
this.disabledMessage = nls.localize(
138+
'arduino/debug/debuggingNotSupported',
139+
"Debugging is not supported by '{0}'",
140+
board.name
141+
);
142+
} else {
143+
this.disabledMessage = undefined;
144+
}
145+
}
146+
143147
protected async startDebug(
144148
board: Board | undefined = this.boardsServiceProvider.boardsConfig
145149
.selectedBoard

‎arduino-ide-extension/src/browser/contributions/examples.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as PQueue from 'p-queue';
2-
import { inject, injectable,postConstruct } from '@theia/core/shared/inversify';
2+
import { inject, injectable } from '@theia/core/shared/inversify';
33
import { CommandHandler } from '@theia/core/lib/common/command';
44
import {
55
MenuPath,
@@ -43,8 +43,8 @@ export abstract class Examples extends SketchContribution {
4343

4444
protected readonly toDispose = new DisposableCollection();
4545

46-
@postConstruct()
47-
init(): void{
46+
protectedoverrideinit(): void{
47+
super.init();
4848
this.boardsServiceClient.onBoardsConfigChanged(({ selectedBoard }) =>
4949
this.handleBoardChanged(selectedBoard)
5050
);
@@ -161,7 +161,7 @@ export abstract class Examples extends SketchContribution {
161161

162162
@injectable()
163163
export class BuiltInExamples extends Examples {
164-
override onStart(): void {
164+
override asynconReady(): Promise<void> {
165165
this.register(); // no `await`
166166
}
167167

@@ -202,11 +202,14 @@ export class LibraryExamples extends Examples {
202202
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
203203

204204
override onStart(): void {
205-
this.register(); // no `await`
206205
this.notificationCenter.onLibraryInstalled(() => this.register());
207206
this.notificationCenter.onLibraryUninstalled(() => this.register());
208207
}
209208

209+
override async onReady(): Promise<void> {
210+
this.register(); // no `await`
211+
}
212+
210213
protected override handleBoardChanged(board: Board | undefined): void {
211214
this.register(board);
212215
}

‎arduino-ide-extension/src/browser/contributions/include-library.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export class IncludeLibrary extends SketchContribution {
4545
protected readonly toDispose = new DisposableCollection();
4646

4747
override onStart(): void {
48-
this.updateMenuActions();
4948
this.boardsServiceClient.onBoardsConfigChanged(() =>
5049
this.updateMenuActions()
5150
);
@@ -55,6 +54,10 @@ export class IncludeLibrary extends SketchContribution {
5554
);
5655
}
5756

57+
override async onReady(): Promise<void> {
58+
this.updateMenuActions();
59+
}
60+
5861
override registerMenus(registry: MenuModelRegistry): void {
5962
// `Include Library` submenu
6063
const includeLibMenuPath = [

‎arduino-ide-extension/src/browser/contributions/open-recent-sketch.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ export class OpenRecentSketch extends SketchContribution {
3636
protected toDisposeBeforeRegister = new Map<string, DisposableCollection>();
3737

3838
override onStart(): void {
39-
const refreshMenu = (sketches: Sketch[]) => {
40-
this.register(sketches);
41-
this.mainMenuManager.update();
42-
};
4339
this.notificationCenter.onRecentSketchesChanged(({ sketches }) =>
44-
refreshMenu(sketches)
40+
this.refreshMenu(sketches)
4541
);
46-
this.sketchService.recentlyOpenedSketches().then(refreshMenu);
42+
}
43+
44+
override async onReady(): Promise<void> {
45+
this.sketchService
46+
.recentlyOpenedSketches()
47+
.then((sketches) => this.refreshMenu(sketches));
4748
}
4849

4950
override registerMenus(registry: MenuModelRegistry): void {
@@ -54,6 +55,11 @@ export class OpenRecentSketch extends SketchContribution {
5455
);
5556
}
5657

58+
private refreshMenu(sketches: Sketch[]): void {
59+
this.register(sketches);
60+
this.mainMenuManager.update();
61+
}
62+
5763
protected register(sketches: Sketch[]): void {
5864
const order = 0;
5965
for (const sketch of sketches) {

‎arduino-ide-extension/src/browser/contributions/sketchbook.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ export class Sketchbook extends Examples {
2424
protected readonly notificationCenter: NotificationCenter;
2525

2626
override onStart(): void {
27-
this.sketchService.getSketches({}).then((container) => {
28-
this.register(container);
29-
this.mainMenuManager.update();
30-
});
3127
this.sketchServiceClient.onSketchbookDidChange(() => {
3228
this.sketchService.getSketches({}).then((container) => {
3329
this.register(container);
@@ -36,6 +32,13 @@ export class Sketchbook extends Examples {
3632
});
3733
}
3834

35+
override async onReady(): Promise<void> {
36+
this.sketchService.getSketches({}).then((container) => {
37+
this.register(container);
38+
this.mainMenuManager.update();
39+
});
40+
}
41+
3942
override registerMenus(registry: MenuModelRegistry): void {
4043
registry.registerSubmenu(
4144
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU,

‎arduino-ide-extension/src/browser/contributions/upload-sketch.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { inject, injectable,postConstruct } from '@theia/core/shared/inversify';
1+
import { inject, injectable } from '@theia/core/shared/inversify';
22
import { Emitter } from '@theia/core/lib/common/event';
33
import { BoardUserField, CoreService } from '../../common/protocol';
44
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
@@ -47,8 +47,8 @@ export class UploadSketch extends SketchContribution {
4747

4848
protected readonly menuActionsDisposables = new DisposableCollection();
4949

50-
@postConstruct()
51-
protectedinit(): void{
50+
protectedoverrideinit(): void{
51+
super.init();
5252
this.boardsServiceClientImpl.onBoardsConfigChanged(async () => {
5353
const userFields =
5454
await this.boardsServiceClientImpl.selectedBoardUserFields();

‎arduino-ide-extension/src/node/arduino-ide-backend-module.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import {
5858
FileSystemExt,
5959
FileSystemExtPath,
6060
} from '../common/protocol/filesystem-ext';
61-
import { ExamplesServiceImpl } from './examples-service-impl';
61+
import { BuiltInExamplesServiceImpl,ExamplesServiceImpl } from './examples-service-impl';
6262
import {
6363
ExamplesService,
6464
ExamplesServicePath,
@@ -124,6 +124,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
124124
)
125125
.inSingletonScope();
126126

127+
// Built-in examples are not board specific, so it is possible to have one shared instance.
128+
bind(BuiltInExamplesServiceImpl).toSelf().inSingletonScope();
129+
127130
// Examples service. One per backend, each connected FE gets a proxy.
128131
bind(ConnectionContainerModule).toConstantValue(
129132
ConnectionContainerModule.create(({ bind, bindBackendService }) => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /