Add sha256sum check for update downloads

This commit is contained in:
2025-11-02 22:36:06 -07:00
parent e8b630ee37
commit 48a7ed545f
6 changed files with 46 additions and 8 deletions

View File

@@ -66,11 +66,15 @@ export default function Home () {
if (!launcherUpdateData) return
const downloadResult = await invoke('download', {
url: getDownloadLink(launcherUpdateData),
name: launcherLatestRequest.data
name: launcherLatestRequest.data,
hash: getDownloadHash(launcherUpdateData)
})
if (downloadResult !== '1') {
if (downloadResult == '-1') {
setState('Failed. Check internet connection.')
return
} else if (downloadResult == '-2') {
setState('File integrity check failed.')
return
}
setState('Starting...')
}
@@ -101,6 +105,26 @@ export default function Home () {
return undefined
}
function getDownloadHash (version: LauncherUpdate): string | undefined {
const p = platform()
const a = arch()
const findUrl = (plat: string) => {
const i = version.platforms.indexOf(plat)
return i >= 0 ? version.sha256sums[i] : undefined
}
if (p === 'windows') {
if (a === 'x86_64') return findUrl('windows-x64')
if (a === 'aarch64') return findUrl('windows-arm64')
} else if (p === 'macos') {
if (a === 'x86_64') return findUrl('macos-intel')
if (a === 'aarch64') return findUrl('macos-silicon')
} else if (p === 'linux') return findUrl(p)
return undefined
}
return (
<>
<div className='absolute left-1/2 top-[20%] -translate-x-1/2 flex flex-col items-center'>

View File

@@ -3,5 +3,5 @@ export interface LauncherUpdate {
releaseDate: number
downloadUrls: string[]
platforms: string[]
executables: string[]
sha256sums: string[]
}