ATL-1195: Show examples if no board is selected.

Show all examples:
 - when no board is selected,
 - when the core is not installed for the selected board.

Otherwise, show examples for the currently selected board only.
Only get libraries from the cores when the FQBN is defined.
Otherwise, we retrieve user installed libraries only.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2021-04-07 11:57:09 +02:00 committed by Akos Kitta
parent a8df2444a9
commit 68af4c38fe
4 changed files with 18 additions and 20 deletions

View File

@ -154,15 +154,14 @@ export class LibraryExamples extends Examples {
protected async register(board: Board | undefined = this.boardsServiceClient.boardsConfig.selectedBoard): Promise<void> {
return this.queue.add(async () => {
this.toDispose.dispose();
if (!board || !board.fqbn) {
return;
}
const { fqbn, name } = board;
const fqbn = board?.fqbn;
const name = board?.name;
// Shows all examples when no board is selected, or the platform of the currently selected board is not installed.
const { user, current, any } = await this.examplesService.installed({ fqbn });
if (user.length) {
(user as any).unshift('Examples from Custom Libraries');
}
if (current.length) {
if (name && fqbn && current.length) {
(current as any).unshift(`Examples for ${name}`);
}
if (any.length) {

View File

@ -4,7 +4,7 @@ export const ExamplesServicePath = '/services/example-service';
export const ExamplesService = Symbol('ExamplesService');
export interface ExamplesService {
builtIns(): Promise<SketchContainer[]>;
installed(options: { fqbn: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }>;
installed(options: { fqbn?: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }>;
}

View File

@ -40,22 +40,20 @@ export class ExamplesServiceImpl implements ExamplesService {
}
// TODO: decide whether it makes sense to cache them. Keys should be: `fqbn` + version of containing core/library.
async installed({ fqbn }: { fqbn: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }> {
async installed({ fqbn }: { fqbn?: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }> {
const user: SketchContainer[] = [];
const current: SketchContainer[] = [];
const any: SketchContainer[] = [];
if (fqbn) {
const packages: LibraryPackage[] = await this.libraryService.list({ fqbn });
for (const pkg of packages) {
const container = await this.tryGroupExamples(pkg);
const { location } = pkg;
if (location === LibraryLocation.USER) {
user.push(container);
} else if (location === LibraryLocation.PLATFORM_BUILTIN || LibraryLocation.REFERENCED_PLATFORM_BUILTIN) {
current.push(container);
} else {
any.push(container);
}
const packages: LibraryPackage[] = await this.libraryService.list({ fqbn });
for (const pkg of packages) {
const container = await this.tryGroupExamples(pkg);
const { location } = pkg;
if (location === LibraryLocation.USER) {
user.push(container);
} else if (location === LibraryLocation.PLATFORM_BUILTIN || LibraryLocation.REFERENCED_PLATFORM_BUILTIN) {
current.push(container);
} else {
any.push(container);
}
}
return { user, current, any };

View File

@ -83,8 +83,9 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
const { client, instance } = coreClient;
const req = new LibraryListReq();
req.setInstance(instance);
req.setAll(true);
if (fqbn) {
// Only get libraries from the cores when the FQBN is defined. Otherwise, we retrieve user installed libraries only.
req.setAll(true); // https://github.com/arduino/arduino-ide/pull/303#issuecomment-815556447
req.setFqbn(fqbn);
}