From 9d69deee99683d285b3b82ade0678faa1e7ea56e Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Tue, 13 Jun 2023 17:42:14 -0400 Subject: [PATCH] Finally fix online library hanging on sync --- src/functions.h | 6 +++--- src/onlineLibrary/librarywidget.cpp | 14 ++++++++------ src/onlineLibrary/librarywidget.h | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/functions.h b/src/functions.h index e34e090..5376607 100644 --- a/src/functions.h +++ b/src/functions.h @@ -262,13 +262,13 @@ namespace { QTextStream in (&config); const QString content = in.readAll(); std::string contentstr = content.toStdString(); + config.close(); if(contentstr.find("true") != std::string::npos) { return true; } else { return false; } - config.close(); } else { return false; @@ -282,13 +282,13 @@ namespace { QTextStream in (&config); const QString content = in.readAll(); std::string contentstr = content.toStdString(); + config.close(); if(contentstr.find("true") != std::string::npos) { return true; } else { return false; } - config.close(); } else { return false; @@ -485,6 +485,7 @@ namespace { QTextStream in (&config); const QString content = in.readAll(); std::string contentstr = content.toStdString(); + config.close(); // Thanks to https://stackoverflow.com/questions/22516463/how-do-i-find-a-complete-word-not-part-of-it-in-a-string-in-c std::regex r("\\b" + pattern + "\\b"); @@ -496,7 +497,6 @@ namespace { else { return false; } - config.close(); return 0; }; bool isBatteryLow() { diff --git a/src/onlineLibrary/librarywidget.cpp b/src/onlineLibrary/librarywidget.cpp index 7c269c1..543cdd6 100644 --- a/src/onlineLibrary/librarywidget.cpp +++ b/src/onlineLibrary/librarywidget.cpp @@ -264,14 +264,15 @@ void libraryWidget::closeIndefiniteToast() { void libraryWidget::syncCatalog() { global::toast::modalToast = true; global::toast::indefiniteToast = true; - bool syncDone = false; log("Gutenberg sync in progress", className); showToast("Sync in progress"); + QTimer::singleShot(500, this, SLOT(syncCatalogSlot())); +} +void libraryWidget::syncCatalogSlot() { + bool syncDone = false; string_writeconfig("/opt/ibxd", "gutenberg_sync\n"); - QTimer * syncCheckTimer = new QTimer(this); - syncCheckTimer->setInterval(500); - connect(syncCheckTimer, &QTimer::timeout, [&]() { + while(true) { if(syncDone == false) { if(QFile::exists("/inkbox/gutenbergSyncDone") == true) { if(checkconfig("/inkbox/gutenbergSyncDone") == true) { @@ -286,10 +287,11 @@ void libraryWidget::syncCatalog() { } QFile::remove("/inkbox/gutenbergSyncDone"); syncDone = true; + break; } } - } ); - syncCheckTimer->start(); + QThread::msleep(500); + } } void libraryWidget::on_previousBtn_clicked() diff --git a/src/onlineLibrary/librarywidget.h b/src/onlineLibrary/librarywidget.h index 30bcb72..7e565a4 100644 --- a/src/onlineLibrary/librarywidget.h +++ b/src/onlineLibrary/librarywidget.h @@ -29,6 +29,7 @@ private: private slots: void syncCatalog(); + void syncCatalogSlot(); void setupView(); void showToast(QString messageToDisplay); void closeIndefiniteToast();