Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible content frame navigation issue in welcome window & setting window #3088

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

Jack251970
Copy link
Contributor

Long before, when I have upgraded Flow.Launcher to v1.19.x version, I encountered the setting window navigation issue like this:
Screenshot 2024-11-21 214502
(Note: This is just a demo screenshot. I just cannot find the original screenshot. :( I forget to create a issue for this.)

Now, I fix this possible issue to make sure the navigation event will only happen after all ui components are loaded. (I guess this is the problem)

@prlabeler prlabeler bot added the bug Something isn't working label Nov 21, 2024

This comment has been minimized.

Copy link

gitstream-cm bot commented Nov 21, 2024

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 Nov 21, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes primarily involve enhancements to the user interface and navigation logic of the Flow.Launcher application. The SettingWindow.xaml file introduces a new grid layout and a NavigationView for improved organization of UI elements. The SettingWindow.xaml.cs file adds methods for initializing navigation and handling events. Similar modifications are made to the WelcomeWindow, including adjustments to the XAML layout and navigation logic to ensure the correct page is displayed upon loading. Overall, these updates aim to improve the user experience and application functionality.

Changes

File Change Summary
Flow.Launcher/SettingWindow.xaml Added a grid layout, title bar with buttons, and a NavigationView with multiple items.
Flow.Launcher/SettingWindow.xaml.cs Introduced methods for navigation initialization (NavView_Loaded, ContentFrame_Loaded). Added null checks in NavigationView_SelectionChanged.
Flow.Launcher/WelcomeWindow.xaml Adjusted margin attributes and added Loaded="ContentFrame_Loaded" to ui:Frame.
Flow.Launcher/WelcomeWindow.xaml.cs Added navigation logic in the constructor and ContentFrame_Loaded method for initial page display. Introduced OnActivated method to clear keyboard focus.

Poem

🐇 In the land of code where rabbits play,
New windows and layouts brighten the day.
With navigation clear and margins just right,
Flow.Launcher leaps into the light!
Hopping through settings, a joyful delight,
A user-friendly world, oh what a sight! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6b6b0fa and 929e7d6.

📒 Files selected for processing (1)
  • Flow.Launcher/WelcomeWindow.xaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/WelcomeWindow.xaml

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
Flow.Launcher/WelcomeWindow.xaml.cs (1)

Line range hint 1-115: Consider implementing a navigation service pattern

The current navigation implementation is tightly coupled and could benefit from:

  1. Extracting navigation logic into a dedicated service
  2. Using dependency injection for Settings
  3. Following MVVM pattern for better separation of concerns

This would improve testability, maintainability, and make the navigation logic more reusable across windows.

Example navigation service interface:

public interface INavigationService
{
    void NavigateToPage(int pageNumber, Settings settings);
    bool CanNavigateBack { get; }
    bool CanNavigateForward { get; }
    void NavigateBack();
    void NavigateForward();
}
Flow.Launcher/SettingWindow.xaml.cs (2)

192-202: Consider cleaning up the Loaded event handler

While the implementation correctly handles both immediate and delayed loading scenarios, consider unsubscribing from the Loaded event after it's handled to prevent potential memory leaks.

Here's a suggested implementation:

 private void NavView_Loaded(object sender, RoutedEventArgs e)
 {
     if (ContentFrame.IsLoaded)
     {
         ContentFrame_Loaded(sender, e);
     }
     else
     {
-        ContentFrame.Loaded += ContentFrame_Loaded;
+        void Handler(object s, RoutedEventArgs args)
+        {
+            ContentFrame_Loaded(s, args);
+            ContentFrame.Loaded -= Handler;
+        }
+        ContentFrame.Loaded += Handler;
     }
 }

204-207: Add bounds check for MenuItems collection

While the null-coalescing assignment is elegant, consider adding a bounds check to ensure MenuItems[0] exists before accessing it.

Here's a suggested implementation:

 private void ContentFrame_Loaded(object sender, RoutedEventArgs e)
 {
-    NavView.SelectedItem ??= NavView.MenuItems[0]; /* Set First Page */
+    NavView.SelectedItem ??= NavView.MenuItems.Count > 0 
+        ? NavView.MenuItems[0] 
+        : null; /* Set First Page */
 }
Flow.Launcher/WelcomeWindow.xaml (1)

Line range hint 1-164: Good architectural approach to fixing the navigation issue.

The solution properly addresses the race condition between UI initialization and navigation by:

  1. Using the Loaded event to ensure proper timing
  2. Maintaining a clean separation between UI layout and navigation logic
  3. Keeping the window's fixed dimensions which helps prevent layout issues

This is a robust fix that should prevent similar timing issues in the future.

Flow.Launcher/SettingWindow.xaml (1)

Line range hint 65-97: Manage the visibility of MaximizeButton and RestoreButton

Both MaximizeButton and RestoreButton are placed in the same grid cell (Grid.Row="0", Grid.Column="3"). Without controlling their Visibility, these buttons may overlap, causing UI issues. Implement logic to toggle the Visibility of these buttons based on the window's WindowState.

Apply this diff to manage the visibility:

<!-- Add style triggers to toggle visibility based on window state -->
<Button
    Name="MaximizeButton"
    Grid.Row="0"
    Grid.Column="3"
    Click="OnMaximizeRestoreButtonClick"
    Style="{StaticResource TitleBarButtonStyle}">
    <!-- Existing Path content -->
+   <Button.Style>
+       <Style TargetType="Button">
+           <Setter Property="Visibility" Value="Visible" />
+           <Style.Triggers>
+               <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType=Window}}" Value="Maximized">
+                   <Setter Property="Visibility" Value="Collapsed" />
+               </DataTrigger>
+           </Style.Triggers>
+       </Style>
+   </Button.Style>
</Button>

