Skip to content
Snippets Groups Projects
Commit fba624a3 authored by akiraohgaki's avatar akiraohgaki
Browse files

Fix

parent 3fd6b73c
No related branches found
No related tags found
No related merge requests found
...@@ -5,11 +5,10 @@ ...@@ -5,11 +5,10 @@
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
#include <QDateTime> #include <QDateTime>
#include <QThread>
#include <QDebug>
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
#include <thread>
#include <chrono>
#include "appimage/update.h" #include "appimage/update.h"
#endif #endif
...@@ -28,11 +27,13 @@ void UpdateHandler::checkAll() ...@@ -28,11 +27,13 @@ void UpdateHandler::checkAll()
auto application = configHandler_->getUsrConfigApplication(); auto application = configHandler_->getUsrConfigApplication();
auto installedItems = configHandler_->getUsrConfigInstalledItems(); auto installedItems = configHandler_->getUsrConfigInstalledItems();
if (installedItems.isEmpty() if (installedItems.isEmpty() || application.contains("update_checked_at")) {
|| (application.contains("update_checked_at") auto currentDate = QDateTime::currentDateTime();
&& application["update_checked_at"].toInt() + (1000 * 60 * 60 * 24) > QDateTime::currentMSecsSinceEpoch())) { auto checkedDate = QDateTime::fromMSecsSinceEpoch(application["update_checked_at"].toInt());
emit checkAllFinished(); if (currentDate.daysTo(checkedDate.addDays(1)) <= 0) {
return; emit checkAllFinished();
return;
}
} }
// Clear data // Clear data
...@@ -83,12 +84,14 @@ void UpdateHandler::checkAll() ...@@ -83,12 +84,14 @@ void UpdateHandler::checkAll()
void UpdateHandler::update(const QString &fileKey) void UpdateHandler::update(const QString &fileKey)
{ {
if (configHandler_->getUsrConfigUpdateAvailable().contains(fileKey)) { if (configHandler_->getUsrConfigUpdateAvailable().contains(fileKey)) {
auto updateAvailableFile = configHandler_->getUsrConfigUpdateAvailable()[fileKey].toObject(); auto updateMethod = configHandler_->getUsrConfigUpdateAvailable()[fileKey].toObject()["update_method"].toString();
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
if (updateAvailableFile["update_method"].toString() == "appimageupdate") { if (updateMethod == "appimageupdate") {
updateAppImage(fileKey); updateAppImage(fileKey);
} }
//else if (updateMethod == "appimageupdatewithocsapi") {
//}
#endif #endif
} }
} }
...@@ -127,7 +130,7 @@ void UpdateHandler::updateAppImage(const QString &fileKey) ...@@ -127,7 +130,7 @@ void UpdateHandler::updateAppImage(const QString &fileKey)
auto updateInformation = describeAppImage(path); auto updateInformation = describeAppImage(path);
for (const auto &info : updateInformation.split("\n")) { for (const auto &info : updateInformation.split("\n")) {
if (info.endsWith(".zsync", Qt::CaseInsensitive)) { 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; break;
} }
} }
...@@ -137,7 +140,7 @@ void UpdateHandler::updateAppImage(const QString &fileKey) ...@@ -137,7 +140,7 @@ void UpdateHandler::updateAppImage(const QString &fileKey)
emit updateStarted(fileKey); emit updateStarted(fileKey);
while (!appImageUpdater.isDone()) { while (!appImageUpdater.isDone()) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); QThread::msleep(100);
double progress; double progress;
if (appImageUpdater.progress(progress)) { if (appImageUpdater.progress(progress)) {
emit updateProgress(fileKey, progress * 100); emit updateProgress(fileKey, progress * 100);
...@@ -163,6 +166,12 @@ void UpdateHandler::updateAppImage(const QString &fileKey) ...@@ -163,6 +166,12 @@ void UpdateHandler::updateAppImage(const QString &fileKey)
configHandler_->removeUsrConfigUpdateAvailableFile(fileKey); configHandler_->removeUsrConfigUpdateAvailableFile(fileKey);
} }
else {
std::string nextMessage;
while (appImageUpdater.nextStatusMessage(nextMessage)) {
qWarning() << QString::fromStdString(nextMessage);
}
}
emit updateFinished(fileKey); emit updateFinished(fileKey);
} }
......
...@@ -51,7 +51,7 @@ int main(int argc, char *argv[]) ...@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
QObject::connect(wsServer, &WebSocketServer::stopped, &app, &QGuiApplication::quit); QObject::connect(wsServer, &WebSocketServer::stopped, &app, &QGuiApplication::quit);
if (wsServer->start()) { if (wsServer->start()) {
qDebug() << "Websocket server started at:" << wsServer->serverUrl().toString(); qInfo() << "Websocket server started at:" << wsServer->serverUrl().toString();
} }
else { else {
qCritical() << "Failed to start websocket server:" << wsServer->errorString(); qCritical() << "Failed to start websocket server:" << wsServer->errorString();
......
...@@ -202,13 +202,13 @@ void WebSocketServer::itemUninstallFinished(QJsonObject result) ...@@ -202,13 +202,13 @@ void WebSocketServer::itemUninstallFinished(QJsonObject result)
void WebSocketServer::updateCheckAllStarted() void WebSocketServer::updateCheckAllStarted()
{ {
QJsonArray data; QJsonArray data;
sendMessage("", "ItemHandler::checkAllStarted", data); sendMessage("", "UpdateHandler::checkAllStarted", data);
} }
void WebSocketServer::updateCheckAllFinished() void WebSocketServer::updateCheckAllFinished()
{ {
QJsonArray data; QJsonArray data;
sendMessage("", "ItemHandler::checkAllFinished", data); sendMessage("", "UpdateHandler::checkAllFinished", data);
} }
void WebSocketServer::updateUpdateStarted(QString fileKey) void WebSocketServer::updateUpdateStarted(QString fileKey)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment