Skip to content

Conversation

Jack251970
Copy link
Member

@Jack251970 Jack251970 commented Jul 5, 2025

Enable dark mode if the system is in dark mode for Win32 windows

For Win32 windows which cannot be set to dark mode by ModerWPFUI, we need to call EnableWin32DarkMode API to enable its dark mode.

And when users change the application theme mode setting, we should reset this API.

Example: Explorer context menu window.

Before:

Screenshot 2025-07-05 225314

After:

Screenshot 2025-07-05 230356

Test

  • Force light / Force dark / System theme change all work well

@Jack251970 Jack251970 enabled auto-merge July 5, 2025 15:08
@Jack251970 Jack251970 added this to the 2.0.0 milestone Jul 5, 2025
@Jack251970 Jack251970 added the enhancement New feature or request label Jul 5, 2025
Copy link

gitstream-cm bot commented Jul 5, 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 Jul 5, 2025

📝 Walkthrough

Walkthrough

A new method to enable Win32 dark mode was added to the Win32Helper class, utilizing a P/Invoke call to an undocumented Windows API. This method is now invoked during the application's startup sequence and also when the color scheme setting changes, ensuring that all windows respect the system's dark mode setting on supported Windows versions.

Changes

File(s) Change Summary
Flow.Launcher.Infrastructure/Win32Helper.cs Added P/Invoke for SetPreferredAppMode; introduced EnableWin32DarkMode() to set Win32 dark mode.
Flow.Launcher/App.xaml.cs Calls EnableWin32DarkMode() during application startup before window creation.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs Calls EnableWin32DarkMode() in ColorScheme setter after theme refresh to update Win32 dark mode.

Sequence Diagram(s)

sequenceDiagram
    participant OS
    participant App.xaml.cs
    participant Win32Helper
    participant uxtheme.dll

    OS->>App.xaml.cs: Start application
    App.xaml.cs->>Win32Helper: EnableWin32DarkMode(colorScheme)
    Win32Helper->>uxtheme.dll: SetPreferredAppMode(mappedFlag)
    uxtheme.dll-->>Win32Helper: (Result)
    Win32Helper-->>App.xaml.cs: (Returns)
    App.xaml.cs->>App.xaml.cs: Continue startup, create windows

    Note over App.xaml.cs, Win32Helper: Later, when ColorScheme changes:
    App.xaml.cs->>SettingsPaneThemeViewModel: ColorScheme setter invoked
    SettingsPaneThemeViewModel->>Win32Helper: EnableWin32DarkMode(newColorScheme)
    Win32Helper->>uxtheme.dll: SetPreferredAppMode(mappedFlag)
    uxtheme.dll-->>Win32Helper: (Result)
    Win32Helper-->>SettingsPaneThemeViewModel: (Returns)
Loading

Suggested reviewers

  • jjw24
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@Jack251970 Jack251970 marked this pull request as draft July 5, 2025 16:34
auto-merge was automatically disabled July 5, 2025 16:34

Pull request was converted to draft

@Jack251970 Jack251970 marked this pull request as ready for review July 6, 2025 01:08
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/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (1)

137-140: Consider awaiting the async operation before enabling Win32 dark mode.

The call to Win32Helper.EnableWin32DarkMode(value) happens immediately after _theme.RefreshFrameAsync(), but since the async method is not awaited, there could be a timing issue where the Win32 dark mode is enabled before the theme frame is fully refreshed.

Consider making the setter async and awaiting the refresh operation:

-        set
+        set async
         {
             ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme = value switch
             {
                 Constant.Light => ApplicationTheme.Light,
                 Constant.Dark => ApplicationTheme.Dark,
                 Constant.System => null,
                 _ => ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme
             };
             Settings.ColorScheme = value;
-            _ = _theme.RefreshFrameAsync();
+            await _theme.RefreshFrameAsync();
             Win32Helper.EnableWin32DarkMode(value);
         }

Alternatively, if making the setter async is not feasible, consider whether the Win32 dark mode setting needs to wait for the theme refresh to complete, or if the current implementation is acceptable given that EnableWin32DarkMode operates independently of the theme frame refresh.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 15d979b and c71da54.

📒 Files selected for processing (3)
  • Flow.Launcher.Infrastructure/Win32Helper.cs (1 hunks)
  • Flow.Launcher/App.xaml.cs (1 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • Flow.Launcher/App.xaml.cs
  • Flow.Launcher.Infrastructure/Win32Helper.cs
🧰 Additional context used
🧬 Code Graph Analysis (1)
Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (1)
Flow.Launcher.Infrastructure/Win32Helper.cs (2)
  • Win32Helper (28-830)
  • EnableWin32DarkMode (804-827)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build

Copy link

gitstream-cm bot commented Jul 6, 2025

🥷 Code experts: onesounds

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

See details

Flow.Launcher.Infrastructure/Win32Helper.cs

Activity based on git-commit:

Jack251970 onesounds
JUL
JUN 5 additions & 0 deletions
MAY 110 additions & 3 deletions
APR 202 additions & 33 deletions 4 additions & 0 deletions
MAR 581 additions & 226 deletions
FEB 13 additions & 16 deletions 22 additions & 0 deletions

Knowledge based on git-blame:
Jack251970: 95%

Flow.Launcher/App.xaml.cs

Activity based on git-commit:

Jack251970 onesounds
JUL
JUN 3 additions & 0 deletions
MAY 51 additions & 28 deletions
APR 73 additions & 40 deletions 3 additions & 0 deletions
MAR 168 additions & 94 deletions
FEB 79 additions & 40 deletions

Knowledge based on git-blame:
Jack251970: 69%

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Activity based on git-commit:

Jack251970 onesounds
JUL
JUN 2 additions & 1 deletions
MAY 3 additions & 2 deletions
APR 61 additions & 63 deletions 60 additions & 6 deletions
MAR 111 additions & 111 deletions 155 additions & 87 deletions
FEB 2 additions & 21 deletions 2 additions & 0 deletions

Knowledge based on git-blame:
onesounds: 31%
Jack251970: 22%

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

@jjw24 jjw24 enabled auto-merge July 6, 2025 07:47
@jjw24 jjw24 removed the 5 min review label Jul 6, 2025
@jjw24 jjw24 merged commit 1e9eaf5 into dev Jul 6, 2025
14 checks passed
@jjw24 jjw24 deleted the win32_dark_mode branch July 6, 2025 07:49
TBM13 pushed a commit to TBM13/Flow.Launcher that referenced this pull request Jul 8, 2025
Enable dark mode if the system is in dark mode for Win32 windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants