fix: prevent dockHiddenSurfaceIds from being reset to empty#1629
Merged
Conversation
There was a problem hiding this comment.
Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
The commit refactors the save logic for tray sort order data to prevent `dockHiddenSurfaceIds` from being accidentally cleared. Previously, `onAvailableSurfacesChanged()` called `saveDataToDConfig()` which saved all configuration values, including `dockHiddenSurfaceIds`, at a point where other processes might be concurrently modifying this value, leading to a race condition where it could be overwritten with empty data. The fix splits the monolithic `saveDataToDConfig()` into targeted save methods: `saveSortOrderToDConfig()`, `saveHiddenIdsToDConfig()`, `saveDockHiddenIdsToDConfig()`, and `saveCollapsedToDConfig()`. In `onAvailableSurfacesChanged()`, only sort order and hidden IDs are saved, deliberately excluding `dockHiddenSurfaceIds` to avoid the race condition. The `dockHiddenSurfaceIds` is now only saved from `setDockVisible()` via the new `saveDockHiddenIdsToDConfig()` method, when the value is explicitly changed. Influence: 1. Test tray plugin visibility toggling and verify `dockHiddenSurfaceIds` persists correctly 2. Verify `hiddenSurfaceIds` and sort order still update properly on surface changes 3. Test scenarios where multiple processes might modify dock configuration simultaneously 4. Verify no data loss occurs when hiding/showing dock tray items 5. Test that collapsed state saves and loads correctly fix: 修复 dockHiddenSurfaceIds 被意外重置为空的问题 本次重构了托盘排序数据的保存逻辑,防止 `dockHiddenSurfaceIds` 被意外清 空。之前 `onAvailableSurfacesChanged()` 调用 `saveDataToDConfig()` 会保 存所有配置值,包括 `dockHiddenSurfaceIds`,而此时其他进程可能正在并发修 改该值,导致竞态条件,使其被空数据覆盖。 修复方案将单一的 `saveDataToDConfig()` 拆分为针对性的保存方 法:`saveSortOrderToDConfig()`、`saveHiddenIdsToDConfig()`、 `saveDockHiddenIdsToDConfig()` 和 `saveCollapsedToDConfig()`。 在 `onAvailableSurfacesChanged()` 中,只保存排序和隐藏 ID,刻意排 除 `dockHiddenSurfaceIds` 以避免竞态条件。`dockHiddenSurfaceIds` 现在仅在通过 `setDockVisible()` 显式修改时,通过新增的 `saveDockHiddenIdsToDConfig()` 方法保存。 Influence: 1. 测试托盘插件的可见性切换,验证 `dockHiddenSurfaceIds` 是否持久化保存 2. 验证在 surface 变化时 `hiddenSurfaceIds` 和排序是否正常更新 3. 测试多个进程同时修改 dock 配置的场景 4. 验证显示/隐藏 dock 托盘项时数据不会丢失 5. 测试折叠状态的保存和加载是否正常 PMS:BUG-363149
BLumia
approved these changes
Jun 11, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, BLumia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review我对这段代码进行了仔细审查,以下是我的分析和改进建议: 代码逻辑
代码质量
代码性能
代码安全
具体改进建议
void TraySortOrderModel::saveDataToDConfig()
{
saveSortOrderToDConfig();
saveHiddenIdsToDConfig();
saveDockHiddenIdsToDConfig();
saveCollapsedToDConfig();
}
#ifdef QT_DEBUG
qDebug() << "collapsedChanged";
#endif
void TraySortOrderModel::saveSortOrderToDConfig()
{
if (!m_dconfig) return;
// 验证数据有效性
QSet<QString> allIds = m_stashedIds.toSet() + m_collapsableIds.toSet() + m_pinnedIds.toSet();
m_dconfig->setValue("stashedSurfaceIds", m_stashedIds);
m_dconfig->setValue("collapsableSurfaceIds", m_collapsableIds);
m_dconfig->setValue("pinnedSurfaceIds", m_pinnedIds);
}
void TraySortOrderModel::saveDataToDConfig()
{
if (!m_dconfig) return;
// 开始批量操作
m_dconfig->beginGroup("TraySettings");
saveSortOrderToDConfig();
saveHiddenDataToDConfig();
saveCollapsedToDConfig();
// 结束批量操作
m_dconfig->endGroup();
}
void TraySortOrderModel::saveCollapsedToDConfig()
{
if (!m_dconfig) {
qWarning() << "DConfig is not initialized";
return;
}
try {
m_dconfig->setValue("isCollapsed", m_collapsed);
} catch (const std::exception &e) {
qWarning() << "Failed to save collapsed state:" << e.what();
}
}这些建议旨在提高代码的健壮性、可维护性和性能,同时保持原有功能的完整性。 |
Contributor
Author
|
/forcemerge |
|
This pr force merged! (status: blocked) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The commit refactors the save logic for tray sort order data to prevent
dockHiddenSurfaceIdsfrom being accidentally cleared. Previously,onAvailableSurfacesChanged()calledsaveDataToDConfig()whichsaved all configuration values, including
dockHiddenSurfaceIds, at apoint where other processes might be concurrently modifying this value,
leading to a race condition where it could be overwritten with empty
data.
The fix splits the monolithic
saveDataToDConfig()into targetedsave methods:
saveSortOrderToDConfig(),saveHiddenIdsToDConfig(),saveDockHiddenIdsToDConfig(), andsaveCollapsedToDConfig(). InonAvailableSurfacesChanged(), only sort order and hidden IDs aresaved, deliberately excluding
dockHiddenSurfaceIdsto avoid therace condition. The
dockHiddenSurfaceIdsis now only saved fromsetDockVisible()via the newsaveDockHiddenIdsToDConfig()method,when the value is explicitly changed.
Influence:
dockHiddenSurfaceIdspersists correctlyhiddenSurfaceIdsand sort order still update properly onsurface changes
configuration simultaneously
fix: 修复 dockHiddenSurfaceIds 被意外重置为空的问题
本次重构了托盘排序数据的保存逻辑,防止
dockHiddenSurfaceIds被意外清空。之前
onAvailableSurfacesChanged()调用saveDataToDConfig()会保存所有配置值,包括
dockHiddenSurfaceIds,而此时其他进程可能正在并发修改该值,导致竞态条件,使其被空数据覆盖。
修复方案将单一的
saveDataToDConfig()拆分为针对性的保存方法:
saveSortOrderToDConfig()、saveHiddenIdsToDConfig()、saveDockHiddenIdsToDConfig()和saveCollapsedToDConfig()。在
onAvailableSurfacesChanged()中,只保存排序和隐藏 ID,刻意排除
dockHiddenSurfaceIds以避免竞态条件。dockHiddenSurfaceIds现在仅在通过
setDockVisible()显式修改时,通过新增的saveDockHiddenIdsToDConfig()方法保存。Influence:
dockHiddenSurfaceIds是否持久化保存hiddenSurfaceIds和排序是否正常更新PMS:BUG-363149