Skip to content

Commit

Permalink
Ensured that 'syncingLibraryStarted' is always emitted when loading b…
Browse files Browse the repository at this point in the history
…ooks
  • Loading branch information
DavidLazarescu committed Dec 13, 2023
1 parent 7c3c445 commit bfc5478
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/application/services/library_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,7 @@ LibraryService::LibraryService(IMetadataExtractor* bookMetadataHelper,
connect(&m_fetchChangesTimer, &QTimer::timeout, this,
[this]()
{
m_libraryStorageManager->downloadRemoteBooks();

auto success = QNetworkInformation::loadDefaultBackend();
if(!success)
qWarning() << "Failed loading QNetworkInformation backend";

auto networkInfo = QNetworkInformation::instance();
if(networkInfo == nullptr)
{
qWarning() << "Failed loading QNetworkInformation instance";
}
else
{
if(networkInfo->reachability() ==
QNetworkInformation::Reachability::Online)
{
emit syncingLibraryStarted();
}
}
downloadBooks();
});

// Apply updates timer
Expand Down Expand Up @@ -105,6 +87,26 @@ LibraryService::LibraryService(IMetadataExtractor* bookMetadataHelper,
void LibraryService::downloadBooks()
{
m_libraryStorageManager->downloadRemoteBooks();

auto success = QNetworkInformation::loadDefaultBackend();
if(!success)
qWarning() << "Failed loading QNetworkInformation backend";

// We only want to emit the library sync signal if we know that we are
// online. Else the loading indicator would be spinning forever.
auto networkInfo = QNetworkInformation::instance();
if(networkInfo == nullptr)
{
qWarning() << "Failed loading QNetworkInformation instance";
}
else
{
if(networkInfo->reachability() ==
QNetworkInformation::Reachability::Online)
{
emit syncingLibraryStarted();
}
}
}

BookOperationStatus LibraryService::addBook(const QString& filePath,
Expand Down

0 comments on commit bfc5478

Please sign in to comment.