Skip to content

fix: refresh monitor handles when app window is shown - #28

Merged
stabldev merged 2 commits into
mainfrom
fix-stale-monitor-handles
Jul 12, 2026
Merged

fix: refresh monitor handles when app window is shown#28
stabldev merged 2 commits into
mainfrom
fix-stale-monitor-handles

Conversation

@stabldev

@stabldev stabldev commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Fixes an issue where stale monitor handles after a sleep cycle caused the fallback WMI brightness adjustment to affect the built-in laptop screen instead of the selected external display.

Summary by CodeRabbit

  • Bug Fixes
    • Preserved the previously selected monitor when the monitor list refreshes.
    • Added a fallback to the primary monitor when the previous selection is unavailable.
    • Automatically refreshes monitor information when the application window becomes visible.
    • Improves monitor identification by capturing an additional device identifier for each available monitor.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 60f9b845-7c49-4df9-b96f-330cfd9c0c9a

📥 Commits

Reviewing files that changed from the base of the PR and between 1b9f2d8 and 5fedc6f.

📒 Files selected for processing (3)
  • MainPage.xaml.cs
  • Models/MonitorInfo.cs
  • Services/MonitorService.cs
 ___________________________________________________________________
< Your PR title says 'refactor'. My diff viewer says 'crime scene'. >
 -------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
📝 Walkthrough

Walkthrough

RefreshMonitors now preserves the selected monitor during refreshes. MainWindow listens for visibility changes and refreshes monitor state when the window becomes visible.

Changes

Monitor refresh lifecycle

Layer / File(s) Summary
Preserve monitor selection
MainPage.xaml.cs
RefreshMonitors restores the prior monitor by name and falls back to the primary monitor when unavailable.
Refresh on window visibility
MainWindow.xaml.cs
MainWindow handles AppWindow.Changed and calls RefreshMonitors() when the window becomes visible.

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

Sequence Diagram(s)

sequenceDiagram
  participant AppWindow
  participant MainWindow
  participant MainPage
  AppWindow->>MainWindow: DidVisibilityChange
  MainWindow->>MainPage: RefreshMonitors()
  MainPage->>MainPage: Restore selected monitor or choose primary
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: refreshing monitor handles when the app window becomes visible.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)

✅ Unit Test PR creation complete.

  • Create PR with unit tests
  • Commit unit tests in branch fix-stale-monitor-handles

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@MainPage.xaml.cs`:
- Around line 27-34: Update MonitorInfo to expose a stable monitor/device
identifier derived from MONITORINFOEX.DeviceName, then change the selection
preservation logic in MainPage to capture and compare that identifier instead of
Name. Keep the existing primary-monitor fallback for cases where no matching
device is found.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 317c68ba-f23d-4142-9385-4b349929e2aa

📥 Commits

Reviewing files that changed from the base of the PR and between 883c51b and 1b9f2d8.

📒 Files selected for processing (2)
  • MainPage.xaml.cs
  • MainWindow.xaml.cs

Comment thread MainPage.xaml.cs
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Note

Unit test generation is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

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

🧹 Nitpick comments (1)
Models/MonitorInfo.cs (1)

9-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Clarify whether this is a device ID or a display name.

Services/MonitorService.cs:28 assigns mi.DeviceName to this property. If that logical display name is intentional, rename the property to DeviceName; otherwise populate DeviceId with the actual device-interface identifier.

As per coding guidelines, use meaningful names.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Models/MonitorInfo.cs` at line 9, Resolve the naming mismatch between
MonitorInfo.DeviceId and the mi.DeviceName assignment in MonitorService by
either renaming the property to DeviceName when it represents the display name,
or updating the assignment to use the actual device-interface identifier. Keep
the property name and assigned value semantically consistent throughout the
affected model and service.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@Models/MonitorInfo.cs`:
- Line 9: Resolve the naming mismatch between MonitorInfo.DeviceId and the
mi.DeviceName assignment in MonitorService by either renaming the property to
DeviceName when it represents the display name, or updating the assignment to
use the actual device-interface identifier. Keep the property name and assigned
value semantically consistent throughout the affected model and service.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 60f9b845-7c49-4df9-b96f-330cfd9c0c9a

📥 Commits

Reviewing files that changed from the base of the PR and between 1b9f2d8 and 5fedc6f.

📒 Files selected for processing (3)
  • MainPage.xaml.cs
  • Models/MonitorInfo.cs
  • Services/MonitorService.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • MainPage.xaml.cs

@stabldev
stabldev merged commit a24ba8e into main Jul 12, 2026
1 check passed
@stabldev
stabldev deleted the fix-stale-monitor-handles branch July 12, 2026 05:58
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

✅ Created PR with unit tests: #29

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