Skip to content

fix(quickCapture): keep deferred menu actions in daemon context - #38

Merged
hthienloc merged 3 commits into
hthienloc:mainfrom
gofroshka:fix/quickcapture-menu-lifetime
Nov 4, 2026
Merged

hthienloc merged 3 commits into
hthienloc:mainfrom
gofroshka:fix/quickcapture-menu-lifetime

Conversation

@gofroshka

@gofroshka gofroshka commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What

Fix screenshot and recording actions launched from both Quick Capture menus: the centered CaptureLauncherModal.qml and the bar popout CaptureMenu.qml. Move the deferred capture/record dispatch into QuickCaptureDaemon.qml and pass the selected mode, action, output and widget to it before closing the popout.

Why

runAfterPopoutClosed() closes the popout and then schedules the supplied callback with Qt.callLater(). Closing the centered menu destroys its content, but the callback still accesses that menu's root (and, for recording, the delegate's modelData). Selecting an action can therefore close the menu without starting capture or recording.

Observed errors on Niri with DMS 2.0.0 and Quick Capture 5.9.0:

CaptureLauncherModal.qml:87: TypeError: Cannot read property 'daemon' of null
CaptureLauncherModal.qml:810: ReferenceError: root is not defined
(exception occurred during delayed function evaluation)

The new daemon methods close the originating widget and create the deferred callback in the persistent daemon's context. The callback no longer reads the destroyed menu or delegate. Capture modes, copy/edit actions, output selection and recording modes remain unchanged.

Reproduction

  1. Open the centered menu with dms ipc call quickCapture toggle, or open the bar widget's popout.
  2. Select a screenshot action, or switch to Screen Recording and select a recording target.
  3. The menu closes, but the requested action does not start; the journal contains one of the errors above.

