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 font select function #3377

Merged
merged 6 commits into from
Mar 26, 2025

Conversation

onesounds
Copy link
Contributor

@onesounds onesounds commented Mar 24, 2025

What's the PR

  • Fixed an issue where theme font changes were not being applied.
  • Fixed an issue where resources could not be found at certain times during debugging.

What was the problem

  • There was an issue where, due to the timing of removing oldResource, there was a brief moment when no resource dictionaries were present.
  • Font settings were not applied correctly for blur themes because of the timing of blur theme application.

Test Cases

  • Font style changes should be applied in real time regardless of whether a blur theme is used.
  • On first launch, the previously saved font settings should be applied.
  • There should be no "resource not found" messages in debug mode.
    image

…Blur theme

- Removed bold style from highlight and delegated it to individual themes
@prlabeler prlabeler bot added the bug Something isn't working label Mar 24, 2025

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Mar 24, 2025

📝 Walkthrough

Walkthrough

This pull request enhances theme and font management functionality. The core theme file updates resource dictionary retrieval for null safety and introduces methods for updating fonts and applying font settings. The settings view model modifies how font properties are updated, focusing on font changes without altering the overall theme. Additionally, redundant font weight settings have been removed from XAML style definitions, and a minor formatting cleanup was performed in another XAML file.

Changes

File(s) Change Summary
Flow.Launcher.Core/Resource/Theme.cs
Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs
In Theme.cs: Changed resource retrieval from First to FirstOrDefault, introduced new methods (UpdateFonts, ApplyFontSettings, SetFontProperties), and modified ChangeTheme logic. In the view model, replaced _theme.ChangeTheme() with _theme.UpdateFonts() for font properties.
Flow.Launcher/Themes/Base.xaml
Flow.Launcher/Themes/BlurBlack … Darker.xaml
In Base.xaml, removed FontWeight property setters from several styles. In BlurBlack Darker.xaml, removed an extraneous blank line before the SeparatorStyle declaration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SettingsPaneThemeVM
    participant ThemeManager as Theme.cs
    participant UI

    User->>SettingsPaneThemeVM: Update font settings
    SettingsPaneThemeVM->>ThemeManager: UpdateFonts()
    ThemeManager->>ThemeManager: Retrieve ResourceDictionary (FirstOrDefault)
    ThemeManager->>ThemeManager: ApplyFontSettings() to update styles
    ThemeManager->>ThemeManager: SetFontProperties() for text elements
    ThemeManager-->>SettingsPaneThemeVM: Return updated theme
    SettingsPaneThemeVM->>UI: Refresh UI with new font settings
Loading

Possibly related PRs

Suggested labels

bug, kind/ui, 5 min review

Suggested reviewers

  • taooceros

Poem

In a field of code where pixels bloom,
I, a rabbit, hop into a brighter room.
Fonts get a tweak, themes set anew,
With safe checks and updates shining through.
Bugs nibble away as my heart sings in tune,
A joyful journey beneath the crescent moon!
🐰💻

✨ 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.

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

🧹 Nitpick comments (3)
Flow.Launcher.Core/Resource/Theme.cs (3)

20-20: Possible unused import
It appears System.Diagnostics is not used in the file. Consider removing this import to keep the codebase clean.

-using System.Diagnostics;

123-143: Consider user feedback on failure
UpdateFonts() silently logs an error but doesn't inform users if loading the target dictionary fails. Provide a fallback or user-friendly error message to maintain clear feedback.


194-249: Minor duplication
Removing and re-adding font setters is repeated for TextBox vs. TextBlock. A shared helper function to reduce duplication could be beneficial, but this is optional.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ddec1bd and a078777.

