Skip to content

Improve code quality#4312

Merged
Jack251970 merged 2 commits intodevfrom
Theme_Enhancement
Mar 9, 2026
Merged

Improve code quality#4312
Jack251970 merged 2 commits intodevfrom
Theme_Enhancement

Conversation

@Jack251970
Copy link
Member

@Jack251970 Jack251970 commented Mar 2, 2026

CHANGES

  • No logical change
  • Improved code style, readability, and comments
  • Replaced static IsBlurTheme() with IsThemeBlurEnabled(dict) for per-theme blur detection

Separated from #4302


Summary by cubic

Refactors theme blur and dark mode handling to be per-theme and more efficient. Behavior should be unchanged for existing themes, with fewer unnecessary system checks.

  • Summary of changes
    • Changed
      • All blur checks now use IsThemeBlurEnabled(dict) instead of a global lookup.
      • BlurEnabled is computed with Win32Helper.IsBackdropSupported() && IsThemeBlurEnabled(dict).
      • Dark mode registry read runs only when SystemBG and ColorScheme are both Auto.
      • Safer pattern matching for backdrop types (is BackdropTypes.Mica or BackdropTypes.MicaAlt).
      • Minor readability updates: var usage, streamlined conditionals, clearer comments.
    • Added
      • Per-theme blur detection via the passed ResourceDictionary, so each theme’s blur flag is respected.
    • Removed
      • Static IsBlurTheme() that used Application resources and bundled OS checks.
    • Memory
      • No material impact. Only local variables and conditional checks; no new caches or long-lived objects.
    • Security
      • No new risks. Reads from HKCU only; no new permissions or external calls.
    • Tests
      • No new unit tests.

Written for commit dad8f3e. Summary will update on new commits.

Refactored Theme.cs to improve theme blur and dark mode handling:
- Replaced static IsBlurTheme() with IsThemeBlurEnabled(dict) for per-theme blur detection.
- Updated all blur checks to use the new method.
- Improved code style, readability, and comments.
- Moved system dark mode registry check to only run when needed.
- Ensured blur and dark mode are applied based on theme and user/system preferences.
Copilot AI review requested due to automatic review settings March 2, 2026 10:06
@github-actions github-actions bot added this to the 2.2.0 milestone Mar 2, 2026
@prlabeler prlabeler bot added Code Refactor enhancement New feature or request labels Mar 2, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

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 refactors Theme.cs for readability while keeping behavior effectively the same, and updates blur detection to be evaluated per theme ResourceDictionary rather than via a global resource lookup.

Changes:

  • Replace IsBlurTheme() with IsThemeBlurEnabled(ResourceDictionary) and use it consistently across theme switching and blur application.
  • Minor readability/style cleanups (use of var, pattern matching is ... or ..., brace/formatting adjustments).
  • Avoid unnecessary registry reads by only querying system dark mode when ColorScheme is effectively “Auto”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gitstream-cm
Copy link

gitstream-cm bot commented Mar 2, 2026

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

Theme.cs refactor: blur capability detection moved from a parameterless helper to a ResourceDictionary-based predicate that also verifies Win32 backdrop support. Font variable declarations were standardized and BackdropType comparisons updated to pattern matching; ChangeTheme and SetBlurForWindow now consult the theme ResourceDictionary for blur capability.

Changes

Cohort / File(s) Summary
Theme Resource & Blur Handling
Flow.Launcher.Core/Resource/Theme.cs
Replaced IsBlurTheme() with IsThemeBlurEnabled(ResourceDictionary dict) and updated calls in ChangeTheme and SetBlurForWindow to use the resource-dictionary check plus Win32Helper.IsBackdropSupported(). Standardized font-related local declarations to var. Replaced equality checks for BackdropType with pattern matching. Minor formatting tweaks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jjw24
  • taooceros
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Improve code quality' is vague and generic, using non-descriptive phrasing that doesn't convey the specific nature of the changes (refactoring blur detection logic). Use a more specific title that highlights the main change, e.g., 'Refactor theme blur detection to be per-theme' or 'Replace static IsBlurTheme() with per-theme blur detection'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly relates to the changeset, detailing the refactoring of blur detection logic, removal of static IsBlurTheme(), and introduction of IsThemeBlurEnabled(dict).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Theme_Enhancement

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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 (1)
Flow.Launcher.Core/Resource/Theme.cs (1)

