mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #3798 from Flow-Launcher/win32_dark_mode
Enable dark mode if the system is in dark mode for Win32 windows
This commit is contained in:
commit
1e9eaf5db8
3 changed files with 40 additions and 0 deletions
|
|
@ -791,5 +791,41 @@ namespace Flow.Launcher.Infrastructure
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Win32 Dark Mode
|
||||
|
||||
/*
|
||||
* Inspired by https://github.com/ysc3839/win32-darkmode
|
||||
*/
|
||||
|
||||
[DllImport("uxtheme.dll", EntryPoint = "#135", SetLastError = true)]
|
||||
private static extern int SetPreferredAppMode(int appMode);
|
||||
|
||||
public static void EnableWin32DarkMode(string colorScheme)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Undocumented API from Windows 10 1809
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
|
||||
Environment.OSVersion.Version.Build >= 17763)
|
||||
{
|
||||
var flag = colorScheme switch
|
||||
{
|
||||
Constant.Light => 3, // ForceLight
|
||||
Constant.Dark => 2, // ForceDark
|
||||
Constant.System => 1, // AllowDark
|
||||
_ => 0 // Default
|
||||
};
|
||||
_ = SetPreferredAppMode(flag);
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore errors on unsupported OS
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,6 +188,9 @@ namespace Flow.Launcher
|
|||
|
||||
Notification.Install();
|
||||
|
||||
// Enable Win32 dark mode if the system is in dark mode before creating all windows
|
||||
Win32Helper.EnableWin32DarkMode(_settings.ColorScheme);
|
||||
|
||||
Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();
|
||||
|
||||
API.LogInfo(ClassName, "Begin Flow Launcher startup ----------------------------------------------------");
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
};
|
||||
Settings.ColorScheme = value;
|
||||
_ = _theme.RefreshFrameAsync();
|
||||
Win32Helper.EnableWin32DarkMode(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue