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) => {
|
ipcMain.handle(DownloadRoute.abortDownload, async (_event, fileName) => {
|
||||||
const rq = DownloadManager.instance.networkRequests[fileName]
|
const rq = DownloadManager.instance.networkRequests[fileName]
|
||||||
|
if (rq) {
|
||||||
DownloadManager.instance.networkRequests[fileName] = undefined
|
DownloadManager.instance.networkRequests[fileName] = undefined
|
||||||
rq?.abort()
|
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 destination = resolve(userDataPath, fileName)
|
||||||
const rq = request(url)
|
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`
|
const downloadingTempFile = `${destination}.download`
|
||||||
|
|
||||||
progress(rq, {})
|
progress(rq, {})
|
||||||
@ -93,13 +107,11 @@ export function handleDownloaderIPCs() {
|
|||||||
DownloadEvent.onFileDownloadError,
|
DownloadEvent.onFileDownloadError,
|
||||||
{
|
{
|
||||||
fileName,
|
fileName,
|
||||||
err: 'Download cancelled',
|
err: { message: 'aborted' },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.pipe(createWriteStream(downloadingTempFile))
|
.pipe(createWriteStream(downloadingTempFile))
|
||||||
|
|
||||||
DownloadManager.instance.setRequest(fileName, rq)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,7 @@ export default function EventListenerWrapper({ children }: PropsWithChildren) {
|
|||||||
|
|
||||||
window.electronAPI.onFileDownloadError(
|
window.electronAPI.onFileDownloadError(
|
||||||
async (_event: string, state: any) => {
|
async (_event: string, state: any) => {
|
||||||
|
if (state.err?.message !== 'aborted')
|
||||||
console.error('Download error', state)
|
console.error('Download error', state)
|
||||||
const modelName = await baseName(state.fileName)
|
const modelName = await baseName(state.fileName)
|
||||||
const model = modelsRef.current.find(
|
const model = modelsRef.current.find(
|
||||||
@ -66,7 +67,7 @@ export default function EventListenerWrapper({ children }: PropsWithChildren) {
|
|||||||
if (state && state.fileName) {
|
if (state && state.fileName) {
|
||||||
const modelName = await baseName(state.fileName)
|
const modelName = await baseName(state.fileName)
|
||||||
const model = modelsRef.current.find(
|
const model = modelsRef.current.find(
|
||||||
async (model) => modelBinFileName(model) === modelName
|
(model) => modelBinFileName(model) === modelName
|
||||||
)
|
)
|
||||||
if (model) {
|
if (model) {
|
||||||
setDownloadStateSuccess(model.id)
|
setDownloadStateSuccess(model.id)
|
||||||
|
|||||||
@ -33,7 +33,7 @@ const setDownloadStateFailedAtom = atom(null, (get, set, modelId: string) => {
|
|||||||
const currentState = { ...get(modelDownloadStateAtom) }
|
const currentState = { ...get(modelDownloadStateAtom) }
|
||||||
const state = currentState[modelId]
|
const state = currentState[modelId]
|
||||||
if (!state) {
|
if (!state) {
|
||||||
console.error(`Cannot find download state for ${modelId}`)
|
console.debug(`Cannot find download state for ${modelId}`)
|
||||||
toaster({
|
toaster({
|
||||||
title: 'Cancel Download',
|
title: 'Cancel Download',
|
||||||
description: `Model ${modelId} cancel download`,
|
description: `Model ${modelId} cancel download`,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user