Skip to content

Commit

Permalink
Add a Lua download button
Browse files Browse the repository at this point in the history
  • Loading branch information
pkendall64 committed Sep 6, 2023
1 parent 9f0ff05 commit 26c332f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<input name="model" id="model" type="text" autocomplete="off" placeholder="Start typing for auto-complete..."/>
<label>Device Model</label>
</div>
<div class="mui--pull-left">
<button class="mui-btn" id="download-lua">Download ELRS Lua Script</button>
</div>
<div class="mui--pull-right">
<button class="mui-btn" id="device-discover" style="cursor: help;">Wifi Auto Discover</button>
<button class="mui-btn mui-btn--primary" id="device-next" disabled>Next</button>
Expand Down
27 changes: 27 additions & 0 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,33 @@ const checkProxy = async () => {
})
}

_('download-lua').onclick = async () => {
downloadFile(`firmware/${versionSelect.value}/lua/elrsV3.lua`, 'elrsV3.lua')
}

async function downloadFile (url, filename) {
try {
const response = await fetch(url)
if (response.status !== 200) {
throw new Error(`Unable to download file. HTTP status: ${response.status}`)
}
const blob = await response.blob()
const downloadLink = document.createElement('a')
downloadLink.href = URL.createObjectURL(blob)
downloadLink.download = filename

document.body.appendChild(downloadLink)
downloadLink.click()

setTimeout(() => {
URL.revokeObjectURL(downloadLink.href)
document.body.removeChild(downloadLink)
}, 100)
} catch (error) {
console.error('Error downloading the file:', error.message)
}
}

function initialise () {
checkProxy()
setInterval(() => { checkProxy() }, 30000)
Expand Down

0 comments on commit 26c332f

Please sign in to comment.