From 64ef4bae1f126be306c125c3d98d6e431cb8bc99 Mon Sep 17 00:00:00 2001 From: nguyd1 <91645046+nguyd1@users.noreply.github.com> Date: Sun, 14 Jan 2024 21:19:56 -0800 Subject: [PATCH] Fix Library Update Freeze (#898) * fix updating library freeze * fix updating library freeze * refactor --- src/services/updates/updates.js | 77 +++++++++++++++------------------ 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/src/services/updates/updates.js b/src/services/updates/updates.js index 6d29b9d51..1c3904a10 100644 --- a/src/services/updates/updates.js +++ b/src/services/updates/updates.js @@ -42,56 +42,49 @@ const updateLibrary = async options => { i++ ) { try { - if (BackgroundService.isRunning()) { - /** - * Update chapters - */ - await updateNovel( - libraryNovels[i].sourceId, - libraryNovels[i].novelUrl, - libraryNovels[i].novelId, - options, - ); + /** + * Update chapters + */ + await updateNovel( + libraryNovels[i].sourceId, + libraryNovels[i].novelUrl, + libraryNovels[i].novelId, + options, + ); - /** - * Update notification - */ - await BackgroundService.updateNotification({ - taskTitle: libraryNovels[i].novelName, - taskDesc: '(' + (i + 1) + '/' + libraryNovels.length + ')', - progressBar: { max: libraryNovels.length, value: i + 1 }, - }); + /** + * Update notification + */ + await BackgroundService.updateNotification({ + taskTitle: libraryNovels[i].novelName, + taskDesc: '(' + (i + 1) + '/' + libraryNovels.length + ')', + progressBar: { max: libraryNovels.length, value: i + 1 }, + }); - /** - * When updating library is finished - */ - if (libraryNovels.length === i + 1) { - resolve(); + const nextNovelIndex = i + 1; - Notifications.scheduleNotificationAsync({ - content: { - title: 'Library Updated', - body: libraryNovels.length + ' novels updated', - }, - trigger: null, - }); - } - - const nextNovelIndex = i + 1; - - if ( - nextNovelIndex in libraryNovels && - libraryNovels[nextNovelIndex].sourceId === - libraryNovels[i].sourceId - ) { - await sleep(taskData.delay); - } + if ( + nextNovelIndex in libraryNovels && + libraryNovels[nextNovelIndex].sourceId === libraryNovels[i].sourceId + ) { + await sleep(taskData.delay); } } catch (error) { showToast(libraryNovels[i].novelName + ': ' + error.message); - continue; } } + /** + * When updating library is finished + */ + resolve(); + + Notifications.scheduleNotificationAsync({ + content: { + title: 'Library Updated', + body: libraryNovels.length + ' novels updated', + }, + trigger: null, + }); }); if (libraryNovels.length > 0) {