Skip to content

Commit

Permalink
fix: [computer]Getting the UUID is stuck, causing the interface to fr…
Browse files Browse the repository at this point in the history
…eeze

Put the obtained UUID into the thread for execution

Log: Fixed some known issues
Bug: https://pms.uniontech.com/bug-view-254659.html
  • Loading branch information
pengfeixx authored and deepin-bot[bot] committed Jun 6, 2024
1 parent 9915975 commit 30dbf16
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 5 deletions.
68 changes: 68 additions & 0 deletions src/dfm-base/base/device/deviceproxymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include "devicemanager.h"
#include "deviceutils.h"
#include "private/deviceproxymanager_p.h"
#include <dfm-base/utils/finallyutil.h>

#include <QDBusServiceWatcher>
#include <QtConcurrent>

using namespace dfmbase;
static constexpr char kDeviceService[] { "org.deepin.filemanager.server" };
Expand Down Expand Up @@ -47,6 +49,20 @@ QStringList DeviceProxyManager::getAllBlockIdsByUUID(const QStringList &uuids, G
return devs;
}

QStringList DeviceProxyManager::asyncGetAllBlockIdsByUUID(const QStringList &uuids, GlobalServerDefines::DeviceQueryOptions opts)
{
const auto &&devices = getAllBlockIds(opts);
QStringList devs;
for (const auto &id : devices) {
const auto &&info = asyncQueryBlockInfo(id);
if (info.value("error", QVariant(false)).toBool())
return devs;
if (uuids.contains(info.value(GlobalServerDefines::DeviceProperty::kUUID).toString()))
devs << id;
}
return devs;
}

