From 6d6c1102c01a97f26fc91d5a11a28a3a0f5b6365 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Aug 2019 13:13:19 -0500 Subject: [PATCH 1/5] Only show actions if the dbus interfaces are available --- .../AppImageFileItemActions.cpp | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/fileitem-actions/AppImageFileItemActions.cpp b/src/fileitem-actions/AppImageFileItemActions.cpp index 492a476..1eac918 100644 --- a/src/fileitem-actions/AppImageFileItemActions.cpp +++ b/src/fileitem-actions/AppImageFileItemActions.cpp @@ -27,33 +27,36 @@ AppImageFileItemActions::AppImageFileItemActions(QObject* parent, const QVariant "/org/appimage/Services1/Updater", QDBusConnection::sessionBus(), this)) { - if (!launcherInterface->isValid()) - qWarning() << "Unable to connect to the AppImage Launcher Service"; - if (!updaterInterface->isValid()) - qWarning() << "Unable to connect to the AppImage Updater Service"; } QList AppImageFileItemActions::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) { QList actions; - - const QList urlList = fileItemInfos.urlList(); - if (urlList.size() == 1) { - if (launcherInterface->isRegistered(urlList.first().toString())) - actions += createRemoveFromMenuAction(fileItemInfos, parentWidget); - else + if (launcherInterface->isValid()) { + const QList urlList = fileItemInfos.urlList(); + if (urlList.size() == 1) { + if (launcherInterface->isRegistered(urlList.first().toString())) + actions += createRemoveFromMenuAction(fileItemInfos, parentWidget); + else + actions += createAddToMenuAction(fileItemInfos, parentWidget); + } else { actions += createAddToMenuAction(fileItemInfos, parentWidget); + actions += createRemoveFromMenuAction(fileItemInfos, parentWidget); + } } else { - actions += createAddToMenuAction(fileItemInfos, parentWidget); - actions += createRemoveFromMenuAction(fileItemInfos, parentWidget); + qWarning() << "Unable to connect to the AppImage Launcher Service"; } - QAction* updateAction = new QAction(QIcon::fromTheme("update-none"), "Update", parentWidget); - updateAction->setProperty("urls", QVariant::fromValue(fileItemInfos.urlList())); - updateAction->setProperty("parentWidget", QVariant::fromValue(parentWidget)); - connect(updateAction, &QAction::triggered, this, &AppImageFileItemActions::update); - actions += updateAction; + if (launcherInterface->isValid()) { + QAction* updateAction = new QAction(QIcon::fromTheme("update-none"), "Update", parentWidget); + updateAction->setProperty("urls", QVariant::fromValue(fileItemInfos.urlList())); + updateAction->setProperty("parentWidget", QVariant::fromValue(parentWidget)); + connect(updateAction, &QAction::triggered, this, &AppImageFileItemActions::update); + actions += updateAction; + } else { + qWarning() << "Unable to connect to the AppImage Updater Service"; + } return actions; } -- GitLab From 1af17332c7dbc5b8596ca77ef9840a9f34ee38cc Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Aug 2019 13:15:19 -0500 Subject: [PATCH 2/5] Download appimage-services only if there are updates --- dist/arch/plasma-appimage-integration-git.install | 13 ++++--------- dist/deb/postinst | 13 ++++--------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/dist/arch/plasma-appimage-integration-git.install b/dist/arch/plasma-appimage-integration-git.install index 9a9a074..d1a8765 100755 --- a/dist/arch/plasma-appimage-integration-git.install +++ b/dist/arch/plasma-appimage-integration-git.install @@ -6,16 +6,11 @@ post_install() { APPIMAGE_SERVICES_BIN_PATH=/usr/bin/appimage-services APPIMAGE_SERVICES_URL="https://www.opencode.net/azubieta/AppImageService/-/jobs/artifacts/master/raw/appimage-services-x86_64.AppImage?job=build:AppImage" - if [ -f "$APPIMAGE_SERVICES_BIN_PATH" ] - then - echo "Using appimamge-services bin from $APPIMAGE_SERVICES_BIN_PATH" - else - echo "Installing appimage-services to $APPIMAGE_SERVICES_BIN_PATH" - wget "$APPIMAGE_SERVICES_URL" -O "$APPIMAGE_SERVICES_BIN_PATH" + echo "Installing appimage-services to $APPIMAGE_SERVICES_BIN_PATH" + wget -N "$APPIMAGE_SERVICES_URL" -O "$APPIMAGE_SERVICES_BIN_PATH" - chmod +x "$APPIMAGE_SERVICES_BIN_PATH" - "$APPIMAGE_SERVICES_BIN_PATH" self-install - fi + chmod +x "$APPIMAGE_SERVICES_BIN_PATH" + "$APPIMAGE_SERVICES_BIN_PATH" self-install } ## arg 1: the old package version diff --git a/dist/deb/postinst b/dist/deb/postinst index 676310e..de626ec 100755 --- a/dist/deb/postinst +++ b/dist/deb/postinst @@ -4,13 +4,8 @@ set -e APPIMAGE_SERVICES_BIN_PATH=/usr/bin/appimage-services APPIMAGE_SERVICES_URL="https://www.opencode.net/azubieta/AppImageService/-/jobs/artifacts/master/raw/appimage-services-x86_64.AppImage?job=build:AppImage" -if [ -f "$APPIMAGE_SERVICES_BIN_PATH" ] -then - echo "Using appimamge-services bin from $APPIMAGE_SERVICES_BIN_PATH" -else - echo "Installing appimage-services to $APPIMAGE_SERVICES_BIN_PATH" - wget "$APPIMAGE_SERVICES_URL" -O "$APPIMAGE_SERVICES_BIN_PATH" +echo "Installing appimage-services to $APPIMAGE_SERVICES_BIN_PATH" +wget -N "$APPIMAGE_SERVICES_URL" -O "$APPIMAGE_SERVICES_BIN_PATH" - chmod +x "$APPIMAGE_SERVICES_BIN_PATH" - "$APPIMAGE_SERVICES_BIN_PATH" self-install -fi +chmod +x "$APPIMAGE_SERVICES_BIN_PATH" +"$APPIMAGE_SERVICES_BIN_PATH" self-install \ No newline at end of file -- GitLab From 18f5bd1e1725698aa867eb427c884554f67f2c9a Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Aug 2019 17:04:53 -0500 Subject: [PATCH 3/5] Add install command --- src/bin/CMakeLists.txt | 1 + src/bin/InstallJob.cpp | 34 +++++++++++++++++++ src/bin/InstallJob.h | 21 ++++++++++++ src/bin/main.cpp | 12 +++++++ .../AppImageFileItemActions.cpp | 27 +++++++++++++-- .../AppImageFileItemActions.h | 4 +++ 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/bin/InstallJob.cpp create mode 100644 src/bin/InstallJob.h diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt index 3e1d9ba..c4e916a 100644 --- a/src/bin/CMakeLists.txt +++ b/src/bin/CMakeLists.txt @@ -3,6 +3,7 @@ add_executable( main.cpp UpdateJob.cpp RemoveJob.cpp + InstallJob.cpp ) target_link_libraries(plasma-appimage-integration appimageservices-interfaces KF5::KIOWidgets KF5::I18n KF5::Notifications) diff --git a/src/bin/InstallJob.cpp b/src/bin/InstallJob.cpp new file mode 100644 index 0000000..171c73c --- /dev/null +++ b/src/bin/InstallJob.cpp @@ -0,0 +1,34 @@ +// libraries +#include +#include +#include +#include + +// local +#include "InstallJob.h" + +InstallJob::InstallJob(QString target, QObject* parent) : KJob(parent), target(std::move(target)) {} + +void InstallJob::start() { + process.setProgram("pkexec"); + process.setArguments({"appimage-services", "install", target}); + qDebug() << "calling pkexec appimage-services install " << target; + + connect(&process, SIGNAL(finished(int)), this, SLOT(onProcessFinished(int))); + description(this, i18n("Installing Application"), + qMakePair(i18nc("The AppImage being installed", "Source"), target)); + + process.start(); +} + +void InstallJob::onProcessFinished(int exitCode) { + qDebug() << exitCode; + qDebug() << process.errorString(); + if (exitCode != 0) { + setError(exitCode); + setErrorText(process.readAllStandardError()); + } + + // notify result delayed + QTimer::singleShot(1000, this, &InstallJob::emitResult); +} diff --git a/src/bin/InstallJob.h b/src/bin/InstallJob.h new file mode 100644 index 0000000..a33cb5f --- /dev/null +++ b/src/bin/InstallJob.h @@ -0,0 +1,21 @@ +#pragma once + +// libraries +#include +#include + +class InstallJob : public KJob { +Q_OBJECT +public: + explicit InstallJob(QString target, QObject* parent = nullptr); + + void start() override; + +protected slots: + + void onProcessFinished(int exitCode); + +private: + QString target; + QProcess process; +}; diff --git a/src/bin/main.cpp b/src/bin/main.cpp index 800efef..93c191c 100644 --- a/src/bin/main.cpp +++ b/src/bin/main.cpp @@ -11,6 +11,7 @@ // local #include "UpdateJob.h" #include "RemoveJob.h" +#include "InstallJob.h" QString parseTarget(QCommandLineParser& parser) { @@ -51,6 +52,13 @@ void executeRemoveCommand(const QString& target) { } +void executeInstallCommand(const QString& target) { + KJob* job = new InstallJob(target); + + KIO::getJobTracker()->registerJob(job); + job->start(); +} + int main(int argc, char** argv) { QApplication app(argc, argv); QApplication::setApplicationName("plasma-appimage-integration"); @@ -82,6 +90,10 @@ int main(int argc, char** argv) { executeRemoveCommand(target); } + if (command == "install") { + QString target = parseTarget(parser); + executeInstallCommand(target); + } return QApplication::exec(); } diff --git a/src/fileitem-actions/AppImageFileItemActions.cpp b/src/fileitem-actions/AppImageFileItemActions.cpp index 1eac918..8552cff 100644 --- a/src/fileitem-actions/AppImageFileItemActions.cpp +++ b/src/fileitem-actions/AppImageFileItemActions.cpp @@ -45,7 +45,7 @@ QList AppImageFileItemActions::actions(const KFileItemListProperties& actions += createRemoveFromMenuAction(fileItemInfos, parentWidget); } } else { - qWarning() << "Unable to connect to the AppImage Launcher Service"; + qWarning() << "Discarding AppImage Add/Remove to Menu actions. Unable to connect to the AppImage Launcher Service"; } if (launcherInterface->isValid()) { @@ -55,9 +55,11 @@ QList AppImageFileItemActions::actions(const KFileItemListProperties& connect(updateAction, &QAction::triggered, this, &AppImageFileItemActions::update); actions += updateAction; } else { - qWarning() << "Unable to connect to the AppImage Updater Service"; + qWarning() << "Discarding AppImage Update action. Unable to connect to the AppImage Launcher Updater"; } + actions += createInstallAction(fileItemInfos, parentWidget); + return actions; } @@ -81,6 +83,15 @@ QAction* AppImageFileItemActions::createAddToMenuAction(const KFileItemListPrope return addToMenuAction; } +QAction *AppImageFileItemActions::createInstallAction(const KFileItemListProperties &fileItemInfos, + QWidget *parentWidget) const { + QAction* installAction = new QAction(QIcon::fromTheme("install"), "Install", parentWidget); + installAction->setProperty("urls", QVariant::fromValue(fileItemInfos.urlList())); + installAction->setProperty("parentWidget", QVariant::fromValue(parentWidget)); + connect(installAction, &QAction::triggered, this, &AppImageFileItemActions::install); + return installAction; +} + void AppImageFileItemActions::addToMenu() { const QList urls = sender()->property("urls").value>(); QWidget* parentWidget = sender()->property("parentWidget").value(); @@ -123,6 +134,18 @@ void AppImageFileItemActions::update() { } } +void AppImageFileItemActions::install() { + const QList urls = sender()->property("urls").value>(); + QString program = "plasma-appimage-integration"; + + for (const QUrl& url : urls) { + QStringList arguments; + arguments << "install" << url.toLocalFile(); + + QProcess::startDetached(program, arguments); + } +} + void AppImageFileItemActions::showErrorMessage(const QString& title, const QString& message, QWidget* parentWidget) { KNotification* notify = new KNotification(QStringLiteral("notification"), parentWidget, KNotification::CloseOnTimeout | KNotification::DefaultEvent); diff --git a/src/fileitem-actions/AppImageFileItemActions.h b/src/fileitem-actions/AppImageFileItemActions.h index 505858f..6d49ae6 100644 --- a/src/fileitem-actions/AppImageFileItemActions.h +++ b/src/fileitem-actions/AppImageFileItemActions.h @@ -33,6 +33,8 @@ private Q_SLOTS: void update(); + void install(); + private: OrgAppimageServices1LauncherInterface* launcherInterface; OrgAppimageServices1UpdaterInterface* updaterInterface; @@ -42,4 +44,6 @@ private: QAction* createAddToMenuAction(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) const; QAction* createRemoveFromMenuAction(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) const; + + QAction* createInstallAction(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) const; }; -- GitLab From 4c17136c2c35d3078a031f161313af76e408bc8a Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Aug 2019 17:17:08 -0500 Subject: [PATCH 4/5] Add uninstall command --- res/AppImage Services.conf | 3 +++ src/bin/CMakeLists.txt | 1 + src/bin/UninstallJob.cpp | 34 ++++++++++++++++++++++++++++++++++ src/bin/UninstallJob.h | 21 +++++++++++++++++++++ src/bin/main.cpp | 13 +++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 src/bin/UninstallJob.cpp create mode 100644 src/bin/UninstallJob.h diff --git a/res/AppImage Services.conf b/res/AppImage Services.conf index 6d9f815..7efdc87 100644 --- a/res/AppImage Services.conf +++ b/res/AppImage Services.conf @@ -4,3 +4,6 @@ RemoveCommandArgs=remove %1 UpdateCommand=plasma-appimage-integration UpdateCommandArgs=update %1 + +UninstallCommand=plasma-appimage-integration +UninstallCommandArgs=uninstall %1 diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt index c4e916a..e268051 100644 --- a/src/bin/CMakeLists.txt +++ b/src/bin/CMakeLists.txt @@ -4,6 +4,7 @@ add_executable( UpdateJob.cpp RemoveJob.cpp InstallJob.cpp + UninstallJob.cpp ) target_link_libraries(plasma-appimage-integration appimageservices-interfaces KF5::KIOWidgets KF5::I18n KF5::Notifications) diff --git a/src/bin/UninstallJob.cpp b/src/bin/UninstallJob.cpp new file mode 100644 index 0000000..4b9ffd6 --- /dev/null +++ b/src/bin/UninstallJob.cpp @@ -0,0 +1,34 @@ +// libraries +#include +#include +#include +#include + +// local +#include "UninstallJob.h" + +UninstallJob::UninstallJob(QString target, QObject* parent) : KJob(parent), target(std::move(target)) {} + +void UninstallJob::start() { + process.setProgram("pkexec"); + process.setArguments({"appimage-services", "uninstall", target}); + qDebug() << "calling pkexec appimage-services install " << target; + + connect(&process, SIGNAL(finished(int)), this, SLOT(onProcessFinished(int))); + description(this, i18n("Uninstalling Application"), + qMakePair(i18nc("The AppImage being uninstalled", "Source"), target)); + + process.start(); +} + +void UninstallJob::onProcessFinished(int exitCode) { + qDebug() << exitCode; + qDebug() << process.errorString(); + if (exitCode != 0) { + setError(exitCode); + setErrorText(process.readAllStandardError()); + } + + // notify result delayed + QTimer::singleShot(1000, this, &UninstallJob::emitResult); +} diff --git a/src/bin/UninstallJob.h b/src/bin/UninstallJob.h new file mode 100644 index 0000000..d72bf8a --- /dev/null +++ b/src/bin/UninstallJob.h @@ -0,0 +1,21 @@ +#pragma once + +// libraries +#include +#include + +class UninstallJob : public KJob { +Q_OBJECT +public: + explicit UninstallJob(QString target, QObject* parent = nullptr); + + void start() override; + +protected slots: + + void onProcessFinished(int exitCode); + +private: + QString target; + QProcess process; +}; diff --git a/src/bin/main.cpp b/src/bin/main.cpp index 93c191c..22b809c 100644 --- a/src/bin/main.cpp +++ b/src/bin/main.cpp @@ -12,6 +12,7 @@ #include "UpdateJob.h" #include "RemoveJob.h" #include "InstallJob.h" +#include "UninstallJob.h" QString parseTarget(QCommandLineParser& parser) { @@ -59,6 +60,13 @@ void executeInstallCommand(const QString& target) { job->start(); } +void executeUninstallCommand(const QString& target) { + KJob* job = new UninstallJob(target); + + KIO::getJobTracker()->registerJob(job); + job->start(); +} + int main(int argc, char** argv) { QApplication app(argc, argv); QApplication::setApplicationName("plasma-appimage-integration"); @@ -94,6 +102,11 @@ int main(int argc, char** argv) { QString target = parseTarget(parser); executeInstallCommand(target); } + + if (command == "uninstall") { + QString target = parseTarget(parser); + executeUninstallCommand(target); + } return QApplication::exec(); } -- GitLab From 1cafb3020ea73bfc18c2afa3385cd041aef89a44 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 5 Aug 2019 18:25:00 -0500 Subject: [PATCH 5/5] Save config to XDG_CONFIG_DIR org.appimage.service.conf --- res/CMakeLists.txt | 2 +- res/{AppImage Services.conf => org.appimage.services.conf} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename res/{AppImage Services.conf => org.appimage.services.conf} (100%) diff --git a/res/CMakeLists.txt b/res/CMakeLists.txt index 2db6cfc..ede1a14 100644 --- a/res/CMakeLists.txt +++ b/res/CMakeLists.txt @@ -1 +1 @@ -install(FILES "AppImage Services.conf" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/The AppImage Project") +install(FILES "org.appimage.services.conf" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/xdg") diff --git a/res/AppImage Services.conf b/res/org.appimage.services.conf similarity index 100% rename from res/AppImage Services.conf rename to res/org.appimage.services.conf -- GitLab