295-304: Consolidate font-setting logic to a single code path.

Line 295–318 keeps manual font setter construction inside GetResourceDictionary, while UpdateFonts() now relies on ApplyFontSettings(dict). This split increases drift risk. Prefer calling ApplyFontSettings(dict) from GetResourceDictionary and removing the duplicated per-style setter blocks.

♻️ Suggested consolidation
 private ResourceDictionary GetResourceDictionary(string theme)
 {
     var dict = GetThemeResourceDictionary(theme);
-
-    if (dict["QueryBoxStyle"] is Style queryBoxStyle &&
-        dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle)
-    {
-        ...
-    }
-
-    if (dict["ItemTitleStyle"] is Style resultItemStyle &&
-        dict["ItemTitleSelectedStyle"] is Style resultItemSelectedStyle &&
-        dict["ItemHotkeyStyle"] is Style resultHotkeyItemStyle &&
-        dict["ItemHotkeySelectedStyle"] is Style resultHotkeyItemSelectedStyle)
-    {
-        ...
-    }
-
-    if (dict["ItemSubTitleStyle"] is Style resultSubItemStyle &&
-        dict["ItemSubTitleSelectedStyle"] is Style resultSubItemSelectedStyle)
-    {
-        ...
-    }
+    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;
 }

Also applies to: 310-318

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Flow.Launcher.Core/Resource/Theme.cs` around lines 295 - 304,
GetResourceDictionary currently duplicates per-style font Setter construction
that UpdateFonts() already centralizes in ApplyFontSettings(dict); remove the
manual setter block in GetResourceDictionary and instead call
ApplyFontSettings(dict) so all font logic flows through the single method.
Locate the block creating fontFamily/fontStyle/fontWeight/fontStretch and the
Array.ForEach that adds them to resultItemStyle, resultItemSelectedStyle,
resultHotkeyItemStyle, resultHotkeyItemSelectedStyle, delete that block and
invoke ApplyFontSettings(dict) (the same dict used to build styles) to ensure
consistent font application across GetResourceDictionary and UpdateFonts().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Flow.Launcher.Core/Resource/Theme.cs`:
- Line 673: The inline comment referencing the window border style has a typo:
replace the lowercase identifier "windowborderstyle" with the correct PascalCase
symbol "WindowBorderStyle" to match the code style and existing symbol names
(reference BackdropType, Mica, MicaAlt and WindowBorderStyle in Theme.cs) so the
comment reads that if BackdropType is Mica or MicaAlt, set the WindowBorderStyle
background to transparent.

---

Nitpick comments:
In `@Flow.Launcher.Core/Resource/Theme.cs`:
- Around line 295-304: GetResourceDictionary currently duplicates per-style font
Setter construction that UpdateFonts() already centralizes in
ApplyFontSettings(dict); remove the manual setter block in GetResourceDictionary
and instead call ApplyFontSettings(dict) so all font logic flows through the
single method. Locate the block creating
fontFamily/fontStyle/fontWeight/fontStretch and the Array.ForEach that adds them
to resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle,
resultHotkeyItemSelectedStyle, delete that block and invoke
ApplyFontSettings(dict) (the same dict used to build styles) to ensure
consistent font application across GetResourceDictionary and UpdateFonts().

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dda9000 and 6566871.

📒 Files selected for processing (1)
  • Flow.Launcher.Core/Resource/Theme.cs

@Jack251970 Jack251970 enabled auto-merge March 2, 2026 10:12
@coderabbitai coderabbitai bot removed the enhancement New feature or request label Mar 9, 2026
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Flow.Launcher.Core/Resource/Theme.cs (1)

908-916: ⚠️ Potential issue | 🟡 Minor

Include Acrylic in transparent background handling for blur effects.

The pattern match at line 908 only covers Mica and MicaAlt, leaving Acrylic to fall through to the else clause where mainWindow.Background receives the opaque selectedBG color. However, the code comment explicitly states the intent is to "set the background to transparent if the theme supports blur," and Acrylic (which maps to DWMSBT_TRANSIENTWINDOW) also requires transparency for the blur effect to render properly.

