fix: app getting stuck at downloading 99 percent while downloading model (#1320)

Addressed a critical issue where the application would become unresponsive at the 99 percent mark during model download
This commit is contained in:
Louis 2024-01-04 11:22:11 +07:00 committed by GitHub
parent 7c784eada6
commit 051dbcb937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 9 deletions

View File

@ -34,8 +34,18 @@ export function handleDownloaderIPCs() {
*/
ipcMain.handle(DownloadRoute.abortDownload, async (_event, fileName) => {
const rq = DownloadManager.instance.networkRequests[fileName]
if (rq) {
DownloadManager.instance.networkRequests[fileName] = undefined
rq?.abort()
} else {
WindowManager?.instance.currentWindow?.webContents.send(
DownloadEvent.onFileDownloadError,
{
fileName,
err: { message: 'aborted' },
}
)
}
})
/**
@ -54,7 +64,11 @@ export function handleDownloaderIPCs() {
}
const destination = resolve(userDataPath, fileName)
const rq = request(url)
// downloading file to a temp file first
// Put request to download manager instance
DownloadManager.instance.setRequest(fileName, rq)
// Downloading file to a temp file first
const downloadingTempFile = `${destination}.download`
progress(rq, {})
@ -93,13 +107,11 @@ export function handleDownloaderIPCs() {
DownloadEvent.onFileDownloadError,
{
fileName,
err: 'Download cancelled',
err: { message: 'aborted' },
}
)
}
})
.pipe(createWriteStream(downloadingTempFile))
DownloadManager.instance.setRequest(fileName, rq)
})
}

View File

@ -52,6 +52,7 @@ export default function EventListenerWrapper({ children }: PropsWithChildren) {
window.electronAPI.onFileDownloadError(
async (_event: string, state: any) => {
if (state.err?.message !== 'aborted')
console.error('Download error', state)
const modelName = await baseName(state.fileName)
const model = modelsRef.current.find(
@ -66,7 +67,7 @@ export default function EventListenerWrapper({ children }: PropsWithChildren) {
if (state && state.fileName) {
const modelName = await baseName(state.fileName)
const model = modelsRef.current.find(
async (model) => modelBinFileName(model) === modelName
(model) => modelBinFileName(model) === modelName
)
if (model) {
setDownloadStateSuccess(model.id)

View File

@ -33,7 +33,7 @@ const setDownloadStateFailedAtom = atom(null, (get, set, modelId: string) => {
const currentState = { ...get(modelDownloadStateAtom) }
const state = currentState[modelId]
if (!state) {
console.error(`Cannot find download state for ${modelId}`)
console.debug(`Cannot find download state for ${modelId}`)
toaster({
title: 'Cancel Download',
description: `Model ${modelId} cancel download`,