Files
rustdesk/libs/scrap
fufesou 0d1cc89828 Fix/privacy mode2 initialization (#17090)
* fix(windows): stabilize privacy mode 2 initialization

First-time Amyuni setup can reset the display layout after the monitor
appears. Prepare it on a worker outside the privacy mutex and connection
loop, keeping remote input and video responsive during initialization.

Poll DXGI for five seconds without capture loss, with a 20-second deadline.
Log and retain the full wait when DXGI cannot be observed. Cancel pending
activation on disable, disconnect or permission revocation.

Validate active outputs before reporting success and detect subsequent
privacy loss in the display loop. Notify the authenticated owner directly
without depending on the connection manager.

Validation: default test build and two privacy-mode regression tests;
Flutter cargo check --tests; formatting and whitespace checks; successful
first-install hardware test with 12.1-second activation and manual exit.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): preserve privacy monitor cleanup and allow retries

Carry the monitor created during Amyuni preparation into privacy mode's
existing cleanup list so exiting removes one monitor instead of all managed
virtual monitors.

Wait cancellably for ongoing preparation when activation is retried, keeping
the connection responsive. Add a regression test for waiting and cancellation.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): skip privacy restoration when cancelling preparation

A cancelled preparation worker already owns cleanup. Acknowledge cancellation without restoring an inactive privacy layout, which could otherwise remove all managed virtual monitors before the worker finishes.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): roll back inactive privacy monitor preparation

Attempt to undo an accepted Amyuni monitor request when privacy preparation fails or is cancelled, even if active-display enumeration cannot see the requested monitor. Preserve non-forced removal for active outputs and report cleanup failures.

Signed-off-by: fufesou <linlong1266@gmail.com>

* chore(windows): trim privacy diagnostics and adjust polling

Remove temporary activation logs and move the preparation-lock test module after the other Amyuni items. Use a 300 ms polling interval for display stabilization and preparation-lock cancellation checks.

Signed-off-by: fufesou <linlong1266@gmail.com>

* perf(windows): probe privacy readiness without pixel readback

Check DXGI duplication access without copying or mapping desktop pixels during first-install privacy preparation. Reuse frame cleanup and preserve the existing stability window and normal capture path.

Log probe creation and recreation timing, and clarify which display flags are excluded from privacy validation.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): probe the prepared display during privacy initialization

Observe the newly created Amyuni output so the readiness probe does not contend with video capture for the same DXGI duplication interface.

Retry temporary DXGI unavailability within the existing initialization deadline while retaining the stability interval and explicit full-wait fallback.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): report privacy preparation cleanup failures

Preserve the single-monitor safety checks when cleaning up a prepared Amyuni display and propagate driver errors directly.

Leave ordinary monitor removal and best-effort bulk cleanup unchanged.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): retain privacy initialization wait across retries

Remember unfinished first-install observation after monitor creation or stability failures. Recheck it when reusing an existing Amyuni output, and clear it only after the existing observation policy completes.

Keep the state local to privacy preparation and serialize access with the existing preparation lock.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): validate privacy preparation and avoid display stalls

Keep initialization pending when its output disappears, and wait for an active output count decrease before completing preparation cleanup.

Skip privacy checks while activation or restoration holds the mutex, report poisoned locks, and log preparation errors with throttling.

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
2026-11-19 17:43:55 +08:00
..
2026-09-06 00:21:28 +08:00
2026-06-18 22:37:15 +08:00
…

Derived from https://github.com/quadrupleslap/scrap

scrap

Scrap records your screen! At least it does if you're on Windows, macOS, or Linux.

Usage

[dependencies]
scrap = "0.5"

Its API is as simple as it gets!

struct Display; /// A screen.
struct Frame; /// An array of the pixels that were on-screen.
struct Capturer; /// A recording instance.

impl Capturer {
    /// Begin recording.
    pub fn new(display: Display) -> io::Result<Capturer>;

    /// Try to get a frame.
    /// Returns WouldBlock if it's not ready yet.
    pub fn frame<'a>(&'a mut self) -> io::Result<Frame<'a>>;

    pub fn width(&self) -> usize;
    pub fn height(&self) -> usize;
}

impl Display {
    /// The primary screen.
    pub fn primary() -> io::Result<Display>;

    /// All the screens.
    pub fn all() -> io::Result<Vec<Display>>;

    pub fn width(&self) -> usize;
    pub fn height(&self) -> usize;
}

impl<'a> ops::Deref for Frame<'a> {
    /// A frame is just an array of bytes.
    type Target = [u8];
}

The Frame Format

  • The frame format is guaranteed to be packed BGRA.
  • The width and height are guaranteed to remain constant.
  • The stride might be greater than the width, and it may also vary between frames.

System Requirements

OS Minimum Requirements
macOS macOS 10.8
Linux XCB + SHM + RandR
Windows DirectX 11.1