Additionally, SetBlurForWindow already handles Acrylic specially by setting its border background to Brushes.Transparent, making the current inconsistency a bug.

🔧 Suggested fix to include Acrylic in transparent handling
-               if (backdropType is BackdropTypes.Mica or BackdropTypes.MicaAlt)
+               if (backdropType is BackdropTypes.Mica or BackdropTypes.MicaAlt or BackdropTypes.Acrylic)
                {
                    mainWindow.Background = ThemeHelper.GetFrozenSolidColorBrush(Color.FromArgb(1, 0, 0, 0));
                }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Flow.Launcher.Core/Resource/Theme.cs` around lines 908 - 916, The backdrop
handling mistakenly treats BackdropTypes.Acrylic like an opaque background;
update the pattern match in the block that sets mainWindow.Background (which
currently checks BackdropTypes.Mica or BackdropTypes.MicaAlt) to also include
BackdropTypes.Acrylic so that
ThemeHelper.GetFrozenSolidColorBrush(Color.FromArgb(1,0,0,0)) is used for
Acrylic as well (matching the transparent handling used in SetBlurForWindow);
this ensures Acrylic gets the transparent background needed for blur effects
instead of receiving selectedBG.
🧹 Nitpick comments (1)
Flow.Launcher.Core/Resource/Theme.cs (1)

832-867: Consider defensive null handling for systemBG.

If the theme's SystemBG value exists but is not a string (e.g., a theme authoring error), as string returns null. The subsequent if-else chain won't match any condition (null != "Dark", etc.), leaving useDarkMode as false.

This silent fallback to light mode is reasonable, but you could make it explicit by treating null the same as "Auto":

💡 Optional: Make the fallback explicit
-            var systemBG = dict.Contains("SystemBG") ? dict["SystemBG"] as string : "Auto";
+            var systemBG = dict.Contains("SystemBG") ? dict["SystemBG"] as string ?? "Auto" : "Auto";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Flow.Launcher.Core/Resource/Theme.cs` around lines 832 - 867, The code
currently does `var systemBG = dict.Contains("SystemBG") ? dict["SystemBG"] as
string : "Auto";` which yields null if the key exists but isn't a string,
causing silent fallback to light mode; change the assignment of systemBG so a
non-string or null value is treated as "Auto" (e.g., coalesce the `as string`
result to "Auto" or use a safe conversion) before the if/else so the subsequent
logic (useDarkMode, _settings.ColorScheme, Registry.GetValue) behaves as if
"Auto".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@Flow.Launcher.Core/Resource/Theme.cs`:
- Around line 908-916: The backdrop handling mistakenly treats
BackdropTypes.Acrylic like an opaque background; update the pattern match in the
block that sets mainWindow.Background (which currently checks BackdropTypes.Mica
or BackdropTypes.MicaAlt) to also include BackdropTypes.Acrylic so that
ThemeHelper.GetFrozenSolidColorBrush(Color.FromArgb(1,0,0,0)) is used for
Acrylic as well (matching the transparent handling used in SetBlurForWindow);
this ensures Acrylic gets the transparent background needed for blur effects
instead of receiving selectedBG.

---

Nitpick comments:
In `@Flow.Launcher.Core/Resource/Theme.cs`:
- Around line 832-867: The code currently does `var systemBG =
dict.Contains("SystemBG") ? dict["SystemBG"] as string : "Auto";` which yields
null if the key exists but isn't a string, causing silent fallback to light
mode; change the assignment of systemBG so a non-string or null value is treated
as "Auto" (e.g., coalesce the `as string` result to "Auto" or use a safe
conversion) before the if/else so the subsequent logic (useDarkMode,
_settings.ColorScheme, Registry.GetValue) behaves as if "Auto".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a1ceae95-414d-43d5-afdf-c49085a35bc9

📥 Commits

Reviewing files that changed from the base of the PR and between 6566871 and dad8f3e.

📒 Files selected for processing (1)
  • Flow.Launcher.Core/Resource/Theme.cs

@Jack251970 Jack251970 merged commit 916b4ff into dev Mar 9, 2026
14 checks passed
@Jack251970 Jack251970 deleted the Theme_Enhancement branch March 9, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants