From 2aaafae1bd40d321c66fe2747ac34b8798740dfd Mon Sep 17 00:00:00 2001 From: Probal Basak Date: Wed, 20 Oct 2021 22:18:28 +0530 Subject: [PATCH] Changes #91: - Added QAppImageUpdate library support for updating appimage - Added update button to AppView qml - Added update appimage functionality to appmodel --- CMakeLists.txt | 3 +- src/CMakeLists.txt | 2 +- src/models/appsmodel.cpp | 50 ++++++++++++++++++++++++++++++++++ src/models/appsmodel.h | 15 ++++++++++ src/ui/views/apps/AppsView.qml | 44 ++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad5078ad..210140c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ include(ECMQMLModules) find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE COMPONENTS Widgets Qml Quick) find_package(KF5 ${REQUIRED_KF5_VERSION} REQUIRED COMPONENTS I18n CoreAddons) +find_package(QAppImageUpdate) find_package(libappimage REQUIRED) find_package(MauiKit REQUIRED) @@ -83,5 +84,5 @@ ecm_setup_version(${NX_SC_VERSION} ) add_subdirectory(src) - + feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 95d7674e..216b85dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,7 +72,7 @@ add_executable(${PROJECT_NAME} kde_source_files_enable_exceptions(${PROJECT_NAME} utils/appimagetools.cpp) -target_link_libraries(${PROJECT_NAME} MauiKit MauiKit::FileBrowsing Qt5::Widgets Qt5::Qml KF5::I18n KF5::CoreAddons libappimage) +target_link_libraries(${PROJECT_NAME} MauiKit MauiKit::FileBrowsing Qt5::Widgets Qt5::Qml KF5::I18n KF5::CoreAddons libappimage QAppImageUpdate) install(TARGETS ${PROJECT_NAME} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES org.nx.softwarecenter.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) diff --git a/src/models/appsmodel.cpp b/src/models/appsmodel.cpp index 1ee5d425..43b5f188 100644 --- a/src/models/appsmodel.cpp +++ b/src/models/appsmodel.cpp @@ -42,6 +42,25 @@ void AppsModel::launchApp(const int &index) FMStatic::openUrl(url); } +void AppsModel::updateApp(const int &index) +{ + + const auto url = this->get(index).value("url").toUrl(); + qDebug() << "try to update appimage" << url; + + QString appImagePath = QString(url.toLocalFile()); + qDebug() << appImagePath; + + updater = new QAppImageUpdate(appImagePath, /*singleThreaded=*/false, /*parent=*/this); + + connect(updater, &QAppImageUpdate::error, this, &AppsModel::handleError); + connect(updater, &QAppImageUpdate::finished, this, &AppsModel::handleFinished); + + updater->setShowLog(false); + + updater->start(QAppImageUpdate::Action::CheckForUpdate); /* Check for update. */ +} + void AppsModel::removeApp(const int &index) { const auto url = this->get(index).value("url").toUrl(); @@ -99,3 +118,34 @@ void AppsModel::clear() emit this->countChanged(); } +void AppsModel::handleError(short errorCode, short action) +{ + if(action == QAppImageUpdate::Action::Update) { + qInfo() << "AppsModel::handleError # " << QAppImageUpdate::errorCodeToString(errorCode); + emit appUpdateError("AppImage update error.\n\nError Message:"+QAppImageUpdate::errorCodeToString(errorCode)); + } else if ( action == QAppImageUpdate::Action::CheckForUpdate ) { + qInfo() << "AppsModel::handleError # " << QAppImageUpdate::errorCodeToString(errorCode); + emit appUpdateError("AppImage check for update error.\n\nError Message:"+QAppImageUpdate::errorCodeToString(errorCode)); + } + + return; +} + +void AppsModel::handleFinished(QJsonObject info, short action) +{ + if(action == QAppImageUpdate::Action::Update) { + qInfo() << "AppsModel::handleFinished # Update:: " << info; + emit appUpdateSuccess("AppImage updated successfully."); + } else if(action == QAppImageUpdate::Action::CheckForUpdate) { + qInfo() << "AppsModel::handleFinished # CheckForUpdate:: " << info; + + if ( info.value("UpdateAvailable") == true ) { + updater->start(QAppImageUpdate::Action::Update); /* Start the update. */ + } else { + qInfo() << "AppsModel::handleFinished # AppImage is already updated and latest"; + emit appUpdateError("AppImage is already updated and latest."); + } + } + + return; +} \ No newline at end of file diff --git a/src/models/appsmodel.h b/src/models/appsmodel.h index 008eed12..cd8b0121 100644 --- a/src/models/appsmodel.h +++ b/src/models/appsmodel.h @@ -5,6 +5,8 @@ #include +#include + class QFileSystemWatcher; class Store; @@ -13,7 +15,11 @@ class AppsModel : public MauiList { Q_OBJECT + // Q_PROPERTY(bool isUpdatable MEMBER m_isUpdatable NOTIFY isUpdatableChanged) + public: + // bool m_isUpdatable = false; + explicit AppsModel(QObject *parent = nullptr); // QQmlParserStatus interface @@ -25,9 +31,14 @@ class AppsModel : public MauiList void appLaunchSuccess(); void appLaunchError(int err); void appDeleteSuccess(); + void appUpdateSuccess(QString msg); + void appUpdateError(QString msg); + + // void isUpdatableChanged(bool isUpdatable); public slots: void launchApp(const int &index); + void updateApp(const int &index); void removeApp(const int &index); void resfresh(); @@ -36,11 +47,15 @@ public slots: QHash m_app; Store *m_store; QFileSystemWatcher * m_watcher; + QAppImageUpdate *updater; void setList(); void unintegrate(const QUrl &url); void clear(); + + void handleError(short errorCode, short action); + void handleFinished(QJsonObject info, short action); }; #endif // APPSMODEL_H diff --git a/src/ui/views/apps/AppsView.qml b/src/ui/views/apps/AppsView.qml index e8d4c0e7..39eb6dfb 100644 --- a/src/ui/views/apps/AppsView.qml +++ b/src/ui/views/apps/AppsView.qml @@ -44,6 +44,27 @@ Maui.Page } } + Maui.Dialog + { + id: appUpdateDialog + + title: i18n("AppImage Update") + message: i18n("Please wait...") + rejectButton.visible: false + + acceptButton.onClicked: + { + appUpdateDialog.visible = false; + } + + function showDialog(fileName, status) + { + message = status + + appUpdateDialog.visible = true; + } + } + Maui.Dialog { id: appRemoveDialog @@ -203,6 +224,16 @@ Maui.Page } }, Action + { + icon.name: "download" + // enabled: _appsList.isUpdatable + onTriggered: + { + _appsListView.currentIndex = index; + _appsList.updateApp(_appsModel.mappedToSource(index)); + } + }, + Action { icon.name: "entry-delete" onTriggered: @@ -233,6 +264,19 @@ Maui.Page function onAppDeleteSuccess() { appRemoveDialog.visible = false; } + + function onAppUpdateSuccess(msg) { + console.log("AppImage updated successfully."); + + appUpdateDialog.showDialog(_appsListView.model.get(_appsListView.currentIndex).path.split("/").pop(), + msg); + } + + function onAppUpdateError(err) { + console.log("AppImage update error."); + appUpdateDialog.showDialog(_appsListView.model.get(_appsListView.currentIndex).path.split("/").pop(), + err); + } } }