filter what is available in user arch (#542)

Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-05-02 13:33:45 +08:00 committed by GitHub
parent 7ae1dd2ddb
commit 90b7c750de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 13 deletions

View file

@ -46,20 +46,15 @@
>
<div class="version-button h-full">
<div class="flex h-full flex-col justify-center p-2">
{#if hasVersionSelectorDropdown}
<div class="flex items-center justify-between gap-x-2">
<div class="flex items-center gap-x-2">
<div>{ctaLabel}</div>
<div class="version-label {badgeClass[pkg.state]}">{pkg.version}</div>
</div>
<i class="icon-downward-arrow flex" />
</div>
{:else}
<div class="flex items-center justify-center gap-x-2">
<div class="flex items-center justify-between gap-x-2">
<div class="flex items-center gap-x-2">
<div>{ctaLabel}</div>
<div class="version-label {badgeClass[pkg.state]}">{pkg.version}</div>
</div>
{/if}
{#if hasVersionSelectorDropdown}
<i class="icon-downward-arrow flex" />
{/if}
</div>
</div>
<!-- This slot holds the drop down menu and it inside of the button so that the
hover effect remain on the button while the user is hovering the dropdown items-->

View file

@ -3,15 +3,16 @@ import { clean } from "semver";
import semverCompare from "semver/functions/compare";
// Find a list of available versions for a package based on the bottles
export const findAvailableVersions = (pkg: GUIPackage) => {
export const findAvailableVersions = (pkg: Pick<GUIPackage, "bottles" | "version">) => {
// default to just showing the latest if bottles haven't loaded yet
if (!pkg.bottles) {
return [pkg.version];
}
const versionSet = new Set<string>();
const arch = process.arch === "arm64" ? "aarch64" : "x86-64";
for (const b of pkg.bottles) {
versionSet.add(b.version);
if (b.arch === arch) versionSet.add(b.version);
}
return Array.from(versionSet).sort((a, b) => semverCompare(cleanVersion(b), cleanVersion(a)));