Skip to content

Refactor monitor handling in automation nodes for improved readabilit…#547

Merged
felix-schultz merged 1 commit intoalphafrom
dev
Apr 2, 2026
Merged

Refactor monitor handling in automation nodes for improved readabilit…#547
felix-schultz merged 1 commit intoalphafrom
dev

Conversation

@felix-schultz
Copy link
Copy Markdown
Member

…y and maintainability

@felix-schultz felix-schultz merged commit 753090b into alpha Apr 2, 2026
12 of 15 checks passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates CI environment dependencies and refactors several automation nodes—including screenshot, display, and RPA logic—to scope monitor enumeration within local blocks. It also introduces a SendSyncRustAutoGui wrapper to manually implement Send and Sync for the underlying GUI library. Feedback identifies a critical thread-safety concern regarding the manual Send/Sync implementation for GDI handles, which may lead to undefined behavior during thread migration. Additionally, there are performance concerns regarding redundant monitor enumeration inside loops and functional issues where provided monitor or display indices are being ignored in screenshot and region capture logic.

Comment on lines +103 to +105
unsafe impl Send for SendSyncRustAutoGui {}
#[cfg(feature = "execute")]
unsafe impl Sync for SendSyncRustAutoGui {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The safety justification for manually implementing Send and Sync on SendSyncRustAutoGui is potentially insufficient. While the Mutex provides mutual exclusion, it does not guarantee thread affinity. If the underlying HDC and HBITMAP handles are thread-bound (as is common for GDI objects on Windows), accessing them from a different thread than the one they were created on can lead to undefined behavior. Since Tokio tasks can migrate between threads, this is a significant risk.

Comment on lines 281 to 282
let monitors = Monitor::all()
.map_err(|e| flow_like_types::anyhow!("Failed to enumerate monitors: {}", e))?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Calling Monitor::all() inside the loop is inefficient as it performs a system-level enumeration of all connected displays on every iteration. It is recommended to move the monitor enumeration outside the loop and reuse the monitor reference.

Comment on lines +102 to +104
let monitor = monitors
.first()
.ok_or_else(|| flow_like_types::anyhow!("No monitors found"))?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The monitor input index (evaluated as _monitor) is currently ignored. Use the provided index to select the correct display from the list.

Suggested change
let monitor = monitors
.first()
.ok_or_else(|| flow_like_types::anyhow!("No monitors found"))?;
let monitor = monitors
.get(_monitor as usize)
.ok_or_else(|| flow_like_types::anyhow!("Monitor index {} not found", _monitor))?;

Comment on lines +169 to +171
let monitor = monitors
.first()
.ok_or_else(|| flow_like_types::anyhow!("No monitors found"))?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The "region" capture type ignores the display_index input. It should respect the selected display index to allow capturing regions on secondary monitors.

Suggested change
let monitor = monitors
.first()
.ok_or_else(|| flow_like_types::anyhow!("No monitors found"))?;
let monitor = monitors.get(display_index as usize).ok_or_else(|| {
flow_like_types::anyhow!("Display index {} not found", display_index)
})?;

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

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