Commit 16fb0ece authored by azubieta's avatar azubieta
Browse files

Merge branch 'development' into 'master'

Add install/uninstall support

See merge request !7
parents dffc340f 1cafb302
Pipeline #668 passed with stage
in 5 minutes and 44 seconds
......@@ -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
......
......@@ -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
install(FILES "AppImage Services.conf" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/The AppImage Project")
install(FILES "org.appimage.services.conf" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/xdg")
......@@ -4,3 +4,6 @@ RemoveCommandArgs=remove %1
UpdateCommand=plasma-appimage-integration
UpdateCommandArgs=update %1
UninstallCommand=plasma-appimage-integration
UninstallCommandArgs=uninstall %1
......@@ -3,6 +3,8 @@ add_executable(
main.cpp
UpdateJob.cpp
RemoveJob.cpp
InstallJob.cpp
UninstallJob.cpp
)
target_link_libraries(plasma-appimage-integration appimageservices-interfaces KF5::KIOWidgets KF5::I18n KF5::Notifications)
......
// libraries
#include <QtCore/QTimer>
#include <QtCore/QDebug>
#include <KI18n/KLocalizedString>
#include <utility>
// 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<QString, QString>(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);
}
#pragma once
// libraries
#include <KJob>
#include <QtCore/QProcess>
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;
};
// libraries
#include <QtCore/QTimer>
#include <QtCore/QDebug>
#include <KI18n/KLocalizedString>
#include <utility>
// 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<QString, QString>(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);
}
#pragma once
// libraries
#include <KJob>
#include <QtCore/QProcess>
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;
};
......@@ -11,6 +11,8 @@
// local
#include "UpdateJob.h"
#include "RemoveJob.h"
#include "InstallJob.h"
#include "UninstallJob.h"
QString parseTarget(QCommandLineParser& parser) {
......@@ -51,6 +53,20 @@ void executeRemoveCommand(const QString& target) {
}
void executeInstallCommand(const QString& target) {
KJob* job = new InstallJob(target);
KIO::getJobTracker()->registerJob(job);
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");
......@@ -82,6 +98,15 @@ int main(int argc, char** argv) {
executeRemoveCommand(target);
}
if (command == "install") {
QString target = parseTarget(parser);
executeInstallCommand(target);
}
if (command == "uninstall") {
QString target = parseTarget(parser);
executeUninstallCommand(target);
}
return QApplication::exec();
}
......
......@@ -27,33 +27,38 @@ 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<QAction*> AppImageFileItemActions::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) {
QList<QAction*> actions;
const QList<QUrl> urlList = fileItemInfos.urlList();
if (urlList.size() == 1) {
if (launcherInterface->isRegistered(urlList.first().toString()))
actions += createRemoveFromMenuAction(fileItemInfos, parentWidget);
else
if (launcherInterface->isValid()) {
const QList<QUrl> 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 {
qWarning() << "Discarding AppImage Add/Remove to Menu actions. Unable to connect to the AppImage Launcher Service";
}
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 {
actions += createAddToMenuAction(fileItemInfos, parentWidget);
actions += createRemoveFromMenuAction(fileItemInfos, parentWidget);
qWarning() << "Discarding AppImage Update action. Unable to connect to the AppImage Launcher Updater";
}
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;
actions += createInstallAction(fileItemInfos, parentWidget);
return actions;
}
......@@ -78,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<QUrl> urls = sender()->property("urls").value<QList<QUrl>>();
QWidget* parentWidget = sender()->property("parentWidget").value<QWidget*>();
......@@ -120,6 +134,18 @@ void AppImageFileItemActions::update() {
}
}
void AppImageFileItemActions::install() {
const QList<QUrl> urls = sender()->property("urls").value<QList<QUrl>>();
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);
......
......@@ -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;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment