From 044aec968929efdd0d2608489c80d6e04c8edebb Mon Sep 17 00:00:00 2001 From: luddens Date: Wed, 19 Jun 2019 15:49:48 +0200 Subject: [PATCH] Pause book's download while dialog to cancel is open When the download of a book finishes while the cancel's dialog is opened and then that the user confirms the deletion of the book, the app crashes because aria2 can't find the active download (which is already complete). Pause the download before opening the dialog and check the download's status before cancel it avoid this crash. --- resources/js/_contentManager.js | 3 +++ src/contentmanager.cpp | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/resources/js/_contentManager.js b/resources/js/_contentManager.js index 9606f4d..6a08fee 100644 --- a/resources/js/_contentManager.js +++ b/resources/js/_contentManager.js @@ -100,10 +100,13 @@ function init() { } }, cancelBook : function(book) { + contentManager.pauseBook(book.id); if (confirm("Are you sure you want to abort the download of '" + book.title + "' ?")) { contentManager.cancelBook(book.id); clearInterval(downloadUpdaters[book.id]); Vue.delete(app.downloads, book.id); + } else { + contentManager.resumeBook(book.id); } }, displayedBooks : function(books, nb) { diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index e95702e..c8a4c8f 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -237,7 +237,9 @@ void ContentManager::cancelBook(const QString& id) { auto& b = mp_library->getBookById(id); auto download = mp_downloader->getDownload(b.getDownloadId()); - download->cancelDownload(); + if (download->getStatus() != kiwix::Download::K_COMPLETE) { + download->cancelDownload(); + } QString fileToRemove = QString::fromUtf8(getLastPathElement(download->getPath()).c_str()) + "*"; eraseBookFilesFromComputer(fileToRemove); mp_library->removeBookFromLibraryById(id);