Skip to content

Automatically install 'Arduino_BuiltIn' library at first startup #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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