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

Check updater progress

parent d0621900
Branches
Tags
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <QJsonValue> #include <QJsonValue>
#include <QJsonArray> #include <QJsonArray>
#include <QDateTime> #include <QDateTime>
//#include <QThread>
#include "qtlib_file.h" #include "qtlib_file.h"
...@@ -106,6 +107,7 @@ void UpdateHandler::appImageUpdaterFinished(AppImageUpdater *updater) ...@@ -106,6 +107,7 @@ void UpdateHandler::appImageUpdaterFinished(AppImageUpdater *updater)
if (!updater->isFinishedWithNoError()) { if (!updater->isFinishedWithNoError()) {
emit updateFinished(itemKey, false); emit updateFinished(itemKey, false);
updater->deleteLater();
return; return;
} }
...@@ -129,6 +131,7 @@ void UpdateHandler::appImageUpdaterFinished(AppImageUpdater *updater) ...@@ -129,6 +131,7 @@ void UpdateHandler::appImageUpdaterFinished(AppImageUpdater *updater)
configHandler_->removeUsrConfigUpdateAvailableItemsItem(itemKey); configHandler_->removeUsrConfigUpdateAvailableItemsItem(itemKey);
emit updateFinished(itemKey, true); emit updateFinished(itemKey, true);
updater->deleteLater();
} }
#endif #endif
...@@ -147,11 +150,17 @@ void UpdateHandler::updateAppImage(const QString &itemKey) ...@@ -147,11 +150,17 @@ void UpdateHandler::updateAppImage(const QString &itemKey)
auto installedItem = installedItems[installedItemKey].toObject(); auto installedItem = installedItems[installedItemKey].toObject();
auto filename = installedItem["filename"].toString(); auto filename = installedItem["filename"].toString();
auto installType = installedItem["install_type"].toString(); auto installType = installedItem["install_type"].toString();
auto filePath = configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString() + "/" + filename; auto filePath = configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString() + "/" + filename;
//auto *thread = new QThread(this);
auto *updater = new AppImageUpdater(itemKey, filePath, this); auto *updater = new AppImageUpdater(itemKey, filePath, this);
//updater->moveToThread(thread);
//connect(thread, &QThread::started, updater, &AppImageUpdater::updateAppImage);
connect(updater, &AppImageUpdater::updateProgress, this, &UpdateHandler::updateProgress); connect(updater, &AppImageUpdater::updateProgress, this, &UpdateHandler::updateProgress);
connect(updater, &AppImageUpdater::finished, this, &UpdateHandler::appImageUpdaterFinished); connect(updater, &AppImageUpdater::finished, this, &UpdateHandler::appImageUpdaterFinished);
//connect(updater, &AppImageUpdater::finished, thread, &QThread::quit);
//connect(thread, &QThread::finished, thread, &QThread::deleteLater);
QJsonObject metadata; QJsonObject metadata;
metadata["installed_item_key"] = installedItemKey; metadata["installed_item_key"] = installedItemKey;
...@@ -170,5 +179,6 @@ void UpdateHandler::updateAppImage(const QString &itemKey) ...@@ -170,5 +179,6 @@ void UpdateHandler::updateAppImage(const QString &itemKey)
emit updateStarted(itemKey, true); emit updateStarted(itemKey, true);
updater->updateAppImage(); updater->updateAppImage();
//thread->start();
} }
#endif #endif
#include "appimageupdater.h" #include "appimageupdater.h"
#include <QThread> #include <QTimer>
#include "appimage/update.h" #include "appimage/update.h"
...@@ -9,6 +9,12 @@ AppImageUpdater::AppImageUpdater(const QString &id, const QString &path, QObject ...@@ -9,6 +9,12 @@ AppImageUpdater::AppImageUpdater(const QString &id, const QString &path, QObject
{ {
isFinishedWithNoError_ = false; isFinishedWithNoError_ = false;
errorString_ = ""; errorString_ = "";
updater_ = new appimage::update::Updater(path_.toStdString(), false);
}
AppImageUpdater::~AppImageUpdater()
{
delete updater_;
} }
QString AppImageUpdater::id() const QString AppImageUpdater::id() const
...@@ -21,19 +27,27 @@ QString AppImageUpdater::path() const ...@@ -21,19 +27,27 @@ QString AppImageUpdater::path() const
return path_; return path_;
} }
bool AppImageUpdater::isFinishedWithNoError() const
{
return isFinishedWithNoError_;
}
QString AppImageUpdater::errorString() const
{
return errorString_;
}
QString AppImageUpdater::describeAppImage() const QString AppImageUpdater::describeAppImage() const
{ {
std::string description = ""; std::string description = "";
appimage::update::Updater updater(path_.toStdString()); updater_.describeAppImage(description);
updater.describeAppImage(description);
return QString::fromStdString(description); return QString::fromStdString(description);
} }
bool AppImageUpdater::checkAppImage() const bool AppImageUpdater::checkAppImage() const
{ {
bool updateAvailable = false; bool updateAvailable = false;
appimage::update::Updater updater(path_.toStdString()); updater_.checkForChanges(updateAvailable);
updater.checkForChanges(updateAvailable);
return updateAvailable; return updateAvailable;
} }
...@@ -41,24 +55,31 @@ void AppImageUpdater::updateAppImage() ...@@ -41,24 +55,31 @@ void AppImageUpdater::updateAppImage()
{ {
isFinishedWithNoError_ = false; isFinishedWithNoError_ = false;
errorString_ = ""; errorString_ = "";
appimage::update::Updater updater(path_.toStdString(), false);
if (!updater.start()) { if (!updater_.start()) {
emit finished(this); emit finished(this);
return; return;
} }
while (!updater.isDone()) { auto timer = new QTimer(this);
QThread::msleep(100); connect(timer, &QTimer::timeout, this, &AppImageUpdater::checkUpdaterProgress);
connect(this, &AppImageUpdater::finished, timer, &QTimer::stop);
timer->start(100);
}
void AppImageUpdater::checkUpdaterProgress()
{
if (!updater_->isDone()) {
double progress; double progress;
if (updater.progress(progress)) { if (updater_.progress(progress)) {
emit updateProgress(id_, progress); emit updateProgress(id_, progress);
} }
return;
} }
if (updater.hasError()) { if (updater_.hasError()) {
std::string message; std::string message;
while (updater.nextStatusMessage(message)) { while (updater_.nextStatusMessage(message)) {
errorString_ += QString::fromStdString(message) + "\n"; errorString_ += QString::fromStdString(message) + "\n";
} }
emit finished(this); emit finished(this);
...@@ -68,13 +89,3 @@ void AppImageUpdater::updateAppImage() ...@@ -68,13 +89,3 @@ void AppImageUpdater::updateAppImage()
isFinishedWithNoError_ = true; isFinishedWithNoError_ = true;
emit finished(this); emit finished(this);
} }
bool AppImageUpdater::isFinishedWithNoError() const
{
return isFinishedWithNoError_;
}
QString AppImageUpdater::errorString() const
{
return errorString_;
}
...@@ -2,29 +2,40 @@ ...@@ -2,29 +2,40 @@
#include <QObject> #include <QObject>
namespace appimage {
namespace update {
class Updater;
}
}
class AppImageUpdater : public QObject class AppImageUpdater : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AppImageUpdater(const QString &id, const QString &path, QObject *parent = nullptr); explicit AppImageUpdater(const QString &id, const QString &path, QObject *parent = nullptr);
~AppImageUpdater();
QString id() const; QString id() const;
QString path() const; QString path() const;
bool isFinishedWithNoError() const;
QString errorString() const;
QString describeAppImage() const; QString describeAppImage() const;
bool checkAppImage() const; bool checkAppImage() const;
void updateAppImage(); void updateAppImage();
bool isFinishedWithNoError() const;
QString errorString() const;
signals: signals:
void finished(AppImageUpdater *updater); void finished(AppImageUpdater *updater);
void updateProgress(QString id, double progress); void updateProgress(QString id, double progress);
private slots:
void checkUpdaterProgress();
private: private:
QString id_; QString id_;
QString path_; QString path_;
bool isFinishedWithNoError_; bool isFinishedWithNoError_;
QString errorString_; QString errorString_;
appimage::update::Updater *updater_;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment