Skip to content

Commit

Permalink
fix: update uab mimetype and uninstall process
Browse files Browse the repository at this point in the history
Update uab file mimetype;
Move uninstall uab package process to thread
to avoid blocking threads.

Log: Update uab mimetype and uninstall process.
  • Loading branch information
rb-union committed Oct 16, 2024
1 parent 2923cad commit c4d7484
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 35 deletions.
91 changes: 57 additions & 34 deletions src/deb-installer/uab/uab_dbus_package_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <QDBusUnixFileDescriptor>
#include <QFile>
#include <QFileInfo>
#include <QTimer>
#include <QtConcurrent/QtConcurrentRun>
#include <QDebug>

namespace Uab {
Expand Down Expand Up @@ -153,47 +153,70 @@ bool UabDBusPackageManager::installFormFile(const UabPackage::Ptr &installPtr)
return true;
}

/**
@brief Uninstall \a uninstallPtr package.
This function will return immediately, and the uninstall process will run in the thread-pool,
avoid the dbus interface blocks threads.
@return True if uninstall start, false if \a uninstallPtr invalid or is running
*/
bool UabDBusPackageManager::uninstall(const UabPackage::Ptr &uninstallPtr)
{
if (!uninstallPtr || !uninstallPtr->isValid() || isRunning()) {
return false;
}
ensureInterface();

QVariantMap pkgParams;
pkgParams[kllParamId] = uninstallPtr->info()->id;
pkgParams[kllParamVersion] = uninstallPtr->info()->version;
pkgParams[kllParamChannel] = uninstallPtr->info()->channel;
pkgParams[kllParamModule] = uninstallPtr->info()->module;
QVariantMap params;
params[kllParamPackage] = pkgParams;

QDBusReply<QVariantMap> reply = m_interface->call(kllDBusUninstall, params);
if (reply.error().isValid()) {
qWarning() << qPrintable("call LinglongPM dbus fails:") << reply.error().message();
return false;
}

const QVariantMap data = reply.value();
const int code = data.value(kllRetCode).toInt();
if (Uab::UabSuccess != code) {
qWarning() << QString("LinglingPM return error: [%1] %2").arg(code).arg(data.value(kllRetMessage).toString());
return false;
}

m_currentTask.taskId = data.value(kllRetTaskId).toString();
m_currentTask.code = code;
m_currentTask.message = data.value(kllRetMessage).toString();

qInfo() << QString("Requset LinglingPM uninstall: %1/%2 [message]: %3")
.arg(uninstallPtr->info()->id)
.arg(uninstallPtr->info()->version)
.arg(m_currentTask.message);

QTimer::singleShot(0, this, [this]() {
Q_EMIT progressChanged(100, m_currentTask.message);
Q_EMIT packageFinished(true);
m_currentTask.taskId = "mark uninstall";

QtConcurrent::run([this, uninstallPtr]() {
bool callRet{false};
QString message;

do {
QVariantMap pkgParams;
pkgParams[kllParamId] = uninstallPtr->info()->id;
pkgParams[kllParamVersion] = uninstallPtr->info()->version;
pkgParams[kllParamChannel] = uninstallPtr->info()->channel;
pkgParams[kllParamModule] = uninstallPtr->info()->module;
QVariantMap params;
params[kllParamPackage] = pkgParams;

QDBusReply<QVariantMap> reply = m_interface->call(kllDBusUninstall, params);
if (reply.error().isValid()) {
qWarning() << qPrintable("call LinglongPM dbus fails:") << reply.error().message();
break;
}

const QVariantMap data = reply.value();
const int code = data.value(kllRetCode).toInt();
if (Uab::UabSuccess != code) {
message = data.value(kllRetMessage).toString();
qWarning() << QString("LinglingPM return error: [%1] %2").arg(code).arg(message);
break;
}

const QString taskId = data.value(kllRetTaskId).toString();
message = data.value(kllRetMessage).toString();

qInfo() << QString("Requset LinglingPM uninstall: %1/%2 [message]: %3")
.arg(uninstallPtr->info()->id)
.arg(uninstallPtr->info()->version)
.arg(message);

callRet = true;
} while (false);

// notify on package manager thread
QMetaObject::invokeMethod(
this,
[this, message, callRet]() {
m_currentTask.taskId.clear();
Q_EMIT progressChanged(callRet ? 100 : 0, message);
Q_EMIT packageFinished(callRet);
},
Qt::QueuedConnection);
});

// uninstall not need receive task info, remove imdealtly and fast
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/deb-installer/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Pkg::PackageType Utils::detectPackage(const QString &filePath)
if (info.suffix().toLower() == "deb" || mime.name().startsWith("application/vnd.debian.binary-package")) {
return Pkg::Deb;
}
if (info.suffix().toLower() == "uab") {
if (info.suffix().toLower() == "uab" || mime.name().startsWith("application/vnd.linyaps.uab")) {
return Pkg::Uab;
}

Expand Down

0 comments on commit c4d7484

Please sign in to comment.