Skip to content

Commit

Permalink
#4486: FindSuitableIcon grabs last suitable icon, not first. (#4629)
Browse files Browse the repository at this point in the history
fixes #4486

Co-authored-by: Justin Willis <[email protected]>
  • Loading branch information
zateutsch and jgw96 authored Jan 25, 2024
1 parent f5ca667 commit d745d41
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions apps/pwabuilder/src/script/utils/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export function findSuitableIcon(
}

const iconInfos = isIconInfos(icons) ? icons : icons.map(i => new IconInfo(i));
const exactMatch = iconInfos.find(i => i.isExactMatch(purpose, desiredWidth, desiredHeight, mimeType));
const exactMatch = iconInfos.findLast(i => i.isExactMatch(purpose, desiredWidth, desiredHeight, mimeType));
if (exactMatch) {
return exactMatch.getIcon();
}

var largerMatch = iconInfos.find(i => i.isSuitableIcon(purpose, desiredWidth, desiredHeight, mimeType));
var largerMatch = iconInfos.findLast(i => i.isSuitableIcon(purpose, desiredWidth, desiredHeight, mimeType));
return largerMatch?.getIcon() || null;
}

Expand Down Expand Up @@ -69,12 +69,7 @@ export function findBestAppIcon(icons: Icon[] | null | undefined): Icon | null {
}

function isIconInfos(icons: Icon[] | IconInfo[]): icons is IconInfo[] {
const firstIcon = icons[0];
if (firstIcon instanceof IconInfo) {
return true;
}

return false;
return ( icons[0] instanceof IconInfo );
}

/**
Expand Down

0 comments on commit d745d41

Please sign in to comment.