Skip to content

fix: theme migration misreads DTK default value - #602

Draft
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bugfix/383981
Draft

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bugfix/383981

Conversation

@add-uos

@add-uos add-uos commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

resolveMigratedFollowSystem() returned true when legacy.themeType == 0, treating the DTK config default value as an explicit "follow system" user choice. On first launch (no prior migration), themeType is 0, so the terminal wrongly switched to follow-system mode and inherited the system's light color scheme — causing the Quake terminal (Alt+F2) to appear with a light theme instead of the expected dark theme.

Key evidence: src/settings/settings.cpp:770 — return legacy.themeType == 0; was the buggy line. The migration path at src/settings/settings.cpp:718 consumed this return value to decide whether to follow the system theme.

Fix Approach

Changed return legacy.themeType == 0; to return false; with an explanatory comment. This means themeType=0 (DTK default) is no longer misinterpreted as an explicit "follow system" choice. The existing colorScheme is preserved unchanged. The illegal-value branch (themeType < 0 || themeType > 2) still returns true, matching dtkgui's normalization behavior.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target line was introduced in baseline commit 976a3a09 (not a historical fix being reverted); only the return value changed, function signature unchanged
  • Single caller (Settings::migrateThemeMode() at settings.cpp:718); behavior becomes more conservative — no new error paths introduced

Business Impact Scope

  • Terminal theme migration: affects first-launch theme migration logic. Users on fresh installs will no longer have their terminal switched to follow-system mode based on the DTK default value.
  • Quake terminal (Alt+F2): first invocation on a fresh install will display the expected dark theme instead of inheriting a light system theme.
  • Users who previously set "follow system" explicitly (migration already completed) are unaffected.

Verification Suggestion

Test first Alt+F2 Quake terminal launch on a fresh install to verify dark theme. Verify theme migration with themeType=0 keeps existing colorScheme. Confirm users with explicit follow-system setting still work after migration.


根因分析

resolveMigratedFollowSystem() 在 legacy.themeType == 0 时返回 true,将 DTK 配置默认值误判为用户显式选择"跟随系统"。首次启动(未迁移过)时 themeType 为 0,终端错误切换为跟随系统模式并继承系统浅色配色——导致 Quake 终端(Alt+F2)显示浅色主题而非预期的深色主题。

关键证据:src/settings/settings.cpp:770 — return legacy.themeType == 0; 为缺陷行。迁移路径 src/settings/settings.cpp:718 消费该返回值决定是否跟随系统主题。

修复方案

将 return legacy.themeType == 0; 改为 return false; 并添加注释说明。themeType=0(DTK 默认值)不再被误判为显式"跟随系统"选择,保持现有 colorScheme 不变。非法值分支(themeType < 0 || themeType > 2)仍返回 true,与 dtkgui 归一逻辑一致。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行由基线 commit 976a3a09 引入(非历史修复被撤销);仅修改返回值,函数签名不变
  • 唯一调用者(Settings::migrateThemeMode(),settings.cpp:718);行为更保守,不引入新错误路径

业务影响范围

  • 终端主题迁移:影响首次启动主题迁移逻辑。全新安装用户不再因 DTK 默认值被切换为跟随系统模式。
  • Quake 终端(Alt+F2):全新安装首次调用将显示预期深色主题,不再继承系统浅色主题。
  • 已在旧版本显式设置跟随系统的用户(迁移已完成)不受影响。

验证建议

在全新安装环境测试首次 Alt+F2 Quake 终端启动验证深色主题。验证 themeType=0 时主题迁移保持现有配色不变。确认已设置跟随系统的用户迁移后功能正常。

Summary by Sourcery

Correct theme migration so the DTK default value preserves the existing color scheme instead of incorrectly enabling follow-system mode.

Bug Fixes:

  • Prevent first-launch theme migration from interpreting the DTK default theme value as an explicit follow-system preference, preserving the expected dark theme for fresh installations.
  • Retain follow-system behavior for invalid legacy theme values while leaving explicitly selected light or dark themes unchanged.

Tests:

  • Update theme migration tests to verify that the DTK default value does not enable follow-system mode.

1. Root cause: resolveMigratedFollowSystem() returned true when
   legacy.themeType==0, treating the DTK config default value as an
   explicit "follow system" user choice. On first launch (no prior
   migration), themeType is 0, so the terminal wrongly switched to
   follow-system mode and inherited the light color scheme.
2. Fix: return false for themeType==0 (conservative — keep existing
   colorScheme unchanged). Only the illegal-value branch (>2 or <0)
   still returns true, matching dtkgui normalization.
3. Impact: first Alt+F2 Quake terminal no longer inherits a light
   theme from the system on fresh installs. Users who explicitly set
   follow-system in a prior version are unaffected (migration already
   completed). Updated unit test to match corrected semantics.

fix: 修复主题迁移误判DTK默认值为跟随系统

1. 根因:resolveMigratedFollowSystem() 在 themeType==0 时返回 true,
   将 DTK 配置默认值误判为用户显式选择"跟随系统"。首次启动(未迁移过)
   时 themeType 为 0,终端错误切换为跟随系统模式并继承浅色配色。
2. 方案:themeType==0 时保守返回 false,保持现有 colorScheme 不变。
   仅非法值分支(>2 或 <0)仍返回 true,与 dtkgui 归一逻辑一致。
3. 影响:首次 Alt+F2 打开 Quake 终端不再继承系统浅色主题。已在旧版本
   显式设置跟随系统的用户不受影响(迁移已完成)。同步更新单元测试。

Log: Fixed Quake terminal showing light theme on first launch due to theme migration misreading DTK default as follow-system
Influence:
  - Test first launch with Alt+F2 Quake terminal shows dark theme
  - Test theme migration with themeType=0 keeps existing colorScheme
  - Verify users with explicit follow-system setting still work after migration
Log: 修复首次 Alt+F2 打开 Quake 终端时因主题迁移误判显示浅色主题的问题
Influence:
  - 测试首次 Alt+F2 打开 Quake 终端显示深色主题
  - 测试 themeType=0 时主题迁移保持现有配色不变
  - 验证已设置跟随系统的用户迁移后功能正常
PMS: BUG-383981
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Change the migration decision so DTK’s default theme value is not mistaken for an explicit follow-system choice, while preserving the existing handling of invalid values.

  • src/settings/settings.cpp L768-770

Tests

Update the unit test to assert that the DTK default value does not enable follow-system mode.

  • tests/src/settings/ut_settings_test.cpp L256-257

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@add-uos
add-uos marked this pull request as draft November 24, 2026 16:55

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/settings/settings.cpp" line_range="770" />
<code_context>
-    return legacy.themeType == 0;
+    // themeType=0 是 DTK 配置默认值,并非用户显式选择"跟随系统"——保守返回 false,
+    // 保持当前 colorScheme 不变,避免首次启动误判为跟随系统导致主题错误
+    return false;
 }

</code_context>
<issue_to_address>
**Saved theme preference is lost**

When an upgraded installation has an unmigrated legacy `themeType=0` follow-system choice, `resolveMigratedFollowSystem()` returns false, so `migrateLegacyThemeMode()` stores `follow_system=false` and marks migration complete; `applyThemeMode()` pins the saved color scheme, and system theme changes no longer update the terminal.

Treat an explicit legacy `themeType=0` follow-system choice as enabled during migration.

Also at `tests/src/settings/ut_settings_test.cpp:257`.
</issue_to_address>

### Comment 2
<location path="src/settings/settings.cpp" line_range="770" />
<code_context>
-    return legacy.themeType == 0;
+    // themeType=0 是 DTK 配置默认值,并非用户显式选择"跟随系统"——保守返回 false,
+    // 保持当前 colorScheme 不变,避免首次启动误判为跟随系统导致主题错误
+    return false;
 }

</code_context>
<issue_to_address>
**Concurrent migration resets theme choice**

When two terminal processes initialize the same fresh configuration concurrently with legacy `themeType=0`, and the user enables follow-system in the first process before the second writes its migration result, process B can read the migration marker as unset, then Process A can finish migration and the user can enable follow-system before B reaches `setFollowSystemTheme(false)`. B overwrites that newer choice and marks migration complete, so the user's selected theme mode is lost.

Serialize migration across processes or recheck the migration marker immediately before applying the migrated value so a late migration cannot overwrite a newer user choice.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/settings/settings.cpp
return legacy.themeType == 0;
// themeType=0 是 DTK 配置默认值,并非用户显式选择"跟随系统"——保守返回 false,
// 保持当前 colorScheme 不变,避免首次启动误判为跟随系统导致主题错误
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Saved theme preference is lost

When an upgraded installation has an unmigrated legacy themeType=0 follow-system choice, resolveMigratedFollowSystem() returns false, so migrateLegacyThemeMode() stores follow_system=false and marks migration complete; applyThemeMode() pins the saved color scheme, and system theme changes no longer update the terminal.

Treat an explicit legacy themeType=0 follow-system choice as enabled during migration.

Also at tests/src/settings/ut_settings_test.cpp:257.

Prompt for AI agents
In `src/settings/settings.cpp` at line 770:

**Saved theme preference is lost**

When an upgraded installation has an unmigrated legacy `themeType=0` follow-system choice, `resolveMigratedFollowSystem()` returns false, so `migrateLegacyThemeMode()` stores `follow_system=false` and marks migration complete; `applyThemeMode()` pins the saved color scheme, and system theme changes no longer update the terminal.

Treat an explicit legacy `themeType=0` follow-system choice as enabled during migration.

Also at `tests/src/settings/ut_settings_test.cpp:257`.

Comment thread src/settings/settings.cpp
return legacy.themeType == 0;
// themeType=0 是 DTK 配置默认值,并非用户显式选择"跟随系统"——保守返回 false,
// 保持当前 colorScheme 不变,避免首次启动误判为跟随系统导致主题错误
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Concurrent migration resets theme choice

When two terminal processes initialize the same fresh configuration concurrently with legacy themeType=0, and the user enables follow-system in the first process before the second writes its migration result, process B can read the migration marker as unset, then Process A can finish migration and the user can enable follow-system before B reaches setFollowSystemTheme(false). B overwrites that newer choice and marks migration complete, so the user's selected theme mode is lost.

Serialize migration across processes or recheck the migration marker immediately before applying the migrated value so a late migration cannot overwrite a newer user choice.

Prompt for AI agents
In `src/settings/settings.cpp` at line 770:

**Concurrent migration resets theme choice**

When two terminal processes initialize the same fresh configuration concurrently with legacy `themeType=0`, and the user enables follow-system in the first process before the second writes its migration result, process B can read the migration marker as unset, then Process A can finish migration and the user can enable follow-system before B reaches `setFollowSystemTheme(false)`. B overwrites that newer choice and marks migration complete, so the user's selected theme mode is lost.

Serialize migration across processes or recheck the migration marker immediately before applying the migrated value so a late migration cannot overwrite a newer user choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants