Skip to content

Commit

Permalink
Fix Library Update Freeze (#898)
Browse files Browse the repository at this point in the history
* fix updating library freeze

* fix updating library freeze

* refactor
  • Loading branch information
nguyd1 authored Jan 15, 2024
1 parent 88a70cb commit 64ef4ba
Showing 1 changed file with 35 additions and 42 deletions.
77 changes: 35 additions & 42 deletions src/services/updates/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 64ef4ba

Please sign in to comment.