Skip to content

Conversation

onesounds
Copy link
Contributor

@onesounds onesounds commented Apr 14, 2025

What's the PR

  • Fix the following error: an exception occurs when the Content Dialog in ModernWpf has no Owner set.
05:49:12 Exception: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Could not find an owner window for this ContentDialog.) ---> System.InvalidOperationException: Could not find an owner window for this ContentDialog. at ModernWpf.Controls.ContentDialog.ShowAsync() at Flow.Launcher.HotkeyControl.OpenHotkeyDialogAsync() in C:\DEV\Flow Launcher\Flow.Launcher\HotkeyControl.xaml.cs:line 246 --- End of inner exception stack trac
  • Fix the Win32Exception
System.ComponentModel.Win32Exception (0x80004005): 작업을 완료했습니다.
   at Flow.Launcher.Infrastructure.Win32Helper.SwitchToEnglishKeyboardLayout(Boolean backupPrevious) in C:\DEV\Flow Launcher\Flow.Launcher.Infrastructure\Win32Helper.cs:line 382
   at Flow.Launcher.ViewModel.MainViewModel.Show() in C:\DEV\Flow Launcher\Flow.Launcher\ViewModel\MainViewModel.cs:line 1548
   at Flow.Launcher.ViewModel.MainViewModel.ToggleFlowLauncher() in C:\DEV\Flow Launcher\Flow.Launcher\ViewModel\MainViewModel.cs:line 1468
   at Flow.Launcher.MainWindow.<InitializeNotifyIcon>b__33_0(Object o, RoutedEventArgs e) in C:\DEV\Flow Launcher\Flow.Launcher\MainWindow.xaml.cs:line 616
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 

Steps to Reproduce

  • In a dev build where this PR is not applied, try to change the hotkey. (The first click does nothing, and the dialog appears on the second click.)
  • Close the entire settings window.
  • Try to change the hotkey again.
  • Observe the error.

Verification

  • Try changing the hotkey. (The dialog should appear on the first click.)
  • Close the entire settings window.
  • Try changing the hotkey again.

@prlabeler prlabeler bot added the bug Something isn't working label Apr 14, 2025
@onesounds onesounds self-assigned this Apr 14, 2025
@onesounds
Copy link
Contributor Author

@coderabbitai Review it.

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch PR details
gh pr view 3466 --repo Flow-Launcher/Flow.Launcher --json title,body,additions,deletions,changedFiles,state,author,files

Length of output: 1595


🏁 Script executed:

#!/bin/bash
# Get the diff for the changed file
gh pr diff 3466 --repo Flow-Launcher/Flow.Launcher

Length of output: 578


@onesounds I've reviewed PR #3466 "Fix Content Dialog owner".

This is a good fix for the exception that occurs when trying to change hotkeys after closing the settings window. The problem was that the ContentDialog had no owner window set, which caused an InvalidOperationException when ShowAsync() was called.

The solution to set dialog.Owner = Window.GetWindow(this) properly establishes the parent-child relationship for the dialog, ensuring it has a valid owner window. This is the correct approach for fixing this type of error in WPF applications.

The change is minimal and focused on addressing just the specific issue. I don't see any potential side effects from this change, and it should resolve the exception described in the PR.

Copy link

gitstream-cm bot commented Apr 14, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

📝 Walkthrough

Walkthrough

The changes update dialog ownership settings in two parts of the application. In HotkeyControl.xaml.cs, the Owner property of HotkeyControlDialog is set to the window containing the current control before showing the dialog asynchronously. In SettingsPanePluginsViewModel.cs, the ContentDialog created in OpenHelperAsync now explicitly sets its Owner property to the main application window. Additionally, an unused using directive is removed and a blank line is deleted. In Win32Helper.cs, the method SwitchToEnglishKeyboardLayout was modified to obtain the foreground window handle directly via PInvoke.GetForegroundWindow() without checking or setting the application main window as foreground. No other logic or control flow changes were made.

Changes

File Change Summary
Flow.Launcher/HotkeyControl.xaml.cs Moved #nullable enable directive; set HotkeyControlDialog.Owner to the parent window before showing dialog async.
Flow.Launcher/SettingPages/ViewModels/...ViewModel.cs Removed unused using; set ContentDialog.Owner to main window; removed an extraneous blank line in dialog setup.
Flow.Launcher.Infrastructure/Win32Helper.cs Modified SwitchToEnglishKeyboardLayout to get foreground window handle directly via PInvoke.GetForegroundWindow() without checking or forcing app window to foreground.

Possibly related PRs

Suggested reviewers

  • onesounds

Poem

A dialog finds its rightful place,
Owned by windows, set with grace.
A line or two, a tidy space,
Ensures each pop-up shows its face.
🐇💻✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9035aa6 and 28c7538.

📒 Files selected for processing (1)
  • Flow.Launcher.Infrastructure/Win32Helper.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (1)
Flow.Launcher.Infrastructure/Win32Helper.cs (1)

368-369: Clean simplification of window handle acquisition.

This change improves the code by directly obtaining the foreground window handle instead of using a more complex approach that involved checking Application.Current and setting windows as foreground. The simplification aligns with the PR's goal of fixing dialog ownership issues while maintaining the same functionality.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@onesounds onesounds requested a review from Jack251970 April 14, 2025 21:01
Jack251970
Jack251970 previously approved these changes Apr 15, 2025
@Jack251970 Jack251970 added this to the 1.20.0 milestone Apr 15, 2025

This comment has been minimized.

@Jack251970 Jack251970 changed the title Fix Content Dialog owner Fix Content Dialog owner & Fix Win32Exception Apr 15, 2025
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link

gitstream-cm bot commented Apr 15, 2025

🥷 Code experts: Jack251970

Jack251970, onesounds have most 👩‍💻 activity in the files.
Jack251970, Yusyuriv have most 🧠 knowledge in the files.

See details

Flow.Launcher.Infrastructure/Win32Helper.cs

Activity based on git-commit:

Jack251970 onesounds
APR 106 additions & 10 deletions 4 additions & 0 deletions
MAR 581 additions & 226 deletions
FEB 13 additions & 16 deletions 22 additions & 0 deletions
JAN 0 additions & 138 deletions
DEC 243 additions & 4 deletions
NOV

Knowledge based on git-blame:
Jack251970: 93%
Yusyuriv: 7%

Flow.Launcher/HotkeyControl.xaml.cs

Activity based on git-commit:

Jack251970 onesounds
APR 4 additions & 9 deletions
MAR 150 additions & 37 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
Jack251970: 44%
Yusyuriv: 16%

Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs

Activity based on git-commit:

Jack251970 onesounds
APR 99 additions & 58 deletions 41 additions & 5 deletions
MAR 2 additions & 1 deletions 69 additions & 0 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
Jack251970: 51%
Yusyuriv: 21%

To learn more about /:\ gitStream - Visit our Docs

@onesounds onesounds merged commit 309a710 into Flow-Launcher:dev Apr 15, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants