-
-
Notifications
You must be signed in to change notification settings - Fork 445
Enable dark mode if the system is in dark mode for Win32 windows #3798
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
Conversation
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
📝 WalkthroughWalkthroughA 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
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)
Suggested reviewers
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Pull request was converted to draft
There was a problem hiding this 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
📒 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
🥷 Code experts: onesounds Jack251970, onesounds have most 👩💻 activity in the files. See details
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame: To learn more about /:\ gitStream - Visit our Docs |
Enable dark mode if the system is in dark mode for Win32 windows
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:
After:
Test