Skip to content

sync: from linuxdeepin/dde-session-shell#488

Open
deepin-ci-robot wants to merge 1 commit intomasterfrom
sync-pr-57-nosync
Open

sync: from linuxdeepin/dde-session-shell#488
deepin-ci-robot wants to merge 1 commit intomasterfrom
sync-pr-57-nosync

Conversation

@deepin-ci-robot
Copy link
Contributor

@deepin-ci-robot deepin-ci-robot commented Feb 9, 2026

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#57

Summary by Sourcery

Bug Fixes:

  • Prevent unintended transitions to the lock screen by extending the shutdown inhibition condition to cover additional power action requirements.

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#57
@deepin-ci-robot
Copy link
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot

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

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Extends the shutdown-inhibit guard logic in WarningContent to also consider new RequireShutdown and RequireRestart power action states, preventing unintended transition to lock content during these actions.

Class diagram for updated shutdown inhibit logic in WarningContent

classDiagram
class WarningContent {
  - SessionBaseModel m_model
  - SessionBaseModel_PowerAction m_powerAction
  + void doAcceptShutdownInhibit()
}

class SessionBaseModel {
  <<enumeration>> ModeStatus
  <<enumeration>> PowerAction
  + ModeStatus currentModeState()
  + void setCurrentContentType(ContentType type)
}

class SessionBaseModel_ModeStatus {
  ShutDownMode
  PowerMode
}

class SessionBaseModel_PowerAction {
  RequireUpdateShutdown
  RequireUpdateRestart
  RequireShutdown
  RequireRestart
}

class FullScreenBackground {
  + static void setContent(LockContent content)
}

class LockContent {
  + static LockContent instance()
}

WarningContent --> SessionBaseModel : uses
WarningContent --> FullScreenBackground : calls
WarningContent --> LockContent : calls
SessionBaseModel --> SessionBaseModel_ModeStatus : defines
SessionBaseModel --> SessionBaseModel_PowerAction : defines
Loading

Flow diagram for extended shutdown inhibit guard in WarningContent::doAcceptShutdownInhibit

flowchart TD
  A[doAcceptShutdownInhibit called] --> B{currentModeState is ShutDownMode or PowerMode}
  B -- yes --> Z[Skip lock transition]
  B -- no --> C{m_powerAction is RequireUpdateShutdown}
  C -- yes --> Z[Skip lock transition]
  C -- no --> D{m_powerAction is RequireUpdateRestart}
  D -- yes --> Z[Skip lock transition]
  D -- no --> E{m_powerAction is RequireShutdown}
  E -- yes --> Z[Skip lock transition]
  E -- no --> F{m_powerAction is RequireRestart}
  F -- yes --> Z[Skip lock transition]
  F -- no --> G[FullScreenBackground setContent with LockContent instance]
  G --> H[m_model setCurrentContentType to LockContent]
  H --> I[End]
Loading

File-Level Changes

Change Details Files
Broaden the conditional guard around shutdown inhibition to handle additional power action states.
  • Update the if-condition in doAcceptShutdownInhibit to include checks for RequireShutdown and RequireRestart in addition to existing shutdown-related actions
  • Ensure that when powerAction reflects any of the update or direct shutdown/restart requirements, the UI does not switch to lock content or reset mode state prematurely
src/widgets/warningcontent.cpp

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
Contributor Author

deepin pr auto review

这段代码的修改主要是在 doAcceptShutdownInhibit 函数中增加了一些条件判断,用于处理电源操作相关的逻辑。以下是对这段代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面:

1. 语法逻辑

  • 修改点:代码在原有的 if 条件判断中增加了两个新的检查:
    • m_powerAction != SessionBaseModel::RequireShutdown
    • m_powerAction != SessionBaseModel::RequireRestart
  • 分析
    • 逻辑上,这个修改是为了确保当 m_powerActionRequireShutdownRequireRestart 时,不执行切换到锁屏界面的操作(即不执行 FullScreenBackground::setContent(...)m_model->setCurrentContentType(...))。
    • 这是一个合理的逻辑补充,防止在系统需要强制关机或重启(例如系统更新)时,误操作导致界面停留在锁屏页面而不是继续执行关机/重启流程。

2. 代码质量

  • 可读性:当前的 if 条件包含了多个 && 连接的长条件,虽然逻辑清晰,但行数较多,可读性稍差。
  • 改进建议:可以将这些复杂的条件提取为一个具有明确语义的私有成员函数或 lambda 表达式,以提高代码的可读性和可维护性。
    • 例如:
      // 在类中定义辅助函数
      bool WarningContent::shouldShowLockScreen() const {
          return m_model->currentModeState() != SessionBaseModel::ModeStatus::ShutDownMode
              && m_model->currentModeState() != SessionBaseModel::ModeStatus::PowerMode
              && m_powerAction != SessionBaseModel::RequireUpdateShutdown
              && m_powerAction != SessionBaseModel::RequireUpdateRestart
              && m_powerAction != SessionBaseModel::RequireShutdown
              && m_powerAction != SessionBaseModel::RequireRestart;
      }
      
      // 在 doAcceptShutdownInhibit 中调用
      void WarningContent::doAcceptShutdownInhibit() {
          if (shouldShowLockScreen()) {
              FullScreenBackground::setContent(LockContent::instance());
              m_model->setCurrentContentType(SessionBaseModel::LockContent);
          }
      }

3. 代码性能

  • 分析
    • 这些条件判断主要涉及枚举值的比较和简单的逻辑运算,性能开销极小,可以忽略不计。
    • LockContent::instance() 看起来是一个单例获取操作,setContentsetCurrentContentType 涉及界面切换,这是主要的性能消耗点,但由于这段代码位于 if 判断内部,只有在特定条件下才会执行,因此没有性能问题。

4. 代码安全

  • 空指针检查
    • 代码中使用了 m_model 指针。虽然通常在类初始化时会确保 m_model 有效,但为了防御性编程,建议在使用前增加判空检查(如果 m_model 有可能为空的话)。
    • 如果 m_model 在类的生命周期中保证不为空,则不需要检查。
  • 逻辑完备性
    • 增加的 RequireShutdownRequireRestart 检查有效地填补了逻辑漏洞,防止了在特定电源操作下界面行为异常,提高了系统的健壮性。

总结

这段代码的修改是正确的,逻辑上填补了之前可能存在的边界情况处理缺失。代码本身没有明显的语法错误或严重的性能问题。主要的改进空间在于代码的可读性和维护性,建议将复杂的条件判断提取为独立的辅助函数。此外,确认 m_model 的生命周期管理是否需要额外的判空保护。

Copy link

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

Hey - I've left some high level feedback:

  • The compound if condition combining multiple currentModeState and m_powerAction checks is getting hard to read and reason about; consider extracting the power-action check into a small helper (e.g. isNormalPowerAction(...)) or using a switch to make the allowed/blocked cases more explicit.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The compound `if` condition combining multiple `currentModeState` and `m_powerAction` checks is getting hard to read and reason about; consider extracting the power-action check into a small helper (e.g. `isNormalPowerAction(...)`) or using a `switch` to make the allowed/blocked cases more explicit.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant