Skip to content

Commit 95971a2

Browse files
author
Akos Kitta
committed
first start installer has its own contribution.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 60ebba4 commit 95971a2

File tree

3 files changed

+48
-38
lines changed

3 files changed

+48
-38
lines changed

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

+1-38
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import {
55
postConstruct,
66
} from '@theia/core/shared/inversify';
77
import * as React from '@theia/core/shared/react';
8-
import {
9-
BoardsService,
10-
LibraryService,
11-
SketchesService,
12-
} from '../common/protocol';
8+
import { SketchesService } from '../common/protocol';
139
import {
1410
MAIN_MENU_BAR,
1511
MenuContribution,
@@ -19,7 +15,6 @@ import {
1915
Dialog,
2016
FrontendApplication,
2117
FrontendApplicationContribution,
22-
LocalStorageService,
2318
OnWillStopAction,
2419
} from '@theia/core/lib/browser';
2520
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
@@ -52,8 +47,6 @@ import { MonitorViewContribution } from './serial/monitor/monitor-view-contribut
5247
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
5348
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
5449

55-
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages';
56-
5750
@injectable()
5851
export class ArduinoFrontendContribution
5952
implements
@@ -66,12 +59,6 @@ export class ArduinoFrontendContribution
6659
@inject(MessageService)
6760
private readonly messageService: MessageService;
6861

69-
@inject(BoardsService)
70-
private readonly boardsService: BoardsService;
71-
72-
@inject(LibraryService)
73-
private readonly libraryService: LibraryService;
74-
7562
@inject(BoardsServiceProvider)
7663
private readonly boardsServiceProvider: BoardsServiceProvider;
7764

@@ -87,35 +74,11 @@ export class ArduinoFrontendContribution
8774
@inject(SketchesServiceClientImpl)
8875
private readonly sketchServiceClient: SketchesServiceClientImpl;
8976

90-
@inject(LocalStorageService)
91-
private readonly localStorageService: LocalStorageService;
92-
9377
@inject(FrontendApplicationStateService)
9478
private readonly appStateService: FrontendApplicationStateService;
9579

9680
@postConstruct()
9781
protected async init(): Promise<void> {
98-
const isFirstStartup = !(await this.localStorageService.getData(
99-
INIT_LIBS_AND_PACKAGES
100-
));
101-
if (isFirstStartup) {
102-
await this.localStorageService.setData(INIT_LIBS_AND_PACKAGES, true);
103-
const avrPackage = await this.boardsService.getBoardPackage({
104-
id: 'arduino:avr',
105-
});
106-
const builtInLibrary = (
107-
await this.libraryService.search({
108-
query: 'Arduino_BuiltIn',
109-
})
110-
)[0];
111-
112-
!!avrPackage && (await this.boardsService.install({ item: avrPackage }));
113-
!!builtInLibrary &&
114-
(await this.libraryService.install({
115-
item: builtInLibrary,
116-
installDependencies: true,
117-
}));
118-
}
11982
if (!window.navigator.onLine) {
12083
// tslint:disable-next-line:max-line-length
12184
this.messageService.warn(

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

+2
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ import { SelectedBoard } from './contributions/selected-board';
310310
import { CheckForUpdates } from './contributions/check-for-updates';
311311
import { OpenBoardsConfig } from './contributions/open-boards-config';
312312
import { SketchFilesTracker } from './contributions/sketch-files-tracker';
313+
import { FirstStartInstaller } from './contributions/first-start-installer';
313314

314315
MonacoThemingService.register({
315316
id: 'arduino-theme',
@@ -708,6 +709,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
708709
Contribution.configure(bind, CheckForUpdates);
709710
Contribution.configure(bind, OpenBoardsConfig);
710711
Contribution.configure(bind, SketchFilesTracker);
712+
Contribution.configure(bind, FirstStartInstaller);
711713

712714
// Disabled the quick-pick customization from Theia when multiple formatters are available.
713715
// 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,45 @@
1+
import { LocalStorageService } from '@theia/core/lib/browser/storage-service';
2+
import { inject, injectable } from '@theia/core/shared/inversify';
3+
import { BoardsService, LibraryService } from '../../common/protocol';
4+
import { Contribution } from './contribution';
5+
6+
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages';
7+
8+
@injectable()
9+
export class FirstStartInstaller extends Contribution {
10+
@inject(LocalStorageService)
11+
private readonly localStorageService: LocalStorageService;
12+
13+
@inject(BoardsService)
14+
private readonly boardsService: BoardsService;
15+
16+
@inject(LibraryService)
17+
private readonly libraryService: LibraryService;
18+
19+
override onReady(): void {
20+
this.localStorageService
21+
.getData(INIT_LIBS_AND_PACKAGES)
22+
.then(async (value) => {
23+
const isFirstStartup = !value;
24+
if (isFirstStartup) {
25+
await this.localStorageService.setData(INIT_LIBS_AND_PACKAGES, true);
26+
const avrPackage = await this.boardsService.getBoardPackage({
27+
id: 'arduino:avr',
28+
});
29+
const builtInLibrary = (
30+
await this.libraryService.search({
31+
query: 'Arduino_BuiltIn',
32+
})
33+
)[0];
34+
35+
!!avrPackage &&
36+
(await this.boardsService.install({ item: avrPackage }));
37+
!!builtInLibrary &&
38+
(await this.libraryService.install({
39+
item: builtInLibrary,
40+
installDependencies: true,
41+
}));
42+
}
43+
});
44+
}
45+
}

0 commit comments

Comments
 (0)