mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-10 14:16:34 +00:00
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:
parent
a8df2444a9
commit
68af4c38fe
@ -154,15 +154,14 @@ export class LibraryExamples extends Examples {
|
|||||||
protected async register(board: Board | undefined = this.boardsServiceClient.boardsConfig.selectedBoard): Promise<void> {
|
protected async register(board: Board | undefined = this.boardsServiceClient.boardsConfig.selectedBoard): Promise<void> {
|
||||||
return this.queue.add(async () => {
|
return this.queue.add(async () => {
|
||||||
this.toDispose.dispose();
|
this.toDispose.dispose();
|
||||||
if (!board || !board.fqbn) {
|
const fqbn = board?.fqbn;
|
||||||
return;
|
const name = board?.name;
|
||||||
}
|
// Shows all examples when no board is selected, or the platform of the currently selected board is not installed.
|
||||||
const { fqbn, name } = board;
|
|
||||||
const { user, current, any } = await this.examplesService.installed({ fqbn });
|
const { user, current, any } = await this.examplesService.installed({ fqbn });
|
||||||
if (user.length) {
|
if (user.length) {
|
||||||
(user as any).unshift('Examples from Custom Libraries');
|
(user as any).unshift('Examples from Custom Libraries');
|
||||||
}
|
}
|
||||||
if (current.length) {
|
if (name && fqbn && current.length) {
|
||||||
(current as any).unshift(`Examples for ${name}`);
|
(current as any).unshift(`Examples for ${name}`);
|
||||||
}
|
}
|
||||||
if (any.length) {
|
if (any.length) {
|
||||||
|
@ -4,7 +4,7 @@ export const ExamplesServicePath = '/services/example-service';
|
|||||||
export const ExamplesService = Symbol('ExamplesService');
|
export const ExamplesService = Symbol('ExamplesService');
|
||||||
export interface ExamplesService {
|
export interface ExamplesService {
|
||||||
builtIns(): Promise<SketchContainer[]>;
|
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[] }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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.
|
// 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 user: SketchContainer[] = [];
|
||||||
const current: SketchContainer[] = [];
|
const current: SketchContainer[] = [];
|
||||||
const any: SketchContainer[] = [];
|
const any: SketchContainer[] = [];
|
||||||
if (fqbn) {
|
const packages: LibraryPackage[] = await this.libraryService.list({ fqbn });
|
||||||
const packages: LibraryPackage[] = await this.libraryService.list({ fqbn });
|
for (const pkg of packages) {
|
||||||
for (const pkg of packages) {
|
const container = await this.tryGroupExamples(pkg);
|
||||||
const container = await this.tryGroupExamples(pkg);
|
const { location } = pkg;
|
||||||
const { location } = pkg;
|
if (location === LibraryLocation.USER) {
|
||||||
if (location === LibraryLocation.USER) {
|
user.push(container);
|
||||||
user.push(container);
|
} else if (location === LibraryLocation.PLATFORM_BUILTIN || LibraryLocation.REFERENCED_PLATFORM_BUILTIN) {
|
||||||
} else if (location === LibraryLocation.PLATFORM_BUILTIN || LibraryLocation.REFERENCED_PLATFORM_BUILTIN) {
|
current.push(container);
|
||||||
current.push(container);
|
} else {
|
||||||
} else {
|
any.push(container);
|
||||||
any.push(container);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { user, current, any };
|
return { user, current, any };
|
||||||
|
@ -83,8 +83,9 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
|
|||||||
const { client, instance } = coreClient;
|
const { client, instance } = coreClient;
|
||||||
const req = new LibraryListReq();
|
const req = new LibraryListReq();
|
||||||
req.setInstance(instance);
|
req.setInstance(instance);
|
||||||
req.setAll(true);
|
|
||||||
if (fqbn) {
|
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);
|
req.setFqbn(fqbn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user