How tested

  • git diff --check passed.
  • qmllint quickCapture/*.qml quickCapture/shared/*.qml exited successfully. It reports warnings, including unresolved DMS imports in the standalone lint environment.
  • qmllint quickCapture/components/bar/CaptureMenu.qml quickCapture/components/bar/CaptureLauncherModal.qml exited successfully with import/type warnings.
  • python3 scripts/refactor_dcommon.py --check --requires-dms ">=2.0.0" passed: 417 files and 21 manifests checked.
  • Added a reproducible Python/QtTest regression harness at quickCapture/tests/test_menu_dispatch.py and documented its usage in the developer guide. It extracts the actual production dispatch methods for both menu surfaces, destroys the originating menu during closePopout(), and checks deferred calls and their arguments. It also checks recording delegate wiring and missing-daemon guards. All 66 results passed: 31 functional cases plus setup/cleanup for each menu (nine capture modes × three actions, three recording modes, and the missing-daemon guard).
  • Run the harness with python3 quickCapture/tests/test_menu_dispatch.py (requires Qt's qmltestrunner and QtTest imports; --qmltestrunner can specify its path).
  • The local plugin was hot-reloaded with dms ipc call plugins reload quickCapture; opening the menu via IPC succeeded. Real screen capture/recording is not exercised by the headless harness.

No changes to shared components, IPC commands, dependencies, user settings or compositor keybindings. The local-only QML cache workaround used during interactive troubleshooting is intentionally excluded.

Summary by Sourcery

Preserve Quick Capture screenshot and recording actions when their originating menus are closed before deferred execution.

Bug Fixes:

  • Ensure screenshot and recording actions from both Quick Capture menus still execute after the menu closes.

Enhancements:

  • Keep deferred menu dispatch in the persistent Quick Capture daemon context and pass recording selections through menu-level handlers.
  • Add a regression harness covering deferred dispatch, menu destruction, recording wiring, and missing-daemon behavior.

Documentation:

  • Document how to run the Quick Capture menu dispatch regression harness.

Tests:

  • Add 66 QtTest regression cases covering capture and recording dispatch from both menu surfaces.

@sourcery-ai

sourcery-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Fixes Quick Capture screenshot and recording actions by capturing all required arguments and scheduling deferred work from the persistent daemon rather than destroyed popout content.

Sequence diagram for deferred Quick Capture dispatch

sequenceDiagram
    actor User
    participant Menu as CaptureLauncherModal
    participant Daemon as QuickCaptureDaemon
    participant Qt
    participant Capture as CaptureOrRecord

    User->>Menu: Select screenshot or recording action
    Menu->>Daemon: captureFromMenu(mode, action, outputName, widget)
    Menu->>Daemon: recordFromMenu(mode, widget)
    Daemon->>Menu: widget.closePopout()
    Daemon->>Qt: Qt.callLater(callback)
    Note over Qt,Capture: Callback runs from persistent daemon context
    Qt->>Daemon: root.capture(mode, action, outputName, false)
    Qt->>Daemon: root.record(mode, "", false)
    Daemon->>Capture: Start requested capture or recording
Loading

File-Level Changes

Change Details Files
Move deferred screenshot and recording dispatch into the persistent daemon context before destroying the popout.
  • Add daemon methods that close the originating widget and schedule capture or recording with captured arguments.
  • Preserve existing capture modes, actions, output selection, and recording mode behavior while avoiding destroyed menu references.
quickCapture/QuickCaptureDaemon.qml
Route Quick Capture menu actions through the daemon-owned dispatch methods.
  • Replace the menu callback-based screenshot path with daemon dispatch.
  • Add a recording helper and use it from recording target tiles instead of capturing delegate data in a delayed callback.
quickCapture/components/bar/CaptureLauncherModal.qml

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

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Walkthrough

Menu capture and recording now use daemon methods that close the popout before deferring the requested action. The launcher routes capture and recording actions through these methods.

Changes: Menu Capture and Recording

Layer / File(s) Summary
Daemon menu actions and launcher wiring
quickCapture/QuickCaptureDaemon.qml, quickCapture/components/bar/CaptureLauncherModal.qml
The daemon adds methods that close the popout and defer capture or recording. The launcher calls them for capture actions and recording-mode tiles. The recording method returns if no daemon is available.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: hthienloc

Merge Risk: Minimal · previous review 8cabf

The change moves deferred capture and recording actions out of the closing menu. No merge-blocking issue is identified; real capture and recording remain unverified by the reported harness.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(quickCapture): keep deferred menu actions in daemon context" matches the main change. The PR moves deferred capture and recording dispatch from the menu popout into QuickCaptureDaemon.q…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(quickCapture): keep deferred menu actions in daemon context" matches the main change. The PR moves deferred capture and recording dispatch from the menu popout into QuickCaptureDaemon.qml, so the deferred actions run in the daemon context. The title is specific, uses a conventional commit prefix, and names the affected component (quickCapture).

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a906bdd5-c328-42fa-b7dd-ded182813c3b
Commits

Reviewing files that changed from the base of the PR and between 7472e61 and 8cabf92.

Files selected for processing: 2
  • quickCapture/QuickCaptureDaemon.qml
  • quickCapture/components/bar/CaptureLauncherModal.qml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@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="quickCapture/components/bar/CaptureLauncherModal.qml" line_range="87" />
<code_context>
         if (!root.daemon)
             return;
-        root.widget.runAfterPopoutClosed(() => root.daemon.capture(mode, action, outputName));
+        root.daemon.captureFromMenu(mode, action, outputName, root.widget);
+    }
+
</code_context>
<issue_to_address>
**Bar popout actions never start**

When a screenshot or recording is selected from the bar widget’s popout rather than the centered modal, `CaptureMenu.run` and its recording delegate defer callbacks that dereference the destroyed menu’s `root` or `modelData`, so the daemon never receives the action and capture or recording does not start.

Have `CaptureMenu.run` and the recording delegate call the daemon’s menu-action methods instead of deferring callbacks that capture the menu’s `root` or `modelData`.

Also at `quickCapture/components/bar/CaptureLauncherModal.qml:816-817`, `quickCapture/QuickCaptureDaemon.qml:96-99`, `quickCapture/QuickCaptureDaemon.qml:101-104`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the deferred call uses the wrong mode or arguments, it could create an unintended capture or recording file. Reverting stops future calls but does not remove files already created; those are bounded and can be deleted.

Blocking findings: quickCapture/components/bar/CaptureLauncherModal.qml:87


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

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

Sourcery assessment

Approved.

@hthienloc

Copy link
Copy Markdown
Owner

Thanks for your PR.

@hthienloc
hthienloc merged commit 1e49345 into hthienloc:main Nov 4, 2026
1 of 2 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.

2 participants