Skip to content
Snippets Groups Projects
Unverified Commit 8b60821f authored by akiraohgaki's avatar akiraohgaki Committed by GitHub
Browse files

Merge pull request #17 from opendesktop/develop

Develop
parents 3dfd4d75 5a1435ac
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ unix:!ios:!android { ...@@ -33,6 +33,7 @@ unix:!ios:!android {
QT += dbus QT += dbus
HEADERS += \ HEADERS += \
$${PWD}/src/updaters/appimageupdater.h \
$${PWD}/src/desktopthemes/kdetheme.h \ $${PWD}/src/desktopthemes/kdetheme.h \
$${PWD}/src/desktopthemes/gnometheme.h \ $${PWD}/src/desktopthemes/gnometheme.h \
$${PWD}/src/desktopthemes/xfcetheme.h \ $${PWD}/src/desktopthemes/xfcetheme.h \
...@@ -40,6 +41,7 @@ unix:!ios:!android { ...@@ -40,6 +41,7 @@ unix:!ios:!android {
$${PWD}/src/desktopthemes/matetheme.h $${PWD}/src/desktopthemes/matetheme.h
SOURCES += \ SOURCES += \
$${PWD}/src/updaters/appimageupdater.cpp \
$${PWD}/src/desktopthemes/kdetheme.cpp \ $${PWD}/src/desktopthemes/kdetheme.cpp \
$${PWD}/src/desktopthemes/gnometheme.cpp \ $${PWD}/src/desktopthemes/gnometheme.cpp \
$${PWD}/src/desktopthemes/xfcetheme.cpp \ $${PWD}/src/desktopthemes/xfcetheme.cpp \
......
{ {
"id": "ocs-manager", "id": "ocs-manager",
"name": "ocs-manager", "name": "ocs-manager",
"version": "0.5.0", "version": "0.5.1",
"organization": "Opendesktop.org", "organization": "Opendesktop.org",
"domain": "org.opendesktop.ocs-manager", "domain": "org.opendesktop.ocs-manager",
"icon": ":/desktop/ocs-manager.svg", "icon": ":/desktop/ocs-manager.svg",
......
...@@ -3,27 +3,22 @@ ...@@ -3,27 +3,22 @@
#include <QStringList> #include <QStringList>
#include <QJsonValue> #include <QJsonValue>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject>
#include <QDateTime> #include <QDateTime>
#include <QThread>
#include <QDebug>
#ifdef QTLIB_UNIX
#include "appimage/update.h"
#endif
#include "qtlib_file.h" #include "qtlib_file.h"
#include "handlers/confighandler.h" #include "handlers/confighandler.h"
#ifdef QTLIB_UNIX
#include "updaters/appimageupdater.h"
#endif
UpdateHandler::UpdateHandler(ConfigHandler *configHandler, QObject *parent) UpdateHandler::UpdateHandler(ConfigHandler *configHandler, QObject *parent)
: QObject(parent), configHandler_(configHandler) : QObject(parent), configHandler_(configHandler)
{} {}
void UpdateHandler::checkAll() void UpdateHandler::checkAll()
{ {
emit checkAllStarted();
// Resets data // Resets data
QJsonObject updateAvailableItems; QJsonObject updateAvailableItems;
configHandler_->setUsrConfigUpdateAvailableItems(updateAvailableItems); configHandler_->setUsrConfigUpdateAvailableItems(updateAvailableItems);
...@@ -31,32 +26,34 @@ void UpdateHandler::checkAll() ...@@ -31,32 +26,34 @@ void UpdateHandler::checkAll()
auto installedItems = configHandler_->getUsrConfigInstalledItems(); auto installedItems = configHandler_->getUsrConfigInstalledItems();
if (installedItems.isEmpty()) { if (installedItems.isEmpty()) {
emit checkAllFinished(); emit checkAllStarted(false);
return; return;
} }
emit checkAllStarted(true);
for (const auto &itemKey : installedItems.keys()) { for (const auto &itemKey : installedItems.keys()) {
auto installedItem = installedItems[itemKey].toObject(); auto installedItem = installedItems[itemKey].toObject();
auto filename = installedItem["filename"].toString(); auto filename = installedItem["filename"].toString();
auto installType = installedItem["install_type"].toString(); auto installType = installedItem["install_type"].toString();
qtlib::File file; QString filePath = "";
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
file.setPath(configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString() + "/" + filename); filePath = configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString() + "/" + filename;
#else #else
file.setPath(configHandler_->getAppConfigInstallTypes()[installType].toObject()["generic_destination"].toString() + "/" + filename); filePath = configHandler_->getAppConfigInstallTypes()[installType].toObject()["generic_destination"].toString() + "/" + filename;
#endif #endif
QString updateMethod = ""; QString updateMethod = "";
if (installType == "bin") { if (installType == "bin") {
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
if (file.path().endsWith(".appimage", Qt::CaseInsensitive)) { if (filePath.endsWith(".appimage", Qt::CaseInsensitive)) {
if (checkAppImage(file.path())) { if (AppImageUpdater(itemKey, filePath).checkForChanges()) {
updateMethod = "appimageupdate"; updateMethod = "appimageupdate";
} }
//else if (checkAppImageWithOcsApi(itemKey)) { //else if (OcsFileUpdater(url).checkFile()) {
// updateMethod = "appimageupdatewithocsapi"; // updateMethod = "appimageupdate_ocs";
//} //}
} }
#endif #endif
...@@ -75,7 +72,7 @@ void UpdateHandler::checkAll() ...@@ -75,7 +72,7 @@ void UpdateHandler::checkAll()
application["update_checked_at"] = QDateTime::currentMSecsSinceEpoch(); application["update_checked_at"] = QDateTime::currentMSecsSinceEpoch();
configHandler_->setUsrConfigApplication(application); configHandler_->setUsrConfigApplication(application);
emit checkAllFinished(); emit checkAllFinished(true);
} }
void UpdateHandler::update(const QString &itemKey) void UpdateHandler::update(const QString &itemKey)
...@@ -83,6 +80,7 @@ void UpdateHandler::update(const QString &itemKey) ...@@ -83,6 +80,7 @@ void UpdateHandler::update(const QString &itemKey)
auto updateAvailableItems = configHandler_->getUsrConfigUpdateAvailableItems(); auto updateAvailableItems = configHandler_->getUsrConfigUpdateAvailableItems();
if (!updateAvailableItems.contains(itemKey)) { if (!updateAvailableItems.contains(itemKey)) {
emit updateStarted(itemKey, false);
return; return;
} }
...@@ -92,34 +90,51 @@ void UpdateHandler::update(const QString &itemKey) ...@@ -92,34 +90,51 @@ void UpdateHandler::update(const QString &itemKey)
if (updateMethod == "appimageupdate") { if (updateMethod == "appimageupdate") {
updateAppImage(itemKey); updateAppImage(itemKey);
} }
//else if (updateMethod == "appimageupdatewithocsapi") { //else if (updateMethod == "appimageupdate_ocs") {
// updateAppImageWithOcsApi(itemKey); // updateAppImageOcs(itemKey);
//} //}
#endif #endif
} }
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
QString UpdateHandler::describeAppImage(const QString &path) const void UpdateHandler::appImageUpdaterFinished(AppImageUpdater *updater)
{ {
appimage::update::Updater appImageUpdater(path.toStdString()); auto itemKey = updater->id();
QString updateInformation;
std::string description; auto metadata = metadataSet_[itemKey].toObject();
if (appImageUpdater.describeAppImage(description)) { metadataSet_.remove(itemKey);
updateInformation = QString::fromStdString(description);
if (!updater->isFinishedWithNoError()) {
emit updateFinished(itemKey, false);
updater->deleteLater();
return;
} }
return updateInformation;
}
bool UpdateHandler::checkAppImage(const QString &path) const auto installedItemKey = metadata["installed_item_key"].toString();
{ auto installedItem = metadata["installed_item_obj"].toObject();
appimage::update::Updater appImageUpdater(path.toStdString()); auto newFilename = metadata["new_filename"].toString();
bool updateAvailable; auto filename = installedItem["filename"].toString();
if (appImageUpdater.checkForChanges(updateAvailable)) {
return updateAvailable; installedItem["filename"] = newFilename;
QJsonArray files;
files.append(QJsonValue(newFilename));
installedItem["files"] = files;
installedItem["installed_at"] = QDateTime::currentMSecsSinceEpoch();
configHandler_->setUsrConfigInstalledItemsItem(installedItemKey, installedItem);
if (newFilename != filename) {
qtlib::File(updater->path()).remove();
} }
return false;
configHandler_->removeUsrConfigUpdateAvailableItemsItem(itemKey);
emit updateFinished(itemKey, true);
updater->deleteLater();
} }
#endif
#ifdef QTLIB_UNIX
void UpdateHandler::updateAppImage(const QString &itemKey) void UpdateHandler::updateAppImage(const QString &itemKey)
{ {
auto updateAvailableItem = configHandler_->getUsrConfigUpdateAvailableItems()[itemKey].toObject(); auto updateAvailableItem = configHandler_->getUsrConfigUpdateAvailableItems()[itemKey].toObject();
...@@ -127,64 +142,35 @@ void UpdateHandler::updateAppImage(const QString &itemKey) ...@@ -127,64 +142,35 @@ void UpdateHandler::updateAppImage(const QString &itemKey)
auto installedItems = configHandler_->getUsrConfigInstalledItems(); auto installedItems = configHandler_->getUsrConfigInstalledItems();
if (!installedItems.contains(installedItemKey)) { if (!installedItems.contains(installedItemKey)) {
emit updateStarted(itemKey, false);
return; return;
} }
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 *updater = new AppImageUpdater(itemKey, filePath, this);
connect(updater, &AppImageUpdater::updateProgress, this, &UpdateHandler::updateProgress);
connect(updater, &AppImageUpdater::finished, this, &UpdateHandler::appImageUpdaterFinished);
qtlib::File file(configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString() + "/" + filename); QJsonObject metadata;
metadata["installed_item_key"] = installedItemKey;
metadata["installed_item_obj"] = installedItem;
metadata["new_filename"] = filename;
auto newFilename = filename; auto updateInformation = updater->describeAppImage();
auto updateInformation = describeAppImage(file.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.split("|").last().split("/").last().replace(".zsync", "", Qt::CaseInsensitive); metadata["new_filename"] = info.split("|").last().split("/").last().replace(".zsync", "", Qt::CaseInsensitive);
break; break;
} }
} }
appimage::update::Updater appImageUpdater(file.path().toStdString(), false); metadataSet_[itemKey] = metadata;
if (!appImageUpdater.start()) {
return;
}
emit updateStarted(itemKey);
while (!appImageUpdater.isDone()) {
QThread::msleep(100);
double progress;
if (appImageUpdater.progress(progress)) {
emit updateProgress(itemKey, progress * 100);
}
}
if (appImageUpdater.hasError()) {
std::string nextMessage;
while (appImageUpdater.nextStatusMessage(nextMessage)) {
qWarning() << QString::fromStdString(nextMessage);
}
emit updateFinished(itemKey);
return;
}
installedItem["filename"] = newFilename;
QJsonArray files;
files.append(QJsonValue(newFilename));
installedItem["files"] = files;
installedItem["installed_at"] = QDateTime::currentMSecsSinceEpoch();
configHandler_->setUsrConfigInstalledItemsItem(installedItemKey, installedItem);
if (newFilename != filename) {
file.remove();
}
configHandler_->removeUsrConfigUpdateAvailableItemsItem(itemKey);
emit updateFinished(itemKey); emit updateStarted(itemKey, true);
updater->start();
} }
#endif #endif
#pragma once #pragma once
#include <QObject> #include <QObject>
#include <QJsonObject>
class ConfigHandler; class ConfigHandler;
#ifdef QTLIB_UNIX
class AppImageUpdater;
#endif
class UpdateHandler : public QObject class UpdateHandler : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -12,22 +17,26 @@ public: ...@@ -12,22 +17,26 @@ public:
explicit UpdateHandler(ConfigHandler *configHandler, QObject *parent = nullptr); explicit UpdateHandler(ConfigHandler *configHandler, QObject *parent = nullptr);
signals: signals:
void checkAllStarted(); void checkAllStarted(bool status);
void checkAllFinished(); void checkAllFinished(bool status);
void updateStarted(QString itemKey); void updateStarted(QString itemKey, bool status);
void updateFinished(QString itemKey); void updateFinished(QString itemKey, bool status);
void updateProgress(QString itemKey, int progress); void updateProgress(QString itemKey, double progress);
public slots: public slots:
void checkAll(); void checkAll();
void update(const QString &itemKey); void update(const QString &itemKey);
private slots:
#ifdef QTLIB_UNIX
void appImageUpdaterFinished(AppImageUpdater *updater);
#endif
private: private:
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
QString describeAppImage(const QString &path) const;
bool checkAppImage(const QString &path) const;
void updateAppImage(const QString &itemKey); void updateAppImage(const QString &itemKey);
#endif #endif
ConfigHandler *configHandler_; ConfigHandler *configHandler_;
QJsonObject metadataSet_;
}; };
#include "appimageupdater.h"
#include <QTimer>
#include "appimage/update.h"
AppImageUpdater::AppImageUpdater(const QString &id, const QString &path, QObject *parent)
: QObject(parent), id_(id), path_(path)
{
isFinishedWithNoError_ = false;
errorString_ = "";
updater_ = new appimage::update::Updater(path_.toStdString(), false);
}
AppImageUpdater::~AppImageUpdater()
{
delete updater_;
}
QString AppImageUpdater::id() const
{
return id_;
}
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 = "";
updater_->describeAppImage(description);
return QString::fromStdString(description);
}
bool AppImageUpdater::checkForChanges() const
{
bool updateAvailable = false;
updater_->checkForChanges(updateAvailable);
return updateAvailable;
}
void AppImageUpdater::start()
{
isFinishedWithNoError_ = false;
errorString_ = "";
if (!updater_->start()) {
emit finished(this);
return;
}
auto timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &AppImageUpdater::checkProgress);
connect(this, &AppImageUpdater::finished, timer, &QTimer::stop);
timer->start(100);
}
void AppImageUpdater::checkProgress()
{
if (!updater_->isDone()) {
double progress;
if (updater_->progress(progress)) {
emit updateProgress(id_, progress);
}
return;
}
if (updater_->hasError()) {
std::string message;
while (updater_->nextStatusMessage(message)) {
errorString_ += QString::fromStdString(message) + "\n";
}
emit finished(this);
return;
}
isFinishedWithNoError_ = true;
emit finished(this);
}
#pragma once
#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 checkForChanges() const;
void start();
signals:
void finished(AppImageUpdater *updater);
void updateProgress(QString id, double progress);
private slots:
void checkProgress();
private:
QString id_;
QString path_;
bool isFinishedWithNoError_;
QString errorString_;
appimage::update::Updater *updater_;
};
...@@ -199,33 +199,37 @@ void WebSocketServer::itemUninstallFinished(QJsonObject result) ...@@ -199,33 +199,37 @@ void WebSocketServer::itemUninstallFinished(QJsonObject result)
sendMessage("", "ItemHandler::uninstallFinished", data); sendMessage("", "ItemHandler::uninstallFinished", data);
} }
void WebSocketServer::updateCheckAllStarted() void WebSocketServer::updateCheckAllStarted(bool status)
{ {
QJsonArray data; QJsonArray data;
data.append(status);
sendMessage("", "UpdateHandler::checkAllStarted", data); sendMessage("", "UpdateHandler::checkAllStarted", data);
} }
void WebSocketServer::updateCheckAllFinished() void WebSocketServer::updateCheckAllFinished(bool status)
{ {
QJsonArray data; QJsonArray data;
data.append(status);
sendMessage("", "UpdateHandler::checkAllFinished", data); sendMessage("", "UpdateHandler::checkAllFinished", data);
} }
void WebSocketServer::updateUpdateStarted(QString itemKey) void WebSocketServer::updateUpdateStarted(QString itemKey, bool status)
{ {
QJsonArray data; QJsonArray data;
data.append(itemKey); data.append(itemKey);
data.append(status);
sendMessage("", "UpdateHandler::updateStarted", data); sendMessage("", "UpdateHandler::updateStarted", data);
} }
void WebSocketServer::updateUpdateFinished(QString itemKey) void WebSocketServer::updateUpdateFinished(QString itemKey, bool status)
{ {
QJsonArray data; QJsonArray data;
data.append(itemKey); data.append(itemKey);
data.append(status);
sendMessage("", "UpdateHandler::updateFinished", data); sendMessage("", "UpdateHandler::updateFinished", data);
} }
void WebSocketServer::updateUpdateProgress(QString itemKey, int progress) void WebSocketServer::updateUpdateProgress(QString itemKey, double progress)
{ {
QJsonArray data; QJsonArray data;
data.append(itemKey); data.append(itemKey);
......
...@@ -51,11 +51,11 @@ private slots: ...@@ -51,11 +51,11 @@ private slots:
void itemUninstallStarted(QJsonObject result); void itemUninstallStarted(QJsonObject result);
void itemUninstallFinished(QJsonObject result); void itemUninstallFinished(QJsonObject result);
void updateCheckAllStarted(); void updateCheckAllStarted(bool status);
void updateCheckAllFinished(); void updateCheckAllFinished(bool status);
void updateUpdateStarted(QString itemKey); void updateUpdateStarted(QString itemKey, bool status);
void updateUpdateFinished(QString itemKey); void updateUpdateFinished(QString itemKey, bool status);
void updateUpdateProgress(QString itemKey, int progress); void updateUpdateProgress(QString itemKey, double progress);
private: private:
void receiveMessage(const QString &id, const QString &func, const QJsonArray &data); void receiveMessage(const QString &id, const QString &func, const QJsonArray &data);
......
#!/bin/sh #!/bin/sh
PKGNAME='ocs-manager' PKGNAME='ocs-manager'
PKGVER='0.5.0' PKGVER='0.5.1'
PKGREL='1' PKGREL='1'
curl -L -o linuxdeployqt "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage" curl -L -o linuxdeployqt "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment