Skip to content

fix: Prevent terminal theme from being changed by other applications - #545

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
JWWTSL:master
Jun 23, 2026
Merged

fix: Prevent terminal theme from being changed by other applications#545
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
JWWTSL:master

Conversation

@JWWTSL

@JWWTSL JWWTSL commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

log: When the terminal is in fixed Light/Dark mode but dtkgui's per-app DConfig (org.deepin.dtk.preference.themeType) is out of sync with the saved colorScheme (e.g. upgrades from older builds, wiped or imported DConfig, shipped conf already containing a fixed theme), the isCustomPalette() guard in DGuiApplicationHelper never engages and external dde-appearance palette broadcasts propagate to qApp. Align dtkgui's paletteType with the saved colorScheme at the end of Settings::init() so the existing guard takes effect. Follow-system mode (extendColorScheme empty AND paletteType==UnknownType) is preserved.

pms: bug-365877

@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.

Sorry @JWWTSL, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@JWWTSL
JWWTSL force-pushed the master branch 3 times, most recently from 83e9d82 to ebef10e Compare June 23, 2026 11:24
log: When the terminal is in fixed Light/Dark mode but dtkgui's per-app DConfig (org.deepin.dtk.preference.themeType) is out of sync with the saved colorScheme (e.g. upgrades from older builds, wiped or imported DConfig, shipped conf already containing a fixed theme), the isCustomPalette() guard in DGuiApplicationHelper never engages and external dde-appearance palette broadcasts propagate to qApp. Align dtkgui's paletteType with the saved colorScheme at the end of Settings::init() so the existing guard takes effect. Follow-system mode (extendColorScheme empty AND paletteType==UnknownType) is preserved.

pms: bug-365877
@JWWTSL JWWTSL changed the title fix: Terminal theme color not updating with application theme changes fix: Prevent terminal theme from being changed by other applications Jun 23, 2026
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL, lzwind

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

@JWWTSL

JWWTSL commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码实现了终端主题 paletteType 的对齐与外部推送过滤,逻辑严密无安全风险
逻辑基本正确且注释清晰,因未对非标准 colorScheme 值做严格防御性处理扣5分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

代码在 Settings::init() 函数中新增了局部作用域,通过获取 DGuiApplicationHelper 单例判断当前是否为跟随系统模式,若非跟随系统则将 paletteType 强制对齐为 LightType 或 DarkType。逻辑通顺,能有效修复外部应用切主题时的状态异常问题。
潜在问题:当 colorScheme() 返回的值既不是 "Light" 也不是预期的 "Dark"(例如空字符串或其他异常值)时,三元表达式会默认将其降级为 DarkType,缺乏对异常值的显式防御处理。
建议:在三元表达式前增加对 colorScheme() 返回值的合法性校验,或将其修改为 if-else 结构以处理非标准值。

  • 2.代码质量(良好)✓

新增代码使用了独立的大括号作用域来限制 helper 等局部变量的生命周期,避免污染外部上下文。变量命名如 isFollowSystem、desiredType 语义清晰,注释详细阐述了修复的背景与意图,符合团队编码规范。
建议:无需改进。

  • 3.代码性能(无性能问题)✓

代码仅包含一次单例获取、两次字符串比较和一次枚举比较,时间复杂度为 O(1),无循环或系统调用,对 Settings::init() 的启动性能无负面影响。
建议:无需优化。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码未涉及外部输入处理、内存分配、命令执行等高风险操作,字符串比较均使用 Qt 内置的安全比较机制,不存在安全风险。

  • 建议:保持当前安全的编码方式。

■ 【改进建议代码示例】

    // 按 colorScheme 对齐 paletteType,激活 dtkgui 的 isCustomPalette() 过滤,
    // 避免外部应用切主题时 dde-appearance 经 DPlatformTheme 把 palette 推送到本进程 qApp。
    // 跟随系统模式(extendColorScheme 为空且 paletteType 为 UnknownType)保持原状。
    {
        auto helper = DGuiApplicationHelper::instance();
        const bool isFollowSystem = extendColorScheme().isEmpty()
                                    && helper->paletteType() == DGuiApplicationHelper::UnknownType;
        if (!isFollowSystem) {
            const QString currentScheme = colorScheme();
            DGuiApplicationHelper::ColorType desiredType = DGuiApplicationHelper::DarkType;
            if (currentScheme == "Light") {
                desiredType = DGuiApplicationHelper::LightType;
            } else if (currentScheme == "Dark") {
                desiredType = DGuiApplicationHelper::DarkType;
            } else {
                // 防御性处理:对于非标准主题值,保持当前 paletteType 不变
                desiredType = helper->paletteType();
            }

            if (helper->paletteType() != desiredType) {
                helper->setPaletteType(desiredType);
            }
        }
    }

@deepin-bot
deepin-bot Bot merged commit f2ac539 into linuxdeepin:master Jun 23, 2026
17 checks passed
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.

3 participants