diff --git a/app/src/handlers/updatehandler.cpp b/app/src/handlers/updatehandler.cpp index d752bc830bcdc9679743aac1c6e379d36eb2b490..8d6229925b449e50047264fcd465603f2da8a68c 100644 --- a/app/src/handlers/updatehandler.cpp +++ b/app/src/handlers/updatehandler.cpp @@ -5,11 +5,10 @@ #include <QJsonArray> #include <QJsonObject> #include <QDateTime> +#include <QThread> +#include <QDebug> #ifdef QTLIB_UNIX -#include <thread> -#include <chrono> - #include "appimage/update.h" #endif @@ -28,11 +27,13 @@ void UpdateHandler::checkAll() auto application = configHandler_->getUsrConfigApplication(); auto installedItems = configHandler_->getUsrConfigInstalledItems(); - if (installedItems.isEmpty() - || (application.contains("update_checked_at") - && application["update_checked_at"].toInt() + (1000 * 60 * 60 * 24) > QDateTime::currentMSecsSinceEpoch())) { - emit checkAllFinished(); - return; + if (installedItems.isEmpty() || application.contains("update_checked_at")) { + auto currentDate = QDateTime::currentDateTime(); + auto checkedDate = QDateTime::fromMSecsSinceEpoch(application["update_checked_at"].toInt()); + if (currentDate.daysTo(checkedDate.addDays(1)) <= 0) { + emit checkAllFinished(); + return; + } } // Clear data @@ -83,12 +84,14 @@ void UpdateHandler::checkAll() void UpdateHandler::update(const QString &fileKey) { if (configHandler_->getUsrConfigUpdateAvailable().contains(fileKey)) { - auto updateAvailableFile = configHandler_->getUsrConfigUpdateAvailable()[fileKey].toObject(); + auto updateMethod = configHandler_->getUsrConfigUpdateAvailable()[fileKey].toObject()["update_method"].toString(); #ifdef QTLIB_UNIX - if (updateAvailableFile["update_method"].toString() == "appimageupdate") { + if (updateMethod == "appimageupdate") { updateAppImage(fileKey); } + //else if (updateMethod == "appimageupdatewithocsapi") { + //} #endif } } @@ -127,7 +130,7 @@ void UpdateHandler::updateAppImage(const QString &fileKey) auto updateInformation = describeAppImage(path); for (const auto &info : updateInformation.split("\n")) { if (info.endsWith(".zsync", Qt::CaseInsensitive)) { - newFilename = info.replace(".zsync", "", Qt::CaseInsensitive).split("/").last(); + newFilename = info.split("|").last().split("/").last().replace(".zsync", "", Qt::CaseInsensitive); break; } } @@ -137,7 +140,7 @@ void UpdateHandler::updateAppImage(const QString &fileKey) emit updateStarted(fileKey); while (!appImageUpdater.isDone()) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + QThread::msleep(100); double progress; if (appImageUpdater.progress(progress)) { emit updateProgress(fileKey, progress * 100); @@ -163,6 +166,12 @@ void UpdateHandler::updateAppImage(const QString &fileKey) configHandler_->removeUsrConfigUpdateAvailableFile(fileKey); } + else { + std::string nextMessage; + while (appImageUpdater.nextStatusMessage(nextMessage)) { + qWarning() << QString::fromStdString(nextMessage); + } + } emit updateFinished(fileKey); } diff --git a/app/src/main.cpp b/app/src/main.cpp index 6bb8c551c402f010114bfd5d6fbf94503449f6bd..8dca2326d7a819830d57a0aff714f57922c17f18 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) QObject::connect(wsServer, &WebSocketServer::stopped, &app, &QGuiApplication::quit); if (wsServer->start()) { - qDebug() << "Websocket server started at:" << wsServer->serverUrl().toString(); + qInfo() << "Websocket server started at:" << wsServer->serverUrl().toString(); } else { qCritical() << "Failed to start websocket server:" << wsServer->errorString(); diff --git a/app/src/websockets/websocketserver.cpp b/app/src/websockets/websocketserver.cpp index 85732e3777e3ee82b87022d631add3596926f4c7..6a135b1e1ce597be1d1717178ac3dd99140b093b 100644 --- a/app/src/websockets/websocketserver.cpp +++ b/app/src/websockets/websocketserver.cpp @@ -202,13 +202,13 @@ void WebSocketServer::itemUninstallFinished(QJsonObject result) void WebSocketServer::updateCheckAllStarted() { QJsonArray data; - sendMessage("", "ItemHandler::checkAllStarted", data); + sendMessage("", "UpdateHandler::checkAllStarted", data); } void WebSocketServer::updateCheckAllFinished() { QJsonArray data; - sendMessage("", "ItemHandler::checkAllFinished", data); + sendMessage("", "UpdateHandler::checkAllFinished", data); } void WebSocketServer::updateUpdateStarted(QString fileKey)