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