Skip to content

fix(power): remove Wayland visibility restrictions on power settings#3254

Open
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:treeland/power/hide
Open

fix(power): remove Wayland visibility restrictions on power settings#3254
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:treeland/power/hide

Conversation

@mhduiy
Copy link
Copy Markdown
Contributor

@mhduiy mhduiy commented May 26, 2026

  1. Removed platformName() !== "wayland" visibility guards from BatteryPage, GeneralPage, PowerMain, and PowerPage
  2. Power settings (screen & suspend, power plans, power saving, power button shortcuts) now show on Wayland
  3. Kept applicable non-Wayland checks (virtual environment, battery presence, suspend capability) intact

Log: Power management settings are no longer hidden on Wayland

fix(power): 移除电源管理设置页面在 Wayland 下的可见性限制

  1. 移除了 BatteryPage、GeneralPage、PowerMain、PowerPage 中的 platformName() !== "wayland" 可见性限制
  2. 电源管理设置(屏幕与休眠、电源计划、省电设置、电源按钮快捷键)现在可在 Wayland 下显示
  3. 保留了其他非 Wayland 相关的可见性检查(虚拟环境、电池状态、休眠能力) Log: 电源管理设置在 Wayland 环境下不再被隐藏
    PMS: BUG-346597
    PMS: BUG-346589
    PMS: BUG-346575

Change-Id: I93bb377d21f1b6d5580c2ddd980411e8a87f92da

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

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

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy

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

1. Removed `platformName() !== "wayland"` visibility guards from BatteryPage, GeneralPage, PowerMain, and PowerPage
2. Power settings (screen & suspend, power plans, power saving, power button shortcuts) now show on Wayland
3. Kept applicable non-Wayland checks (virtual environment, battery presence, suspend capability) intact

Log: Power management settings are no longer hidden on Wayland

fix(power): 移除电源管理设置页面在 Wayland 下的可见性限制

1. 移除了 BatteryPage、GeneralPage、PowerMain、PowerPage 中的 `platformName() !== "wayland"` 可见性限制
2. 电源管理设置(屏幕与休眠、电源计划、省电设置、电源按钮快捷键)现在可在 Wayland 下显示
3. 保留了其他非 Wayland 相关的可见性检查(虚拟环境、电池状态、休眠能力)
Log: 电源管理设置在 Wayland 环境下不再被隐藏
PMS: BUG-346597
PMS: BUG-346589
PMS: BUG-346575
@mhduiy mhduiy force-pushed the treeland/power/hide branch from 2feded4 to 85e5d27 Compare May 26, 2026 01:35
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX。我已仔细审查了你提供的 Git Diff。本次代码变更的核心逻辑是移除了在 QML 界面中对 Wayland 平台的大量显式隐藏限制dccData.platformName() !== "wayland"),使得电源管理相关设置项在 Wayland 环境下也变为可见。

以下是我对本次代码变更在语法逻辑、代码质量、代码性能和代码安全方面的详细审查意见:

1. 语法逻辑

  • 逻辑变更合理性:移除 !== "wayland" 的限制意味着 Wayland 环境下将开放屏幕亮度、待机、休眠等控制选项。从逻辑上看,如果底层 dccData 已经支持了 Wayland 下的电源管理,那么移除前端限制是合理的。
  • ⚠️ 潜在的运行时错误风险:在 BatteryPage.qmlPowerPage.qml 中,移除了外层容器的 visible: dccData.platformName() !== "wayland",但内部的子组件可能仍然包含与 Wayland 不兼容的操作。例如,在 X11 下可能通过 xrandr 或 DBus 控制亮度,而在 Wayland 下这些接口可能受限。如果底层逻辑未完全适配 Wayland,强制显示这些 UI 会导致用户操作无响应或报错。
  • 版权年份逻辑倒退SPDX-FileCopyrightText 的年份从 2024 - 2027 修改为了 2024 - 2026。通常情况下,版权结束年份应该是延长的,这里缩短了年份,请确认这是否是笔误。

