mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-08 11:56:36 +00:00
Automatically install 'Arduino_BuiltIn' library at first startup (#663)
This commit is contained in:
parent
5ddab1ded7
commit
88397931c5
@ -7,6 +7,7 @@ import {
|
||||
SketchesService,
|
||||
ExecutableService,
|
||||
Sketch,
|
||||
LibraryService,
|
||||
} from '../common/protocol';
|
||||
import { Mutex } from 'async-mutex';
|
||||
import {
|
||||
@ -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
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
@ -30,7 +30,8 @@ import { InstallWithProgress } from './grpc-installable';
|
||||
@injectable()
|
||||
export class LibraryServiceImpl
|
||||
extends CoreClientAware
|
||||
implements LibraryService {
|
||||
implements LibraryService
|
||||
{
|
||||
@inject(ILogger)
|
||||
protected logger: ILogger;
|
||||
|
||||
@ -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);
|
||||
@ -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(),
|
||||
@ -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);
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user