📒 Files selected for processing (6)
  • Flow.Launcher.Core/Resource/Theme.cs (6 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (6 hunks)
  • Flow.Launcher/Themes/Base.xaml (0 hunks)
  • Flow.Launcher/Themes/BlurBlack Darker.xaml (1 hunks)
  • Flow.Launcher/Themes/BlurBlack.xaml (1 hunks)
  • Flow.Launcher/Themes/BlurWhite.xaml (1 hunks)
💤 Files with no reviewable changes (1)
  • Flow.Launcher/Themes/Base.xaml
🧰 Additional context used
🧬 Code Definitions (2)
Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (1)
Flow.Launcher.Core/Resource/Theme.cs (1)
  • UpdateFonts (126-143)
Flow.Launcher.Core/Resource/Theme.cs (1)
Flow.Launcher.Infrastructure/Constant.cs (1)
  • Constant (7-57)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (13)
Flow.Launcher/Themes/BlurBlack.xaml (1)

55-57: Addition of HighlightStyle provides consistent text emphasis across themes

The new HighlightStyle adds a standardized way to apply bold formatting to inline text elements, which improves the consistency of text emphasis across the application.

Flow.Launcher/Themes/BlurWhite.xaml (1)

63-65: Addition of HighlightStyle provides consistent text emphasis across themes

The addition of this style with identical properties as in the other theme files ensures that highlighted text appears the same regardless of the selected theme.

Flow.Launcher/Themes/BlurBlack Darker.xaml (1)

57-59: Addition of HighlightStyle provides consistent text emphasis across themes

The addition of HighlightStyle to this theme maintains consistency with the other themes, ensuring highlighted text appears uniformly across all theme variants.

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (6)

345-345: Performance improvement: Using more specific font update method

Replacing _theme.ChangeTheme() with _theme.UpdateFonts() is more efficient as it only refreshes the font resources instead of reloading the entire theme when just the font changes.


367-367: Performance improvement: Using more specific font update method

Using UpdateFonts() instead of a full theme change is more targeted and efficient for font-related updates.


389-389: Performance improvement: Using more specific font update method

Using the dedicated UpdateFonts() method provides better performance by focusing only on updating font resources.


411-411: Performance improvement: Using more specific font update method

The focused font update approach prevents unnecessary resource reloading when only font properties have changed.


435-435: Performance improvement: Using more specific font update method

This change improves UI responsiveness by using a targeted update method instead of triggering a full theme reload.


456-456: Performance improvement: Using more specific font update method

Using the dedicated font update method completes the consistent approach across all font property setters.

Flow.Launcher.Core/Resource/Theme.cs (4)

105-119: Good dictionary update approach
Adding the new resource dictionary first and only then removing the old resource prevents potential flicker and broken references. Looks solid.


148-189: Controlled font updates
ApplyFontSettings properly checks the style keys and updates font properties. The logic is straightforward and correct.


412-430: Asynchronous UI refresh
Invoking _ = RefreshFrameAsync() after updating the dictionary helps the UI adapt smoothly without blocking. The flow is clear and well-handled.


627-627: Consistent resource retrieval
Using GetResourceDictionary(theme) ensures that the newly applied font settings are correctly reflected in the dictionary.

This comment has been minimized.

Copy link

gitstream-cm bot commented Mar 24, 2025

🥷 Code experts: Jack251970

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

See details

Flow.Launcher.Core/Resource/Theme.cs

Activity based on git-commit:

onesounds Jack251970
MAR 989 additions & 867 deletions 805 additions & 891 deletions
FEB 333 additions & 17 deletions 64 additions & 28 deletions
JAN 7 additions & 4 deletions
DEC 2 additions & 96 deletions
NOV 2 additions & 2 deletions
OCT

Knowledge based on git-blame:
Jack251970: 74%
onesounds: 8%

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Activity based on git-commit:

onesounds Jack251970
MAR 147 additions & 80 deletions 80 additions & 99 deletions
FEB 2 additions & 0 deletions 1 additions & 20 deletions
JAN 1 additions & 1 deletions
DEC
NOV 2 additions & 2 deletions
OCT

Knowledge based on git-blame:
onesounds: 24%
Jack251970: 13%

Flow.Launcher/Themes/Base.xaml

Activity based on git-commit:

onesounds Jack251970
MAR 34 additions & 49 deletions
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 67%

Flow.Launcher/Themes/BlurBlack Darker.xaml

Activity based on git-commit:

onesounds Jack251970
MAR 9 additions & 6 deletions
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 69%

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

@Jack251970 Jack251970 added Dev branch only An issue or fix for the Dev branch build and removed bug Something isn't working labels Mar 24, 2025
@Jack251970 Jack251970 added this to the 1.20.0 milestone Mar 24, 2025
@onesounds
Copy link
Contributor Author

@coderabbitai OK now?

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Mar 24, 2025

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get PR details and status
gh pr view 3377 --json state,title,body,comments

# Check commit history for this PR
gh pr view 3377 --json commits

# Look at the conversation thread
gh pr view 3377 --json comments

Length of output: 43887


@onesounds Yes, the PR looks good now! Your latest commit addressing potential null references with _oldResource completes the fixes for the theme font issues. The approach you've taken - using FirstOrDefault for safer resource retrieval, adding dedicated font update methods, and ensuring proper resource management - effectively addresses both the font application problems and the resource availability issues you identified. Is there anything specific you'd like me to review about the implementation?

✅ Actions performed

Comments resolved.

This comment has been minimized.

Copy link
Contributor

@Jack251970 Jack251970 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

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: 0

🧹 Nitpick comments (1)
Flow.Launcher.Core/Resource/Theme.cs (1)

273-320: Consider refactoring to use the new ApplyFontSettings method.

There's duplicated logic between this section and the new ApplyFontSettings method. Consider refactoring the GetResourceDictionary method to use the new ApplyFontSettings method instead of directly manipulating the style setters here.

private ResourceDictionary GetResourceDictionary(string theme)
{
    var dict = GetThemeResourceDictionary(theme);

-   if (dict["QueryBoxStyle"] is Style queryBoxStyle &&
-       dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle)
-   {
-       var fontFamily = new FontFamily(_settings.QueryBoxFont);
-       var fontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.QueryBoxFontStyle);
-       var fontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.QueryBoxFontWeight);
-       var fontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.QueryBoxFontStretch);
-
-       queryBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily));
-       queryBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, fontStyle));
-       queryBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight));
-       queryBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch));
-
-       var caretBrushPropertyValue = queryBoxStyle.Setters.OfType<Setter>().Any(x => x.Property.Name == "CaretBrush");
-       var foregroundPropertyValue = queryBoxStyle.Setters.OfType<Setter>().Where(x => x.Property.Name == "Foreground")
-           .Select(x => x.Value).FirstOrDefault();
-       if (!caretBrushPropertyValue && foregroundPropertyValue != null) //otherwise BaseQueryBoxStyle will handle styling
-           queryBoxStyle.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue));
-
-       // Query suggestion box's font style is aligned with query box
-       querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily));
-       querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, fontStyle));
-       querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight));
-       querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch));
-   }
-
-   if (dict["ItemTitleStyle"] is Style resultItemStyle &&
-       dict["ItemTitleSelectedStyle"] is Style resultItemSelectedStyle &&
-       dict["ItemHotkeyStyle"] is Style resultHotkeyItemStyle &&
-       dict["ItemHotkeySelectedStyle"] is Style resultHotkeyItemSelectedStyle)
-   {
-       Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(_settings.ResultFont));
-       Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultFontStyle));
-       Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultFontWeight));
-       Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultFontStretch));
-
-       Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch };
-       Array.ForEach(
-           new[] { resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o
-           => Array.ForEach(setters, p => o.Setters.Add(p)));
-   }
-
-   if (
-       dict["ItemSubTitleStyle"] is Style resultSubItemStyle &&
-       dict["ItemSubTitleSelectedStyle"] is Style resultSubItemSelectedStyle)
-   {
-       Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(_settings.ResultSubFont));
-       Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultSubFontStyle));
-       Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultSubFontWeight));
-       Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultSubFontStretch));
-
-       Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch };
-       Array.ForEach(
-           new[] { resultSubItemStyle, resultSubItemSelectedStyle }, o
-           => Array.ForEach(setters, p => o.Setters.Add(p)));
-   }
+   // Apply font settings to the theme resource
+   ApplyFontSettings(dict);

    /* Ignore Theme Window Width and use setting */
    var windowStyle = dict["WindowStyle"] as Style;
    var width = _settings.WindowSize;
    windowStyle.Setters.Add(new Setter(FrameworkElement.WidthProperty, width));
    return dict;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2af033b and d212e0e.

