diff --git a/localtypings/pxtarget.d.ts b/localtypings/pxtarget.d.ts index 06f15833ea45..a78a63351dff 100644 --- a/localtypings/pxtarget.d.ts +++ b/localtypings/pxtarget.d.ts @@ -28,6 +28,8 @@ declare namespace pxt { // localized galleries localizedGalleries?: pxt.Map>; windowsStoreLink?: string; + // localized options on download dialog; name, description, url, imageUrl, variant used. + hardwareOptions?: CodeCard[]; // release manifest for the electron app electronManifest?: pxt.electron.ElectronManifest; profileNotification?: ProfileNotification; diff --git a/webapp/src/projects.tsx b/webapp/src/projects.tsx index e83a695a9d49..625d6603e9ee 100644 --- a/webapp/src/projects.tsx +++ b/webapp/src/projects.tsx @@ -1642,20 +1642,6 @@ export class ChooseHwDialog extends data.Component g.cards)) - .filter(c => !!c.variant); - } - } - return this.prevGalleries || []; - } - private setHwVariant(cfg: pxt.PackageConfig, card: pxt.CodeCard) { pxt.tickEvent("projects.choosehwvariant", { hwid: cfg.name, @@ -1682,17 +1668,19 @@ export class ChooseHwDialog extends data.Component this.setHwVariant(savedV, null) } - let cards = this.fetchGallery(); - for (const card of cards) { - const savedV = variants.find(variant => variant.name == card.variant); - const savedCard = card; - if (savedV) - card.onClick = () => this.setHwVariant(savedV, savedCard); - else { - pxt.reportError("hw", "invalid variant"); + + const targetConfig = this.getData("target-config:") as pxt.TargetConfig; + const cards = targetConfig?.hardwareOptions?.map(el => { + const displayCard = { ...el }; + const matchingVariant = variants.find(variant => variant.name === displayCard.variant); + if (!matchingVariant) { + // Variant may be experimental hw, ignore this option + return undefined; } - } - cards = cards.filter(card => !!card.onClick); + + displayCard.onClick = () => this.setHwVariant(matchingVariant, displayCard); + return displayCard; + }).filter(el => !!el); return (
- {cards.map(card => + {cards?.map(card =>