Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix updating library freeze #898

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading