Skip to content

Commit 1192d6a

Browse files
author
Alberto Iannaccone
committed
Automatically install 'Arduino_BuiltIn' library at first startup
1 parent f0d9894 commit 1192d6a

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

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

+22-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
SketchesService,
88
ExecutableService,
99
Sketch,
10+
LibraryService,
1011
} from '../common/protocol';
1112
import { Mutex } from 'async-mutex';
1213
import {
@@ -69,7 +70,7 @@ import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-c
6970
import { SaveAsSketch } from './contributions/save-as-sketch';
7071
import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution';
7172

72-
const INIT_AVR_PACKAGES = 'initializedAvrPackages';
73+
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages';
7374

7475
@injectable()
7576
export class ArduinoFrontendContribution
@@ -89,6 +90,9 @@ export class ArduinoFrontendContribution
8990
@inject(BoardsService)
9091
protected readonly boardsService: BoardsService;
9192

93+
@inject(LibraryService)
94+
protected readonly libraryService: LibraryService;
95+
9296
@inject(BoardsServiceProvider)
9397
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
9498

@@ -161,15 +165,26 @@ export class ArduinoFrontendContribution
161165

162166
@postConstruct()
163167
protected async init(): Promise<void> {
164-
const notFirstStartup = await this.localStorageService.getData(
165-
INIT_AVR_PACKAGES
166-
);
167-
if (!notFirstStartup) {
168-
await this.localStorageService.setData(INIT_AVR_PACKAGES, true);
168+
const isFirstStartup = !(await this.localStorageService.getData(
169+
INIT_LIBS_AND_PACKAGES
170+
));
171+
if (isFirstStartup) {
172+
await this.localStorageService.setData(INIT_LIBS_AND_PACKAGES, true);
169173
const avrPackage = await this.boardsService.getBoardPackage({
170174
id: 'arduino:avr',
171175
});
172-
avrPackage && (await this.boardsService.install({ item: avrPackage }));
176+
const builtInLibrary = (
177+
await this.libraryService.search({
178+
query: 'Arduino_BuiltIn',
179+
})
180+
)[0];
181+
182+
!!avrPackage && (await this.boardsService.install({ item: avrPackage }));
183+
!!builtInLibrary &&
184+
(await this.libraryService.install({
185+
item: builtInLibrary,
186+
installDependencies: true,
187+
}));
173188
}
174189
if (!window.navigator.onLine) {
175190
// tslint:disable-next-line:max-line-length

Diff for: arduino-ide-extension/src/node/library-service-server-impl.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import { InstallWithProgress } from './grpc-installable';
3030
@injectable()
3131
export class LibraryServiceImpl
3232
extends CoreClientAware
33-
implements LibraryService {
33+
implements LibraryService
34+
{
3435
@inject(ILogger)
3536
protected logger: ILogger;
3637

@@ -267,9 +268,7 @@ export class LibraryServiceImpl
267268
req.setInstance(instance);
268269
req.setName(item.name);
269270
req.setVersion(version);
270-
if (options.installDependencies === false) {
271-
req.setNoDeps(true);
272-
}
271+
req.setNoDeps(!options.installDependencies);
273272

274273
console.info('>>> Starting library package installation...', item);
275274
const resp = client.libraryInstall(req);
@@ -282,13 +281,14 @@ export class LibraryServiceImpl
282281
);
283282
await new Promise<void>((resolve, reject) => {
284283
resp.on('end', () => {
285-
this.boardDiscovery.startBoardListWatch(coreClient)
284+
this.boardDiscovery.startBoardListWatch(coreClient);
286285
resolve();
287286
});
288287
resp.on('error', (error) => {
289288
this.responseService.appendToOutput({
290-
chunk: `Failed to install library: ${item.name}${version ? `:${version}` : ''
291-
}.\n`,
289+
chunk: `Failed to install library: ${item.name}${
290+
version ? `:${version}` : ''
291+
}.\n`,
292292
});
293293
this.responseService.appendToOutput({
294294
chunk: error.toString(),
@@ -332,7 +332,7 @@ export class LibraryServiceImpl
332332
);
333333
await new Promise<void>((resolve, reject) => {
334334
resp.on('end', () => {
335-
this.boardDiscovery.startBoardListWatch(coreClient)
335+
this.boardDiscovery.startBoardListWatch(coreClient);
336336
resolve();
337337
});
338338
resp.on('error', reject);
@@ -364,7 +364,7 @@ export class LibraryServiceImpl
364364
);
365365
await new Promise<void>((resolve, reject) => {
366366
resp.on('end', () => {
367-
this.boardDiscovery.startBoardListWatch(coreClient)
367+
this.boardDiscovery.startBoardListWatch(coreClient);
368368
resolve();
369369
});
370370
resp.on('error', reject);

0 commit comments

Comments
 (0)