Skip to content

Commit

Permalink
remove unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
bongbui321 committed Apr 21, 2024
1 parent e87e329 commit e04901f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 282 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"dependencies": {
"autoprefixer": "10.4.14",
"comlink": "^4.4.1",
"crc-32": "^1.2.2",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
Expand Down
99 changes: 20 additions & 79 deletions src/utils/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { useEffect, useRef, useState } from 'react'

import { concatUint8Array } from '@/QDL/utils'
import { qdlDevice } from '@/QDL/qdl'
import * as Comlink from 'comlink'
import { usePlausible } from 'next-plausible'

import config from '@/config'
import { download } from '@/utils/blob'
import { useImageWorker } from '@/utils/image'
import { createManifest } from '@/utils/manifest'
import { withProgress } from '@/utils/progress'

Expand Down Expand Up @@ -76,7 +74,6 @@ export function useQdl() {
const [onContinue, setOnContinue] = useState(null)
const [onRetry, setOnRetry] = useState(null)

const imageWorker = useImageWorker()
const qdl = useRef(new qdlDevice())

/** @type {React.RefObject<Image[]>} */
Expand All @@ -101,10 +98,6 @@ export function useQdl() {
setMessage()

if (error) return
if (!imageWorker.current) {
console.debug('[QDL] Waiting for image worker')
return
}

switch (step) {
case Step.INITIALIZING: {
Expand All @@ -130,24 +123,17 @@ export function useQdl() {
}

// TODO: change manifest once alt image is in release
imageWorker.current?.init()
.then(() => download(config.manifests['master']))
.then(blob => blob.text())
.then(text => {
manifest.current = createManifest(text)

// sanity check
if (manifest.current.length === 0) {
throw 'Manifest is empty'
}
async function initialize() {
const blobText = await (await download(config.manifests['master'])).text()
manifest.current = createManifest(blobText)
if (manifest.current.length === 0) {
throw 'Manifest is empty'
}
console.debug('[QDL] Loaded manifest', manifest.current)
setStep(Step.READY)
}

console.debug('[QDL] Loaded manifest', manifest.current)
setStep(Step.READY)
})
.catch((err) => {
console.error('[QDL] Initialization error', err)
setError(Error.UNKNOWN)
})
initialize()
break
}

Expand Down Expand Up @@ -177,7 +163,7 @@ export function useQdl() {
setSerial(qdl.current.sahara.serial || 'unknown')
setConnected(true)
plausible('device-connected')
setStep(Step.DOWNLOADING)
setStep(Step.FLASHING)
})
.catch((err) => {
console.error('[QDL] Error getting device information', err)
Expand All @@ -197,54 +183,6 @@ export function useQdl() {
break
}

case Step.DOWNLOADING: {
setProgress(0)

async function downloadImages() {
for await (const [image, onProgress] of withProgress(manifest.current, setProgress)) {
setMessage(`Downloading ${image.name}`)
await imageWorker.current.downloadImage(image, Comlink.proxy(onProgress))
}
}

downloadImages()
.then(() => {
console.debug('[QDL] Downloaded all images')
setStep(Step.UNPACKING)
})
.catch((err) => {
console.error('[QDL] Download error', err)
setError(Error.DOWNLOAD_FAILED)
})
break
}

case Step.UNPACKING: {
setProgress(0)

async function unpackImages() {
for await (const [image, onProgress] of withProgress(manifest.current, setProgress)) {
setMessage(`Unpacking ${image.name}`)
await imageWorker.current.unpackImage(image, Comlink.proxy(onProgress))
}
}

unpackImages()
.then(() => {
console.debug('[QDL] Unpacked all images')
setStep(Step.FLASHING)
})
.catch((err) => {
console.error('[QDL] Unpack error', err)
if (err.startsWith('Checksum mismatch')) {
setError(Error.CHECKSUM_MISMATCH)
} else {
setError(Error.UNPACK_FAILED)
}
})
break
}

case Step.FLASHING: {
setProgress(0)

Expand All @@ -260,12 +198,9 @@ export function useQdl() {
await qdl.current.erase("xbl"+`_${currentSlot}`)

for await (const [image, onProgress] of withProgress(manifest.current, setProgress)) {
const fileHandle = await imageWorker.current.getImage(image)
const blob = await fileHandle.getFile()

setMessage(`Flashing ${image.name}`)
const partitionName = image.name + `_${otherSlot}`
await qdl.current.flashBlob(partitionName, blob, onProgress)
await qdl.current.flashBlob(partitionName, image, onProgress)
}
console.debug('[QDL] Flashed all partitions')

Expand All @@ -280,7 +215,13 @@ export function useQdl() {
})
.catch((err) => {
console.error('[QDL] Flashing error', err)
setError(Error.FLASH_FAILED)
if (err.startsWith("Checksum mismatch")) {
setError(Error.CHECKSUM_MISMATCH)
} else if (error.startsWith("Error download archive")) {
setError(Error.DOWNLOAD_FAILED)
} else {
setError(Error.FLASH_FAILED)
}
})
break
}
Expand Down Expand Up @@ -318,7 +259,7 @@ export function useQdl() {
break
}
}
}, [imageWorker, step])
}, [step])

useEffect(() => {
if (error !== Error.NONE) {
Expand Down
15 changes: 0 additions & 15 deletions src/utils/image.js

This file was deleted.

6 changes: 2 additions & 4 deletions src/utils/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ export class Image {
this.checksum = json.alt.hash
this.fileName = `${this.name}-skip-chunks-${json.hash_raw}.img`
this.archiveUrl = json.alt.url
this.size = json.alt.size
} else {
this.checksum = json.hash
this.fileName = `${this.name}-${json.hash_raw}.img`
this.archiveUrl = json.url
this.size = json.size
}
}

this.archiveFileName = this.archiveUrl.split('/').pop()
this.size = json.size
}
}

Expand Down
183 changes: 0 additions & 183 deletions src/workers/image.worker.js

This file was deleted.

0 comments on commit e04901f

Please sign in to comment.