<Button
    Name="RestoreButton"
    Grid.Row="0"
    Grid.Column="3"
    Click="OnMaximizeRestoreButtonClick"
    Style="{StaticResource TitleBarButtonStyle}">
    <!-- Existing Path content -->
+   <Button.Style>
+       <Style TargetType="Button">
+           <Setter Property="Visibility" Value="Collapsed" />
+           <Style.Triggers>
+               <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType=Window}}" Value="Maximized">
+                   <Setter Property="Visibility" Value="Visible" />
+               </DataTrigger>
+           </Style.Triggers>
+       </Style>
+   </Button.Style>
</Button>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7e9ed8e and 6b6b0fa.

📒 Files selected for processing (4)
  • Flow.Launcher/SettingWindow.xaml (1 hunks)
  • Flow.Launcher/SettingWindow.xaml.cs (2 hunks)
  • Flow.Launcher/WelcomeWindow.xaml (5 hunks)
  • Flow.Launcher/WelcomeWindow.xaml.cs (1 hunks)
🔇 Additional comments (6)
Flow.Launcher/WelcomeWindow.xaml.cs (1)

104-109: Verify OnActivated event subscription

The method implementation looks correct, but ensure it's properly subscribed to the window's Activated event, typically in XAML or constructor.

✅ Verification successful

OnActivated event is properly wired up

The OnActivated method is correctly subscribed to the window's Activated event in the XAML file through the attribute Activated="OnActivated" on the Window element.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for Activated event subscription in XAML
rg -l "Activated=\"OnActivated\"" --type xaml

# Check for programmatic subscription
ast-grep --pattern 'this.Activated += $handler;'

Length of output: 125


Script:

#!/bin/bash
# Check for Activated event subscription in XAML with different file extensions
rg -l "Activated=\"OnActivated\"" -g "*.xaml"

# Check for programmatic subscription with different patterns
ast-grep --pattern 'Activated += OnActivated'

# Find the WelcomeWindow.xaml file to inspect its content
fd "WelcomeWindow.xaml$"

# If found, let's see its content
fd "WelcomeWindow.xaml$" -x cat {}

Length of output: 7149

Flow.Launcher/SettingWindow.xaml.cs (1)

171-175: LGTM: Good defensive programming practice

The null check for selectedItem with fallback to the first page provides a robust solution to handle navigation edge cases and prevents potential crashes.

Flow.Launcher/WelcomeWindow.xaml (3)

46-46: LGTM! Margin format standardization.

The changes standardize margin format to space-separated values, which is the preferred XAML syntax.

Also applies to: 51-51


101-101: LGTM! Layout improvements for navigation controls.

The margin adjustments improve the spacing and alignment of navigation controls.

Since these are visual changes, please verify:

  1. The navigation controls are properly aligned
  2. The spacing between elements looks consistent
  3. The layout works well at different window sizes (the window has fixed dimensions: 550x650)

Also applies to: 115-115, 128-128, 135-135, 141-141


Line range hint 85-89: Good fix for the navigation timing issue.

Adding the ContentFrame_Loaded event handler ensures proper navigation timing by waiting for the frame to be fully loaded before navigation occurs. This directly addresses the reported issue.

Let's verify the implementation of the event handler:

✅ Verification successful

Verified: ContentFrame_Loaded implementation properly handles navigation timing

The implementation in WelcomeWindow.xaml.cs shows that ContentFrame_Loaded correctly navigates to the first page only after the frame is fully loaded:

ContentFrame.Navigate(PageTypeSelector(1), settings); /* Set First Page */

