diff --git a/.changeset/purple-terms-relax.md b/.changeset/purple-terms-relax.md new file mode 100644 index 000000000..effdd83e6 --- /dev/null +++ b/.changeset/purple-terms-relax.md @@ -0,0 +1,5 @@ +--- +'website': patch +--- + +Fixed an issue where the desktop download widget would not autoselect the correct OS download. diff --git a/apps/website/components/DownloadDesktopSelect.tsx b/apps/website/components/DownloadDesktopSelect.tsx index a343e1a73..519fec6f1 100644 --- a/apps/website/components/DownloadDesktopSelect.tsx +++ b/apps/website/components/DownloadDesktopSelect.tsx @@ -21,7 +21,7 @@ type Props = { } export function DownloadDesktopSelect({ daemon, release, testnetOnly }: Props) { - const downloadLinks = getDownloadLinksDesktop(daemon, release) + const downloadLinks = getDownloadLinksDesktop(release) const { accepted } = useTermsOfService() const [download, setDownload] = useState(downloadLinks[0]) diff --git a/apps/website/content/downloads.spec.ts b/apps/website/content/downloads.spec.ts new file mode 100644 index 000000000..3d9996db8 --- /dev/null +++ b/apps/website/content/downloads.spec.ts @@ -0,0 +1,114 @@ +import { getTags, findUserDefaultDownload } from './downloads' + +const downloadsList = [ + // desktop release naming scheme + { name: 'walletd-arm64.dmg' }, + { name: 'walletd-x64.dmg' }, + { name: 'walletd-0.12.0.Setup.exe' }, + { name: 'walletd_0.12.0_arm64.deb' }, + { name: 'walletd_0.12.0_amd64.deb' }, + { name: 'walletd-0.12.0-1.arm64.rpm' }, + { name: 'walletd-0.12.0-1.x86_64.rpm' }, + // daemon release naming scheme + { name: 'walletd_darwin_amd64.zip' }, + { name: 'walletd_darwin_arm64.zip' }, + { name: 'walletd_linux_amd64.zip' }, + { name: 'walletd_linux_arm64.zip' }, + { name: 'walletd_windows_amd64.zip' }, +].map(({ name }) => ({ title: '', link: '', tags: getTags({ name }) })) + +describe('getTags', () => { + test('desktop releases should return the correct tags', () => { + expect(getTags({ name: 'walletd-arm64.dmg' })).toEqual(['macos', 'arm64']) + expect(getTags({ name: 'walletd-x64.dmg' })).toEqual(['macos', 'amd64']) + expect(getTags({ name: 'walletd-0.12.0.Setup.exe' })).toEqual([ + 'windows', + 'amd64', + ]) + expect(getTags({ name: 'walletd_0.12.0_arm64.deb' })).toEqual([ + 'linux', + 'arm64', + ]) + expect(getTags({ name: 'walletd_0.12.0_amd64.deb' })).toEqual([ + 'linux', + 'amd64', + ]) + expect(getTags({ name: 'walletd-0.12.0-1.arm64.rpm' })).toEqual([ + 'linux', + 'arm64', + ]) + expect(getTags({ name: 'walletd-0.12.0-1.x86_64.rpm' })).toEqual([ + 'linux', + 'amd64', + ]) + }) + test('daemon releases should return the correct tags', () => { + expect(getTags({ name: 'walletd_darwin_amd64.zip' })).toEqual([ + 'macos', + 'amd64', + ]) + expect(getTags({ name: 'walletd_darwin_arm64.zip' })).toEqual([ + 'macos', + 'arm64', + ]) + expect(getTags({ name: 'walletd_linux_amd64.zip' })).toEqual([ + 'linux', + 'amd64', + ]) + expect(getTags({ name: 'walletd_linux_arm64.zip' })).toEqual([ + 'linux', + 'arm64', + ]) + expect(getTags({ name: 'walletd_windows_amd64.zip' })).toEqual([ + 'windows', + 'amd64', + ]) + }) +}) + +describe('findUserDefaultDownload', () => { + test('any windows user-agent should return amd64', () => { + const userAgent = + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0' + jest.spyOn(navigator, 'userAgent', 'get').mockReturnValue(userAgent) + const download = findUserDefaultDownload(downloadsList) + expect(download).toEqual({ + title: '', + link: '', + tags: ['windows', 'amd64'], + }) + }) + test('any macos user-agent should return arm64', () => { + const userAgent = + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' + jest.spyOn(navigator, 'userAgent', 'get').mockReturnValue(userAgent) + const download = findUserDefaultDownload(downloadsList) + expect(download).toEqual({ + title: '', + link: '', + tags: ['macos', 'arm64'], + }) + }) + test('linux arm user-agent should return arm64', () => { + const userAgent = + 'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36' + jest.spyOn(navigator, 'userAgent', 'get').mockReturnValue(userAgent) + const download = findUserDefaultDownload(downloadsList) + expect(download).toEqual({ + title: '', + link: '', + tags: ['linux', 'arm64'], + }) + }) + test('linux amd user-agent should return amd64', () => { + const userAgent = + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36' + jest.spyOn(navigator, 'userAgent', 'get').mockReturnValue(userAgent) + const download = findUserDefaultDownload(downloadsList) + expect(download).toEqual({ + title: '', + link: '', + tags: ['linux', 'amd64'], + }) + }) +}) diff --git a/apps/website/content/downloads.ts b/apps/website/content/downloads.ts index 6e508c2df..b5859ff07 100644 --- a/apps/website/content/downloads.ts +++ b/apps/website/content/downloads.ts @@ -1,4 +1,4 @@ -import { GitHubRelease, GitHubReleaseAsset } from '@siafoundation/data-sources' +import { GitHubRelease } from '@siafoundation/data-sources' type DownloadOption = { title: string; link: string; tags: DownloadTag[] } @@ -25,15 +25,13 @@ export function getDownloadLinksDaemon(daemon: string, release: GitHubRelease) { } export function getDownloadLinksDesktop( - daemon: string, release: GitHubRelease ): DownloadOption[] { if (!release) { return [] } - // Desktop releases include assets for multiple daemons, so we need to filter. - const assets = release.assets.filter((asset) => asset.name.includes(daemon)) + const { assets } = release const final = [] @@ -117,7 +115,7 @@ export function getDownloadLinksDesktop( type DownloadTag = 'zen' | 'windows' | 'macos' | 'linux' | 'amd64' | 'arm64' -function getTags(asset: GitHubReleaseAsset): DownloadTag[] { +export function getTags(asset: { name: string }): DownloadTag[] { const tags: DownloadTag[] = [] if (asset.name.includes('testnet') || asset.name.includes('zen')) { tags.push('zen') @@ -125,10 +123,19 @@ function getTags(asset: GitHubReleaseAsset): DownloadTag[] { if (asset.name.includes('windows')) { tags.push('windows') } - if (asset.name.includes('darwin')) { + if (asset.name.includes('Setup.exe')) { + // For now assume amd64 for Windows exe. + tags.push('windows') + tags.push('amd64') + } + if (asset.name.includes('darwin') || asset.name.includes('.dmg')) { tags.push('macos') } - if (asset.name.includes('linux')) { + if ( + asset.name.includes('linux') || + asset.name.includes('.deb') || + asset.name.includes('.rpm') + ) { tags.push('linux') } if (