📒 Files selected for processing (2)
  • Flow.Launcher.Core/Resource/Theme.cs (8 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (7)
Flow.Launcher.Core/Resource/Theme.cs (7)

59-75: Excellent defensive programming with null safety!

The change from First to FirstOrDefault with proper null handling is a significant improvement that prevents potential crashes. This addresses the resource availability issue mentioned in the PR objectives by properly handling cases when the theme resource is not found.


104-115: Good resource management improvement.

The updated resource dictionary management logic now properly checks if the new dictionary already exists before adding it and only removes the old resource if it exists and is different. This prevents potential resource conflicts and memory leaks.


120-142: Well-implemented font update method.

The new UpdateFonts method properly addresses the issue where theme font changes weren't being applied correctly. It provides a focused way to update just the fonts without changing the entire theme, making the UI refresh more efficient.


147-188: Comprehensive font settings implementation.

This method properly applies font settings to all relevant UI elements, ensuring consistency across the application interface. Good separation of concerns by having this logic in a dedicated method.


193-248: Well-structured font property management.

The SetFontProperties method efficiently handles font application for both TextBox and TextBlock elements. The removal of existing font-related setters before adding new ones prevents duplicate style definitions.


410-430: Improved theme change logic and error handling.

The updates to the ChangeTheme method make it more robust by using a better error message format and ensuring the resource dictionary is always retrieved with font settings applied. The explicit refresh of the frame and return value are good improvements.


627-635: Good defensive programming with null checks.

The addition of null checks for dictionary, window border style, and main window prevents potential null reference exceptions during the blur effect application process, making the feature more robust.

@onesounds onesounds merged commit 7c418a6 into Flow-Launcher:dev Mar 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
20 min review Dev branch only An issue or fix for the Dev branch build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants