Skip to content

Commit

Permalink
Automatically install 'Arduino_BuiltIn' library at first startup (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Iannaccone authored Dec 6, 2021
1 parent 5ddab1d commit 8839793
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SketchesService,
ExecutableService,
Sketch,
LibraryService,
} from '../common/protocol';
import { Mutex } from 'async-mutex';
import {
Expand Down Expand Up @@ -69,7 +70,7 @@ import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-c
import { SaveAsSketch } from './contributions/save-as-sketch';
import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution';

const INIT_AVR_PACKAGES = 'initializedAvrPackages';
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages';

@injectable()
export class ArduinoFrontendContribution
Expand All @@ -89,6 +90,9 @@ export class ArduinoFrontendContribution
@inject(BoardsService)
protected readonly boardsService: BoardsService;

@inject(LibraryService)
protected readonly libraryService: LibraryService;

@inject(BoardsServiceProvider)
protected readonly boardsServiceClientImpl: BoardsServiceProvider;

Expand Down Expand Up @@ -161,15 +165,26 @@ export class ArduinoFrontendContribution

@postConstruct()
protected async init(): Promise<void> {
const notFirstStartup = await this.localStorageService.getData(
INIT_AVR_PACKAGES
);
if (!notFirstStartup) {
await this.localStorageService.setData(INIT_AVR_PACKAGES, true);
const isFirstStartup = !(await this.localStorageService.getData(
INIT_LIBS_AND_PACKAGES
));
if (isFirstStartup) {
await this.localStorageService.setData(INIT_LIBS_AND_PACKAGES, true);
const avrPackage = await this.boardsService.getBoardPackage({
id: 'arduino:avr',
});
avrPackage && (await this.boardsService.install({ item: avrPackage }));
const builtInLibrary = (
await this.libraryService.search({
query: 'Arduino_BuiltIn',
})
)[0];

!!avrPackage && (await this.boardsService.install({ item: avrPackage }));
!!builtInLibrary &&
(await this.libraryService.install({
item: builtInLibrary,
installDependencies: true,
}));
}
if (!window.navigator.onLine) {
// tslint:disable-next-line:max-line-length
Expand Down
18 changes: 9 additions & 9 deletions arduino-ide-extension/src/node/library-service-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import { InstallWithProgress } from './grpc-installable';
@injectable()
export class LibraryServiceImpl
extends CoreClientAware
implements LibraryService {
implements LibraryService
{
@inject(ILogger)
protected logger: ILogger;

Expand Down Expand Up @@ -267,9 +268,7 @@ export class LibraryServiceImpl
req.setInstance(instance);
req.setName(item.name);
req.setVersion(version);
if (options.installDependencies === false) {
req.setNoDeps(true);
}
req.setNoDeps(!options.installDependencies);

console.info('>>> Starting library package installation...', item);
const resp = client.libraryInstall(req);
Expand All @@ -282,13 +281,14 @@ export class LibraryServiceImpl
);
await new Promise<void>((resolve, reject) => {
resp.on('end', () => {
this.boardDiscovery.startBoardListWatch(coreClient)
this.boardDiscovery.startBoardListWatch(coreClient);
resolve();
});
resp.on('error', (error) => {
this.responseService.appendToOutput({
chunk: `Failed to install library: ${item.name}${version ? `:${version}` : ''
}.\n`,
chunk: `Failed to install library: ${item.name}${
version ? `:${version}` : ''
}.\n`,
});
this.responseService.appendToOutput({
chunk: error.toString(),
Expand Down Expand Up @@ -332,7 +332,7 @@ export class LibraryServiceImpl
);
await new Promise<void>((resolve, reject) => {
resp.on('end', () => {
this.boardDiscovery.startBoardListWatch(coreClient)
this.boardDiscovery.startBoardListWatch(coreClient);
resolve();
});
resp.on('error', reject);
Expand Down Expand Up @@ -364,7 +364,7 @@ export class LibraryServiceImpl
);
await new Promise<void>((resolve, reject) => {
resp.on('end', () => {
this.boardDiscovery.startBoardListWatch(coreClient)
this.boardDiscovery.startBoardListWatch(coreClient);
resolve();
});
resp.on('error', reject);
Expand Down

0 comments on commit 8839793

Please sign in to comment.