QStringList DeviceProxyManager::getAllProtocolIds()
{
if (d->isDBusRuning() && d->devMngDBus) {
Expand Down Expand Up @@ -80,6 +96,32 @@ QVariantMap DeviceProxyManager::queryProtocolInfo(const QString &id, bool reload
}
}

QVariantMap DeviceProxyManager::asyncQueryBlockInfo(const QString &id, bool reload)
{
if (d->isDBusRuning() && d->devMngDBus) {
auto fun = [=](const QString &id, bool reload) -> QDBusPendingReply<QVariantMap> {
DeviceManagerInterface devMngDBus(kDeviceService, kDevMngPath, QDBusConnection::sessionBus());
return devMngDBus.QueryBlockDeviceInfo(id, reload);
};
return d->asyncQueryInfo(id, reload, fun);
} else {
return queryBlockInfo(id, reload);
}
}

QVariantMap DeviceProxyManager::asyncQueryProtocolInfo(const QString &id, bool reload)
{
if (d->isDBusRuning() && d->devMngDBus) {
auto fun = [=](const QString &id, bool reload) -> QDBusPendingReply<QVariantMap> {
DeviceManagerInterface devMngDBus(kDeviceService, kDevMngPath, QDBusConnection::sessionBus());
return devMngDBus.QueryProtocolDeviceInfo(id, reload);
};
return d->asyncQueryInfo(id, reload, fun);
} else {
return queryProtocolInfo(id, reload);
}
}

void DeviceProxyManager::reloadOpticalInfo(const QString &id)
{
if (d->isDBusRuning() && d->devMngDBus)
Expand Down Expand Up @@ -345,6 +387,32 @@ void DeviceProxyManagerPrivate::disconnCurrentConnections()
currentConnectionType = kNoneConnection;
}

QVariantMap DeviceProxyManagerPrivate::asyncQueryInfo(const QString &id, bool reload, std::function<QDBusPendingReply<QVariantMap>(const QString&, bool)> func)
{
QEventLoop loop;
QFutureWatcher<QDBusPendingReply<QVariantMap>>* fw = new QFutureWatcher<QDBusPendingReply<QVariantMap>>;
FinallyUtil release([&] {
if (fw) {
delete fw;
fw = nullptr;
}
});
connect(fw, &QFutureWatcher<QDBusPendingReply<QVariantMap>>::finished, [&loop](){
loop.quit();
});
QFuture<QDBusPendingReply<QVariantMap>> ft =
QtConcurrent::run([id, reload, func](){
QDBusPendingReply<QVariantMap> reply = func(id, reload);
reply.waitForFinished();
return reply;
});
fw->setFuture(ft);
if (loop.exec()) {
return QVariantMap({{"error", true}});
}
return fw->result();
}

void DeviceProxyManagerPrivate::addMounts(const QString &id, const QString &mpt)
{
QString p = mpt.endsWith("/") ? mpt : mpt + "/";
Expand Down
3 changes: 3 additions & 0 deletions src/dfm-base/base/device/deviceproxymanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ class DeviceProxyManager : public QObject
// device info getter
QStringList getAllBlockIds(GlobalServerDefines::DeviceQueryOptions opts = GlobalServerDefines::DeviceQueryOption::kNoCondition);
QStringList getAllBlockIdsByUUID(const QStringList &uuids, GlobalServerDefines::DeviceQueryOptions opts = GlobalServerDefines::DeviceQueryOption::kNoCondition);
QStringList asyncGetAllBlockIdsByUUID(const QStringList &uuids, GlobalServerDefines::DeviceQueryOptions opts = GlobalServerDefines::DeviceQueryOption::kNoCondition);
QStringList getAllProtocolIds();
QVariantMap queryBlockInfo(const QString &id, bool reload = false);
QVariantMap queryProtocolInfo(const QString &id, bool reload = false);
QVariantMap asyncQueryBlockInfo(const QString &id, bool reload = false);
QVariantMap asyncQueryProtocolInfo(const QString &id, bool reload = false);

// device operation
void reloadOpticalInfo(const QString &id);
Expand Down
2 changes: 2 additions & 0 deletions src/dfm-base/base/device/private/deviceproxymanager_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class DeviceProxyManagerPrivate : public QObject
void connectToAPI();
void disconnCurrentConnections();

QVariantMap asyncQueryInfo(const QString &id, bool reload, std::function<QDBusPendingReply<QVariantMap>(const QString &, bool)> func);

private Q_SLOTS:
void addMounts(const QString &id, const QString &mpt);
void removeMounts(const QString &id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ComputerViewPrivate
private:
ComputerView *q { nullptr };
ComputerStatusBar *statusBar { nullptr };
bool exit { false };
};
}
#endif // COMPUTERVIEW_P_H
Original file line number Diff line number Diff line change
Expand Up @@ -221,21 +221,23 @@ QStringList ComputerUtils::allValidBlockUUIDs()
{
const auto &allBlocks = DevProxyMng->getAllBlockIds(GlobalServerDefines::DeviceQueryOption::kNotIgnored).toSet();
QSet<QString> uuids;
std::for_each(allBlocks.cbegin(), allBlocks.cend(), [&](const QString &devId) {
const auto &&data = DevProxyMng->queryBlockInfo(devId);
for(const QString &devId : allBlocks) {
const auto &&data = DevProxyMng->asyncQueryBlockInfo(devId);
if (data.value("error", QVariant(false)).toBool())
return uuids.values();
const auto &&uuid = data.value(GlobalServerDefines::DeviceProperty::kUUID).toString();
// optical item not hidden by dconfig, its uuid might be empty.
if (data.value(GlobalServerDefines::DeviceProperty::kOpticalDrive).toBool())
return;
continue;
if (!uuid.isEmpty())
uuids << uuid;
});
};
return uuids.values();
}

QList<QUrl> ComputerUtils::blkDevUrlByUUIDs(const QStringList &uuids)
{
const auto &&devIds = DevProxyMng->getAllBlockIdsByUUID(uuids);
const auto &&devIds = DevProxyMng->asyncGetAllBlockIdsByUUID(uuids);
QList<QUrl> ret;
for (const auto &id : devIds)
ret << makeBlockDevUrl(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ComputerView::ComputerView(const QUrl &url, QWidget *parent)

ComputerView::~ComputerView()
{
dp->exit = true;
}

QWidget *ComputerView::widget() const
Expand Down Expand Up @@ -301,6 +302,8 @@ void ComputerView::handleDisksVisible()
}

const auto &&hiddenPartitions = ComputerItemWatcher::hiddenPartitions();
if (dp->exit)
return;

fmInfo() << "ignored/hidden disks:" << hiddenPartitions;
for (int i = 7; i < model->items.count(); i++) { // 7 means where the disk group start.
Expand Down Expand Up @@ -399,6 +402,8 @@ void ComputerView::handleComputerItemVisible()
handleUserDirVisible();
handle3rdEntriesVisible();
handleDisksVisible();
if (dp->exit)
return;

dp->statusBar->itemCounted(dp->visibleItemCount());
}
Expand Down

0 comments on commit 30dbf16

Please sign in to comment.