2. 代码质量

  • 代码整洁度提升:本次变更移除了大量重复的硬编码平台判断逻辑,这大大提高了代码的整洁度和可读性,符合 DRY(Don't Repeat Yourself)原则。
  • ⚠️ 拼写错误遗留:在 GeneralPage.qml 第 79 行,存在一个拼写错误 haveBettary,正确的英文应为 haveBattery。虽然这不是本次 diff 引入的新问题,但既然修改了该行,建议顺手修复,避免将错别字继续留在代码库中。
  • 平台适配逻辑下沉:将 UI 层的 visible 判断移除,意味着平台适配的责任转移到了后端数据模型(dccData.model)或底层 Controller。这是一种更好的架构设计,但需要确保后端数据模型在 Wayland 下能正确返回对应的可用状态(例如 canSuspend 在 Wayland 下是否准确)。

3. 代码性能

  • QML 绑定性能优化:移除 dccData.platformName() !== "wayland" 这样的 JavaScript 表达式绑定,对 QML 引擎的性能是有微小提升的。QML 的属性绑定会在依赖项变化时重新计算,移除不必要的绑定可以减少评估开销,尤其是在这些 DccObject 初始化时。
  • 不可见对象的销毁:需要注意的是,移除 visible 判断后,这些组件在 Wayland 下不仅可见,而且会被实例化。如果某些组件加载开销很大且在 Wayland 下确实无用,应该使用 Loader 或从底层 model 过滤掉,而不是仅仅依靠 visible: false 隐藏(不过本次既然是改为可见,说明这些组件是需要被使用的,因此是合理的)。

4. 代码安全

  • 功能越权与操作安全:这是本次修改最大的安全隐患。Wayland 协议相比 X11 更加注重安全性,特别是屏幕截图、全局快捷键、输入模拟等操作受到严格限制。电源管理中的“按下电源按钮时的行为”等操作可能涉及系统底层的权限控制。如果 UI 暴露了这些选项,但后端在 Wayland 下没有相应的 PolicyKit 授权或 DBus 接口支持,可能会导致:
    1. 普通用户触发高权限操作时,系统弹窗要求输入密码,体验不佳。
    2. 操作静默失败,导致用户认为程序出现了 Bug。
    3. 如果后端存在校验漏洞,甚至可能引发提权风险。
  • 建议:确保后端 dccData.model 提供的属性(如 canSuspend, canHibernate)在 Wayland 环境下已经做了正确的鉴权和能力检测,前端展示与后端实际能力必须保持一致。

💡 改进建议代码

针对上述审查意见,建议对 GeneralPage.qml 中的拼写错误进行修复,并确认版权年份:

diff --git a/src/plugin-power/qml/GeneralPage.qml b/src/plugin-power/qml/GeneralPage.qml
index 91c20b3e19..e5f4a2b3c1 100644
--- a/src/plugin-power/qml/GeneralPage.qml
+++ b/src/plugin-power/qml/GeneralPage.qml
@@ -1,4 +1,4 @@
-// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
+// SPDX-FileCopyrightText: 2024 - 2027 UnionDESTech Co., Ltd. // 提示:请确认版权年份是否应恢复为2027
 // SPDX-License-Identifier: GPL-3.0-or-later
 import QtQuick 2.15
 import QtQuick.Window 2.15
@@ -76,7 +76,7 @@ DccObject {
         displayName: qsTr("Auto power saving on battery")
         weight: 400
         backgroundType: DccObject.Normal
-        visible: dccData.model.haveBettary
+        visible: dccData.model.haveBattery // 修复拼写错误: Bettary -> Battery
         pageType: DccObject.Editor
         page: D.Switch {
             checked: dccData.model.autoPowerSaveMode

总结:本次代码变更方向是好的,它清除了不必要的前端平台硬编码判断,使得代码更简洁。但请务必确认底层接口在 Wayland 下的实际支持情况,修复版权年份的异常变更,并顺手修正遗留的拼写错误。

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