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:
parent
7c784eada6
commit
051dbcb937
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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`,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user