From ee34d9bbd04988e7faa4de009ceff2ec87ff1942 Mon Sep 17 00:00:00 2001 From: Joe Kendall Date: Fri, 10 May 2024 10:19:00 -0400 Subject: [PATCH] adding windows support to the download button and also fixing a bug where platforms were not being detected properly resulting in all platforms getting a email prompt --- src/components/Download.astro | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/components/Download.astro b/src/components/Download.astro index cb60229..95f7d0f 100644 --- a/src/components/Download.astro +++ b/src/components/Download.astro @@ -54,7 +54,6 @@ return e => { e.preventDefault(); e.stopImmediatePropagation(); - if (selected.asset) { const dl = document.createElement('a') dl.setAttribute('href', selected.asset.browser_download_url) @@ -111,8 +110,8 @@ const getRelease = async () => { const release = await fetch('https://api.github.com/repos/noop-inc/desktop/releases/latest', - { - headers: { + { + headers: { Accept: 'application/vnd.github+json', 'X-GitHub-Api-Version': '2022-11-28' } @@ -136,7 +135,8 @@ case ('macIntel'): searchTerm = `Noop-${version}-x64.dmg`; break; - case ('windows'): + case ('win'): + searchTerm = `Noop-${version}.Setup.exe`; break; case ('linux'): break; @@ -161,7 +161,7 @@ }, win: { label: 'Windows', - supported: false, + supported: true, releases: [ {label: 'Windows'} ]}, @@ -175,36 +175,34 @@ } const rel = await getRelease() - + const {name, assets } = rel Object.keys(detectables).forEach(k => detectables[k].releases.forEach(rel => Object.assign(rel, {asset: findAsset(k, name, assets), name: k}))) const selected = detectables[os] - if (!selected) { - - } else if (selected.supported) { + if (selected && selected.supported) { detectedOptions.innerHTML = '' - selected.releases.forEach(rel => { + selected.releases.forEach(s => { const relBtn = defaultButton.cloneNode() const label = document.createElement('span') - label.textContent = `Download Noop ${rel.label}` + label.textContent = `Download Noop ${s.label}` const icon = document.createElement('span') - icon.innerHTML = icons[rel.name] + icon.innerHTML = icons[s.name] icon.setAttribute('class', 'mr-2') relBtn.textContent = '' relBtn.appendChild(icon) relBtn.appendChild(label) - relBtn.setAttribute('href', rel.asset.browser_download_url) - relBtn.addEventListener('click', dlButtonHandler(rel, selected)) + relBtn.setAttribute('href', s.asset.browser_download_url) + relBtn.addEventListener('click', dlButtonHandler(rel, s)) detectedOptions.appendChild(relBtn) }) - } else { + } else if (selected) { detectedOptions.innerHTML = '' notifyHeadline.textContent = `${selected.label} support isn't available today, but we are working on it.`