Enable Win32 dark mode if the system is in dark mode before creating all windows

This commit is contained in:
Jack251970 2025-07-05 23:05:49 +08:00
parent 8e6eaf728d
commit 15d979bc2c
2 changed files with 33 additions and 0 deletions

View file

@ -791,5 +791,35 @@ 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()
{
try
{
// From Windows 10 1809
// AppMode: 0=Default, 1=AllowDark, 2=ForceDark, 3=ForceLight, 4=Max
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
Environment.OSVersion.Version.Build >= 17763)
{
_ = SetPreferredAppMode(1);
}
}
catch
{
// Ignore errors on unsupported OS
}
}
#endregion
}
}

View file

@ -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();
Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();
API.LogInfo(ClassName, "Begin Flow Launcher startup ----------------------------------------------------");