Skip to content

Commit 29f7816

Browse files
author
Alberto Iannaccone
committed
move initialization of libs and platforms into new contribution
1 parent 7f2b849 commit 29f7816

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

-26
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
SketchesService,
1111
ExecutableService,
1212
Sketch,
13-
LibraryService,
1413
ArduinoDaemon,
1514
} from '../common/protocol';
1615
import { Mutex } from 'async-mutex';
@@ -77,7 +76,6 @@ import { IDEUpdater } from '../common/protocol/ide-updater';
7776
import { FileSystemFrontendContribution } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
7877
import { HostedPluginEvents } from './hosted-plugin-events';
7978

80-
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages';
8179
export const SKIP_IDE_VERSION = 'skipIDEVersion';
8280

8381
@injectable()
@@ -98,9 +96,6 @@ export class ArduinoFrontendContribution
9896
@inject(BoardsService)
9997
private readonly boardsService: BoardsService;
10098

101-
@inject(LibraryService)
102-
private readonly libraryService: LibraryService;
103-
10499
@inject(BoardsServiceProvider)
105100
private readonly boardsServiceClientImpl: BoardsServiceProvider;
106101

@@ -162,27 +157,6 @@ export class ArduinoFrontendContribution
162157

163158
@postConstruct()
164159
protected async init(): Promise<void> {
165-
const isFirstStartup = !(await this.localStorageService.getData(
166-
INIT_LIBS_AND_PACKAGES
167-
));
168-
if (isFirstStartup) {
169-
await this.localStorageService.setData(INIT_LIBS_AND_PACKAGES, true);
170-
const avrPackage = await this.boardsService.getBoardPackage({
171-
id: 'arduino:avr',
172-
});
173-
const builtInLibrary = (
174-
await this.libraryService.search({
175-
query: 'Arduino_BuiltIn',
176-
})
177-
)[0];
178-
179-
!!avrPackage && (await this.boardsService.install({ item: avrPackage }));
180-
!!builtInLibrary &&
181-
(await this.libraryService.install({
182-
item: builtInLibrary,
183-
installDependencies: true,
184-
}));
185-
}
186160
if (!window.navigator.onLine) {
187161
// tslint:disable-next-line:max-line-length
188162
this.messageService.warn(

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ import { CompilerErrors } from './contributions/compiler-errors';
302302
import { WidgetManager } from './theia/core/widget-manager';
303303
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
304304
import { StartupTask } from './widgets/sketchbook/startup-task';
305+
import { InitLibsPlatforms } from './contributions/init-libs-platforms';
305306

306307
MonacoThemingService.register({
307308
id: 'arduino-theme',
@@ -695,6 +696,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
695696
Contribution.configure(bind, Format);
696697
Contribution.configure(bind, CompilerErrors);
697698
Contribution.configure(bind, StartupTask);
699+
Contribution.configure(bind, InitLibsPlatforms);
698700

699701
// Disabled the quick-pick customization from Theia when multiple formatters are available.
700702
// Use the default VS Code behavior, and pick the first one. In the IDE2, clang-format has `exclusive` selectors.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { LocalStorageService } from '@theia/core/lib/browser';
2+
import { inject, injectable } from '@theia/core/shared/inversify';
3+
import { BoardsService, LibraryService } from '../../common/protocol';
4+
import { Contribution } from './contribution';
5+
6+
@injectable()
7+
export class InitLibsPlatforms extends Contribution {
8+
@inject(LocalStorageService)
9+
private readonly localStorageService: LocalStorageService;
10+
@inject(BoardsService)
11+
private readonly boardsService: BoardsService;
12+
@inject(LibraryService)
13+
private readonly libraryService: LibraryService;
14+
15+
override async onReady(): Promise<void> {
16+
const isFirstStartup = !(await this.localStorageService.getData(
17+
InitLibsPlatforms.INIT_LIBS_AND_PACKAGES
18+
));
19+
if (isFirstStartup) {
20+
await this.localStorageService.setData(
21+
InitLibsPlatforms.INIT_LIBS_AND_PACKAGES,
22+
true
23+
);
24+
const avrPackage = await this.boardsService.getBoardPackage({
25+
id: 'arduino:avr',
26+
});
27+
const builtInLibrary = (
28+
await this.libraryService.search({
29+
query: 'Arduino_BuiltIn',
30+
})
31+
)[0];
32+
33+
if (avrPackage) {
34+
await this.boardsService.install({ item: avrPackage });
35+
}
36+
if (builtInLibrary) {
37+
await this.libraryService.install({
38+
item: builtInLibrary,
39+
installDependencies: true,
40+
});
41+
}
42+
}
43+
}
44+
}
45+
export namespace InitLibsPlatforms {
46+
export const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages';
47+
}

0 commit comments

Comments
 (0)