From d4304c5e9301cc018ccec4d4400b8f9dbe1f414f Mon Sep 17 00:00:00 2001 From: nguyd1 <91645046+nguyd1@users.noreply.github.com> Date: Sun, 14 Jan 2024 11:29:12 -0800 Subject: [PATCH 1/3] fix updating library freeze --- src/services/updates/updates.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/updates/updates.js b/src/services/updates/updates.js index 6d29b9d51..02926a06b 100644 --- a/src/services/updates/updates.js +++ b/src/services/updates/updates.js @@ -89,7 +89,17 @@ const updateLibrary = async options => { } } catch (error) { showToast(libraryNovels[i].novelName + ': ' + error.message); - continue; + if (libraryNovels.length === i + 1) { + resolve(); + + Notifications.scheduleNotificationAsync({ + content: { + title: 'Library Updated', + body: libraryNovels.length + ' novels updated', + }, + trigger: null, + }); + } } } }); From 8867215215c2d3e2f48ffff72bcc5a2c71026290 Mon Sep 17 00:00:00 2001 From: nguyd1 <91645046+nguyd1@users.noreply.github.com> Date: Sun, 14 Jan 2024 11:29:12 -0800 Subject: [PATCH 2/3] fix updating library freeze --- src/services/updates/updates.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/services/updates/updates.js b/src/services/updates/updates.js index 6d29b9d51..906d136d7 100644 --- a/src/services/updates/updates.js +++ b/src/services/updates/updates.js @@ -62,21 +62,6 @@ const updateLibrary = async options => { progressBar: { max: libraryNovels.length, value: i + 1 }, }); - /** - * When updating library is finished - */ - if (libraryNovels.length === i + 1) { - resolve(); - - Notifications.scheduleNotificationAsync({ - content: { - title: 'Library Updated', - body: libraryNovels.length + ' novels updated', - }, - trigger: null, - }); - } - const nextNovelIndex = i + 1; if ( @@ -89,9 +74,20 @@ const updateLibrary = async options => { } } 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) { From b6a099ac3ff9132e1ae55fb87b4d00db35a9043f Mon Sep 17 00:00:00 2001 From: nguyd1 <91645046+nguyd1@users.noreply.github.com> Date: Sun, 14 Jan 2024 11:57:01 -0800 Subject: [PATCH 3/3] refactor --- src/services/updates/updates.js | 50 +++++++++++++++------------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/services/updates/updates.js b/src/services/updates/updates.js index 8f3fd97e3..1c3904a10 100644 --- a/src/services/updates/updates.js +++ b/src/services/updates/updates.js @@ -42,39 +42,35 @@ 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 }, + }); - const nextNovelIndex = i + 1; + 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; } } /**