Support for color scheme change

This commit is contained in:
Jack251970 2025-07-06 09:08:20 +08:00
parent 15d979bc2c
commit c71da5413a
3 changed files with 12 additions and 5 deletions

View file

@ -801,16 +801,22 @@ namespace Flow.Launcher.Infrastructure
[DllImport("uxtheme.dll", EntryPoint = "#135", SetLastError = true)]
private static extern int SetPreferredAppMode(int appMode);
public static void EnableWin32DarkMode()
public static void EnableWin32DarkMode(string colorScheme)
{
try
{
// From Windows 10 1809
// AppMode: 0=Default, 1=AllowDark, 2=ForceDark, 3=ForceLight, 4=Max
// Undocumented API from Windows 10 1809
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
Environment.OSVersion.Version.Build >= 17763)
{
_ = SetPreferredAppMode(1);
var flag = colorScheme switch
{
Constant.Light => 3, // ForceLight
Constant.Dark => 2, // ForceDark
Constant.System => 1, // AllowDark
_ => 0 // Default
};
_ = SetPreferredAppMode(flag);
}
}

View file

@ -189,7 +189,7 @@ namespace Flow.Launcher
Notification.Install();
// Enable Win32 dark mode if the system is in dark mode before creating all windows
Win32Helper.EnableWin32DarkMode();
Win32Helper.EnableWin32DarkMode(_settings.ColorScheme);
Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();

View file

@ -136,6 +136,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
};
Settings.ColorScheme = value;
_ = _theme.RefreshFrameAsync();
Win32Helper.EnableWin32DarkMode(value);
}
}