This matches the intended behavior mentioned in the review comment and ensures proper navigation timing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the ContentFrame_Loaded implementation
ast-grep --pattern 'private void ContentFrame_Loaded(object sender, RoutedEventArgs e) {
  $$$
}'

Length of output: 99


Script:

#!/bin/bash
# Let's try a broader search for ContentFrame_Loaded using ripgrep
rg -l "ContentFrame_Loaded" --type-add 'csharp:*.{cs,xaml}' -tcsharp

# Then get the content of files containing this handler
rg "ContentFrame_Loaded" --type-add 'csharp:*.{cs,xaml}' -tcsharp -C 5

Length of output: 3047

Flow.Launcher/SettingWindow.xaml (1)

174-174: Verify that the NavView_Loaded event handler is implemented correctly

The Loaded="NavView_Loaded" attribute has been added to the NavigationView. Ensure that the NavView_Loaded method is properly implemented in SettingWindow.xaml.cs to initialize the navigation view upon loading.

Run the following script to confirm the implementation of NavView_Loaded:

✅ Verification successful

Let me verify the implementation of ContentFrame_Loaded to ensure the complete navigation flow is properly handled.


Let me verify the complete navigation setup by checking the NavView definition and its menu items.


Let me check the menu items definition for the NavView to ensure the navigation setup is complete.


NavView_Loaded implementation is correct and properly integrated

The verification shows that:

  • NavView_Loaded event handler is properly implemented, calling ContentFrame_Loaded when the frame is loaded
  • ContentFrame_Loaded correctly initializes the navigation by selecting the first menu item
  • The navigation structure is complete with:
    • A properly defined ContentFrame for page content
    • NavigationView with menu items (General, Plugins, etc.)
    • Default selection behavior implemented
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for the implementation of NavView_Loaded in SettingWindow.xaml.cs

# Test: Expect to find the method NavView_Loaded in SettingWindow.xaml.cs
rg -A 5 'void\s+NavView_Loaded' Flow.Launcher/SettingWindow.xaml.cs

Length of output: 240


Script:

#!/bin/bash
# Search for ContentFrame_Loaded implementation
rg -A 10 'void\s+ContentFrame_Loaded' Flow.Launcher/SettingWindow.xaml.cs

# Also check if ContentFrame is properly defined in XAML
rg 'ContentFrame' Flow.Launcher/SettingWindow.xaml

Length of output: 442


Script:

#!/bin/bash
# Search for NavView definition and menu items in XAML
rg -A 10 'x:Name="NavView"' Flow.Launcher/SettingWindow.xaml

Length of output: 542


Script:

#!/bin/bash
# Search for MenuItems within NavigationView
rg -B 5 -A 15 '<ui:NavigationView.MenuItems>' Flow.Launcher/SettingWindow.xaml

Length of output: 1241

Flow.Launcher/WelcomeWindow.xaml.cs Show resolved Hide resolved
@taooceros
Copy link
Member

On the other hand would you mind reverting the style change on xaml?

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
❌ ignored-expect-variant 1
⚠️ 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.

@jjw24
Copy link
Member

jjw24 commented Nov 23, 2024

@Jack251970 I suppose this happens very randomly? Have you found a reliable way to reproduce the issue?

@Jack251970
Copy link
Contributor Author

@Jack251970 I suppose this happens very randomly? Have you found a reliable way to reproduce the issue?

If I catch this issue again, I will record all things. Currently no idea about how to reproduce.

@jjw24 jjw24 merged commit db5b773 into Flow-Launcher:dev Nov 25, 2024
6 of 7 checks passed
@jjw24 jjw24 added this to the 1.19.5 milestone Nov 25, 2024
Copy link

gitstream-cm bot commented Nov 25, 2024

🥷 Code experts: onesounds

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

See details

Flow.Launcher/SettingWindow.xaml

Activity based on git-commit:

onesounds
NOV
OCT
SEP
AUG
JUL
JUN 11 additions & 12 deletions

Knowledge based on git-blame:
onesounds: 91%
Yusyuriv: 6%

Flow.Launcher/SettingWindow.xaml.cs

Activity based on git-commit:

onesounds
NOV
OCT
SEP
AUG
JUL
JUN 34 additions & 34 deletions

Knowledge based on git-blame:
Yusyuriv: 58%
onesounds: 12%

Flow.Launcher/WelcomeWindow.xaml

Activity based on git-commit:

onesounds
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
onesounds: 95%

Flow.Launcher/WelcomeWindow.xaml.cs

Activity based on git-commit:

onesounds
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
onesounds: 58%

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

@jjw24 jjw24 modified the milestones: 1.19.5, 1.20.0 Dec 7, 2024
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.

3 participants