Skip to content

feat: switch camera hotkey to daemon hardware privacy switch - #163

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
fly602:master
Sep 7, 2026
Merged

feat: switch camera hotkey to daemon hardware privacy switch#163
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
fly602:master

Conversation

@fly602

@fly602 fly602 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor
  1. Add CameraController to dde-shortcut-tool exposing camera toggle/on/off. It reads the real device state through org.deepin.dde.Daemon1.GetCameraPrivacy and switches it through SetCameraPrivacy, so the camera is disabled at the hardware level.
  2. The hotkey only drives the hardware switch and shows the matching OSD; it never launches or closes the camera application. When the daemon reports no switchable camera, the hotkey stays silent.
  3. Point the webcam shortcut config at dde-shortcut-tool camera toggle so the hotkey no longer needs the camera-switch helper script.

Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用

Influence:

  1. Press the camera hotkey on a machine with a USB camera and confirm the camera toggles off/on with the OSD shown, and the built-in mic on the same device keeps working.
  2. Press the camera hotkey on a machine without a switchable camera and confirm nothing happens (no application is launched).
  3. Build dde-shortcut-tool and confirm camera toggle/on/off commands work without errors.

feat: 摄像头热键改为仅通过系统接口硬件级开关摄像头

  1. 在 dde-shortcut-tool 中新增 CameraController,提供 camera toggle/on/off,经 org.deepin.dde.Daemon1.GetCameraPrivacy 读取状态、 SetCameraPrivacy 开关,硬件级禁用摄像头。
  2. 热键仅驱动硬件开关并显示 OSD,不启停相机应用;守护进程无可切换 摄像头时热键静默不动作。
  3. 将 webcam 快捷键配置指向 dde-shortcut-tool camera toggle,热键不再 依赖 camera-switch 辅助脚本。

Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用

Influence:

  1. 有 USB 摄像头的机型按热键,确认开关且有 OSD,同设备内置麦克风 不受影响。
  2. 无可切换摄像头的机型按热键,确认无动作(不启动相机应用)。
  3. 构建 dde-shortcut-tool,确认 camera toggle/on/off 命令无报错。

PMS: BUG-375443

Summary by Sourcery

Switch the webcam hotkey to control camera privacy through the system hardware interface without managing the camera application.

New Features:

  • Add camera toggle, enable, and disable commands to dde-shortcut-tool using the system daemon’s camera privacy controls.

Bug Fixes:

  • Prevent the camera hotkey from launching or closing the camera application when no switchable camera is available.

Enhancements:

  • Route the webcam shortcut through the hardware privacy switch and display matching camera OSD notifications.
  • Remove the obsolete camera-switch helper script.

@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

The webcam hotkey is migrated from application/helper-script control to dde-shortcut-tool camera actions, which use org.deepin.dde.Daemon1 to query and apply hardware-level camera privacy, show corresponding OSD feedback, and remain silent when no switchable camera is available.

Sequence diagram for hardware camera hotkey toggle

sequenceDiagram
    actor User
    participant Shortcut as dde-shortcut-tool
    participant Daemon as org.deepin.dde.Daemon1
    participant OSD as org.deepin.dde.Osd1

    User->>Shortcut: camera toggle
    Shortcut->>Daemon: GetCameraPrivacy()
    Daemon-->>Shortcut: privacy, deviceKnown
    alt switchable camera available
        Shortcut->>Daemon: SetCameraPrivacy(!privacy)
        Daemon-->>Shortcut: applied
        alt hardware switch applied
            Shortcut->>OSD: ShowOSD(CameraOn or CameraOff)
            OSD-->>User: Matching camera OSD
        else no switch applied
        end
    else no switchable camera
    end
Loading

File-Level Changes

Change Details Files
Adds a camera controller that delegates privacy state and hardware switching to dde-system-daemon over system D-Bus.
  • Creates camera toggle, on, and off actions.
  • Reads GetCameraPrivacy and handles unavailable or non-switchable cameras without fallback behavior.
  • Calls SetCameraPrivacy and reports success only when the daemon applies the hardware switch.
src/plugin-qt/shortcut/tools/dde-shortcut-tool/cameracontroller.cpp
src/plugin-qt/shortcut/tools/dde-shortcut-tool/cameracontroller.h
Integrates camera actions into the shortcut tool and its build.
  • Adds the controller sources to the executable.
  • Registers the camera command with the command parser.
src/plugin-qt/shortcut/tools/dde-shortcut-tool/CMakeLists.txt
src/plugin-qt/shortcut/tools/dde-shortcut-tool/main.cpp
Changes the webcam shortcut to invoke the shortcut tool's hardware camera toggle instead of the legacy helper behavior.
  • Points the webcam keybinding at the camera toggle command.
  • Preserves matching camera-on/camera-off OSD feedback and avoids launching the camera application.
src/plugin-qt/shortcut/configs/org.deepin.dde.keybinding.shortcut.webcam/org.deepin.shortcut.json

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

@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 1 issue

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

## Individual Comments

