Skip to content
Snippets Groups Projects
Verified Commit 94185a43 authored by azubieta's avatar azubieta
Browse files

Use killall

parent a92d1f3b
No related branches found
No related tags found
1 merge request!5Use killall
#include <QDebug>
#include <QtConcurrent/QtConcurrent>
#include "appimage/update.h"
#include "appupdater.h"
AppUpdater::AppUpdater(const QString &appImagePath, QObject *parent) : QObject(parent), appImagePath(appImagePath), updateHelper(nullptr)
{
connect(this, &AppUpdater::updateAvailable, &updateDialog, &AppUpdateDialog::showUpdateConfirmationMessage);
connect(&updateDialog, &AppUpdateDialog::updateRequested, this, &AppUpdater::doUpdate);
connect(&updateDialog, &AppUpdateDialog::restartRequested, this, &AppUpdater::doRestart);
connect(&updateDialog, &AppUpdateDialog::rejected, this, &AppUpdater::stop);
}
void AppUpdater::setSilentLookup(bool value)
{
silentLookup = value;
}
void AppUpdater::doUpdateLookUp()
{
if (appImagePath.isEmpty()) {
qWarning() << "Self-updates disabled: No app file provided.";
return;
}
if (!silentLookup)
updateDialog.show();
QtConcurrent::run([=]() {
appimage::update::Updater updater(appImagePath.toStdString());
bool updateAvailable; // this is an output parameter!!!
updater.checkForChanges(updateAvailable);
if (updateAvailable) {
qDebug() << "Update available";
emit this->updateAvailable();
}
});
}
void AppUpdater::doUpdate()
{
if (appImagePath.isEmpty()) {
qWarning() << "Self-updates disabled: No app file provided.";
return;
}
if (updateHelper !=nullptr)
delete updateHelper;
updateHelper = new appimage::update::Updater(appImagePath.toStdString());
updateHelper->start();
progressCheckTimer.setInterval(200);
progressCheckTimer.start();
connect(&progressCheckTimer, &QTimer::timeout, this, &AppUpdater::checkUpdateProgress);
}
void AppUpdater::doRestart()
{
QProcess::startDetached("killall", {"pling-store"});
if (updateHelper != nullptr) {
std::string pathToNewFile;
updateHelper->pathToNewFile(pathToNewFile);
if (!pathToNewFile.empty()) {
QString path = QString::fromStdString(pathToNewFile);
QFile::setPermissions(path, QFileDevice::ReadUser | QFileDevice::ExeUser);
QProcess proc;
proc.setEnvironment(getCleanSystemEnvironment());
qDebug() << proc.environment();
if (proc.startDetached(path)) {
updateDialog.accept();
} else
updateDialog.showErrorMessage("Unable to start: " + path);
}
}
}
void AppUpdater::stop()
{
}
void AppUpdater::checkUpdateProgress()
{
using namespace appimage::update;
auto state = updateHelper->state();
switch (state) {
case Updater::INITIALIZED:
break;
case Updater::RUNNING:
double progress;
updateHelper->progress(progress);
updateDialog.showProgress(progress*100);
break;
case Updater::STOPPING:
break;
case Updater::SUCCESS:
updateDialog.showCompletionMessage();
progressCheckTimer.stop();
break;
case Updater::ERROR:
updateDialog.showErrorMessage(tr("Update failed"));
progressCheckTimer.stop();
break;
}
}
QStringList AppUpdater::getCleanSystemEnvironment()
{
QString appDirPath = qgetenv("APPDIR");
QProcessEnvironment systenEnvironemnt = QProcessEnvironment::systemEnvironment();
QProcessEnvironment processEnvironment;
for (QString key: systenEnvironemnt.keys()) {
QString value = systenEnvironemnt.value(key);
QStringList oldValue = value.split(":");
QStringList newVaule;
for (const QString &valueSection: oldValue)
if (!valueSection.contains(appDirPath))
newVaule << valueSection;
if (!newVaule.empty())
processEnvironment.insert(key, newVaule.join(":"));
}
return processEnvironment.toStringList();
// return {"DISPLAY=:0"};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment