Skip to content

Conversation

@dnenov
Copy link
Collaborator

@dnenov dnenov commented Jun 24, 2025

Purpose

Addresses an issue where the notification popup window was not getting focus correctly after activation. This would lead to the user not being able to close the Dynamo window unless they hit the close 'X' button multiple times. Furthermore, the webView2-hosted component would not correctly capture the mouseover 'hover' interactions. This PR fixes that.

Captured in this jira ticket: Dynamo does not close when click on X with notification open

Before

DynamoSandbox_EuxyXPPPQV

After

DynamoSandbox_TLTMO8TU02

Declarations

Check these if you believe they are true

  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB
  • This PR introduces new feature code involve network connecting and is tested with no-network mode.

Release Notes

  • Fix the notification popup window to allow Dynamo window to be closed correctly (without having to hit 'X' multiple times)
  • small auto-formatting changes
  • Testing not added as no new logic is introduced, just window focus handling

Reviewers

@zeusongit
@reddyashish

FYIs

@jasonstratton
@achintyabhat

- fix to the notification popup window to allow Dynamo window to be closed correctly (without having to hit 'X' multiple times)
@github-actions github-actions bot changed the title notification focus fix DYN-7099: notification focus fix Jun 24, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-7099

dnenov added 4 commits June 25, 2025 12:38
- potential race condition to execute refocus during Dynamo window tear down (not sure why the notification popup would be involved, but possibly linked)
- testing if synchronous call might be better for the smoke test
- clean up alternative code
@dnenov dnenov requested a review from jasonstratton June 25, 2025 15:39
- fixed test failing when no application is found during headless test execution
@aparajit-pratap aparajit-pratap requested a review from Copilot June 25, 2025 20:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the notification popup’s focus handling by reclaiming the main window’s focus when the popup opens and cleans up some XAML formatting.

  • Adds an Opened event handler in XAML and implements NotificationUI_Opened to force focus back to the main window.
  • Implements native calls (SetForegroundWindow, ReleaseCapture) via P/Invoke in NotificationUI.xaml.cs.
  • Applies auto-formatting changes to imports and XAML attributes.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Notifications/View/NotificationUI.xaml.cs Added NotificationUI_Opened handler, ForceMainWindowFocus P/Invoke logic, plus formatting updates
src/Notifications/View/NotificationUI.xaml Wired Opened event, reordered attributes, and cleaned up XAML formatting
Comments suppressed due to low confidence (2)

src/Notifications/View/NotificationUI.xaml.cs:74

  • This new focus-restoration logic is critical for UX; consider adding an integration or UI test to verify the main window regains focus when the popup opens.
        private void NotificationUI_Opened(object sender, EventArgs e)

src/Notifications/View/NotificationUI.xaml.cs:80

  • Add XML documentation comments to ForceMainWindowFocus (and NotificationUI_Opened) to explain their purpose and any platform-specific implications.
        private void ForceMainWindowFocus()

Comment on lines 85 to 93
ReleaseCapture();
SetForegroundWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle);
}

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

Consider adding SetLastError = true to the DllImport attribute and checking Marshal.GetLastWin32Error() after the call to aid debugging if the native call fails.

Suggested change
ReleaseCapture();
SetForegroundWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle);
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
if (!ReleaseCapture())
{
int errorCode = Marshal.GetLastWin32Error();
Console.WriteLine($"ReleaseCapture failed with error code: {errorCode}");
}
if (!SetForegroundWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle))
{
int errorCode = Marshal.GetLastWin32Error();
Console.WriteLine($"SetForegroundWindow failed with error code: {errorCode}");
}
}
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Good suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's now done.

Copy link
Contributor

@jasonstratton jasonstratton left a comment

Choose a reason for hiding this comment

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

As you mentioned in the meeting earlier, there was a lot of formatting changes in the resx, but they are not impactful. The core change of regaining the focus did the trick. Looks good.

@zeusongit
Copy link
Contributor

- added SetLastError to true
- surfacing the errors
@zeusongit zeusongit merged commit e806d54 into DynamoDS:master Jul 2, 2025
27 of 28 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.

4 participants