Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions panels/dock/taskmanager/dockglobalelementmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ DockGlobalElementModel::DockGlobalElementModel(QAbstractItemModel *appsModel, Do
*it = std::make_tuple(id, m_appsModel, row);
Q_EMIT dataChanged(pIndex,
pIndex,
{TaskManager::ActiveRole, TaskManager::AttentionRole, TaskManager::WindowsRole, TaskManager::MenusRole});
{TaskManager::ActiveRole, TaskManager::AttentionRole, TaskManager::WindowsRole, TaskManager::MenusRole, TaskManager::WinTitleRole});
}
} else {
beginRemoveRows(QModelIndex(), pos, pos);
Expand Down Expand Up @@ -303,7 +303,11 @@ QString DockGlobalElementModel::getMenus(const QModelIndex &index) const
if (TaskManagerSettings::instance()->isAllowedForceQuit()) {
menusArray.append(QJsonObject{{"id", DOCK_ACTION_FORCEQUIT}, {"name", tr("Force Quit")}});
}
menusArray.append(QJsonObject{{"id", DOCK_ACTION_CLOSEALL}, {"name", tr("Close All")}});
if (TaskManagerSettings::instance()->isWindowSplit()) {
menusArray.append(QJsonObject{{"id", DOCK_ACTION_CLOSEWINDOW}, {"name", tr("Close")}});
} else {
menusArray.append(QJsonObject{{"id", DOCK_ACTION_CLOSEALL}, {"name", tr("Close All")}});
}
}

return QJsonDocument(menusArray).toJson();
Expand Down Expand Up @@ -366,6 +370,49 @@ void DockGlobalElementModel::requestActivate(const QModelIndex &index) const
}
}

void DockGlobalElementModel::requestNewInstance(const QModelIndex &index, const QString &action) const
{
auto data = m_data.value(index.row());
auto id = std::get<0>(data);
auto sourceModel = std::get<1>(data);
auto sourceRow = std::get<2>(data);

// Handle special actions first (for both active and docked apps)
if (action == DOCK_ACTION_DOCK) {
TaskManagerSettings::instance()->toggleDockedElement(QStringLiteral("desktop/%1").arg(id));
Comment on lines +373 to +382
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (performance): Avoid blocking the UI thread by waiting synchronously on QProcess when dispatching app actions.

In requestNewInstance, QProcess is started and then waitForFinished() is called, which will block the calling (likely GUI) thread until dde-am exits and can cause visible UI freezes. Instead, consider starting the process without blocking (e.g., QProcess::startDetached or an asynchronous start) and handle errors via signals or logging.

return;
} else if (action == DOCK_ACTION_FORCEQUIT) {
requestClose(index, true);
return;
} else if (action == DOCK_ACTION_CLOSEWINDOW || action == DOCK_ACTION_CLOSEALL) {
requestClose(index, false);
return;
}

//应用自身处理的action
if (!action.isEmpty()) {
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.start("dde-am", {"--by-user", id, action});
process.waitForFinished();
return;
}

// Handle launch/activate (empty action)
if (sourceModel == m_activeAppModel) {
auto sourceIndex = sourceModel->index(sourceRow, 0);
m_activeAppModel->requestNewInstance(sourceIndex, action);
} else {
QString dbusPath = QStringLiteral("/org/desktopspec/ApplicationManager1/") + escapeToObjectPath(id);
using Application = org::desktopspec::ApplicationManager1::Application;
Application appInterface(QStringLiteral("org.desktopspec.ApplicationManager1"), dbusPath, QDBusConnection::sessionBus());

if (appInterface.isValid()) {
appInterface.Launch(QString(), QStringList(), QVariantMap());
}
}
}

void DockGlobalElementModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const
{
auto data = m_data.value(index.row());
Expand Down
1 change: 1 addition & 0 deletions panels/dock/taskmanager/dockglobalelementmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DockGlobalElementModel : public QAbstractListModel, public AbstractTaskMan
inline int mapToSourceModelRole(QAbstractItemModel *model, int role) const;

void requestActivate(const QModelIndex &index) const override;
void requestNewInstance(const QModelIndex &index, const QString &action) const override;

void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const override;
void requestClose(const QModelIndex &index, bool force = false) const override;
Expand Down
1 change: 1 addition & 0 deletions panels/dock/taskmanager/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace dock {
static inline const QString DOCK_ACTION_ALLWINDOW = "dock-action-allWindow";
static inline const QString DOCK_ACTION_FORCEQUIT = "dock-action-forceQuit";
static inline const QString DOCK_ACTION_CLOSEALL = "dock-action-closeAll";
static inline const QString DOCK_ACTION_CLOSEWINDOW = "dock-action-closeWindow";
static inline const QString DOCK_ACTIN_LAUNCH = "dock-action-launch";
static inline const QString DOCK_ACTION_DOCK = "dock-action-dock";

Expand Down
Loading