### Comment 1
<location path="src/plugin-qt/shortcut/tools/dde-shortcut-tool/cameracontroller.cpp" line_range="188" />
<code_context>
+        QDBusConnection::sessionBus()
+    );
+
+    if (osdInterface.isValid()) {
+        osdInterface.call("ShowOSD", signal);
+    } else {
+        qWarning() << "Failed to connect to OSD interface";
</code_context>
<issue_to_address>
**issue (bug_risk):** `ShowOSD` is called without checking the returned D-Bus message, so a camera switch can succeed while the OSD call fails and `execute` still reports success. The hotkey therefore does not guarantee the matching OSD described by the feature.

**Triggers:** When the OSD service is registered but rejects or fails the `ShowOSD` method call.

**Suggested fix:** Capture the returned `QDBusMessage` and log or propagate its error when the call is not a valid reply.

```suggestion
        QDBusMessage reply = osdInterface.call("ShowOSD", signal);
        if (reply.type() != QDBusMessage::ReplyMessage) {
            qWarning() << "ShowOSD failed:" << reply.errorMessage();
        }
```
</issue_to_address>

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.

Comment thread src/plugin-qt/shortcut/tools/dde-shortcut-tool/cameracontroller.cpp
@fly602
fly602 force-pushed the master branch 5 times, most recently from 469f119 to 902a9b6 Compare September 7, 2026 07:49

@yixinshark yixinshark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

看是否需要添加对dde-daemon版本的依赖。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, yixinshark

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. Add CameraController to dde-shortcut-tool exposing camera
   toggle/on/off. It reads the real device state through
   org.deepin.dde.Daemon1.GetCameraPrivacy and switches it through
   SetCameraPrivacy, so the camera is disabled at the hardware level.
2. The hotkey only drives the hardware switch and shows the matching OSD;
   it never launches or closes the camera application. When the daemon
   reports no switchable camera, the hotkey stays silent.
3. Point the webcam shortcut config at dde-shortcut-tool camera toggle
   so the hotkey no longer needs the camera-switch helper script.

Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用

Influence:
1. Press the camera hotkey on a machine with a USB camera and confirm
   the camera toggles off/on with the OSD shown, and the built-in mic
   on the same device keeps working.
2. Press the camera hotkey on a machine without a switchable camera and
   confirm nothing happens (no application is launched).
3. Build dde-shortcut-tool and confirm camera toggle/on/off commands
   work without errors.

feat: 摄像头热键改为仅通过系统接口硬件级开关摄像头

1. 在 dde-shortcut-tool 中新增 CameraController,提供 camera
   toggle/on/off,经 org.deepin.dde.Daemon1.GetCameraPrivacy 读取状态、
   SetCameraPrivacy 开关,硬件级禁用摄像头。
2. 热键仅驱动硬件开关并显示 OSD,不启停相机应用;守护进程无可切换
   摄像头时热键静默不动作。
3. 将 webcam 快捷键配置指向 dde-shortcut-tool camera toggle,热键不再
   依赖 camera-switch 辅助脚本。

Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用

Influence:
1. 有 USB 摄像头的机型按热键,确认开关且有 OSD,同设备内置麦克风
   不受影响。
2. 无可切换摄像头的机型按热键,确认无动作(不启动相机应用)。
3. 构建 dde-shortcut-tool,确认 camera toggle/on/off 命令无报错。

PMS: BUG-375443
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。摄像头热键改为通过系统守护进程 D-Bus 接口硬件级开关摄像头,设计合理,实现规范,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码语法正确,逻辑清晰,边界处理完善。CameraController 通过 D-Bus 与系统守护进程通信,toggle() 函数正确读取当前隐私状态并翻转,setPrivacy() 正确处理守护进程返回的 applied 标志,currentPrivacy() 和 requestPrivacy() 均检查接口有效性和返回参数数量,错误处理完整。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码结构清晰,注释完整。SPDX 版权头声明齐全,头文件使用 #ifndef 保护,命名空间内常量定义规范,函数职责单一,每个方法都有明确的功能边界。cameracontroller.h 中类文档注释详细说明了设计意图(仅驱动硬件开关,不启停相机应用)。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理。QDBusInterface 在构造函数中创建一次并复用,避免重复连接开销。同步 D-Bus 调用对于一次性 CLI 工具是合理的,无性能瓶颈。showOSD() 中的 OSD 接口为栈上临时对象,符合使用场景。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 安全合规。action 参数仅与固定字符串(toggle/on/off)比较,无注入风险。D-Bus 通信目标为系统已知服务(org.deepin.dde.Daemon1、org.deepin.dde.Osd1),无用户输入直接传递到 D-Bus 调用。showOSD 的 signal 参数来自硬编码字符串(CameraOff/CameraOn)。相比删除的 camera-switch 脚本(使用 pgrep/pkill/exec),新方案通过 D-Bus 接口交互,安全性显著提升。


💡 改进建议代码示例

// 当前实现已符合规范,无需额外修复
// CameraController 通过 D-Bus 安全地控制摄像头硬件隐私开关

bool CameraController::execute(const QString &action, const QStringList &args)
{
    Q_UNUSED(args);

    // action 仅与固定字符串比较,无注入风险
    if (action == "toggle") {
        return toggle();
    } else if (action == "on") {
        return setPrivacy(false);
    } else if (action == "off") {
        return setPrivacy(true);
    }

    qWarning() << "Unknown camera action:" << action;
    return false;
}

本报告由 AI 代码审查工具自动生成

@fly602

fly602 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 608eda9 into linuxdeepin:master Sep 7, 2026
6 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