Skip to content

Commit 15d979b

Browse files
committed
Enable Win32 dark mode if the system is in dark mode before creating all windows
1 parent 8e6eaf7 commit 15d979b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,5 +791,35 @@ public static unsafe void OpenFolderAndSelectFile(string filePath)
791791
}
792792

793793
#endregion
794+
795+
#region Win32 Dark Mode
796+
797+
/*
798+
* Inspired by https://github.com/ysc3839/win32-darkmode
799+
*/
800+
801+
[DllImport("uxtheme.dll", EntryPoint = "#135", SetLastError = true)]
802+
private static extern int SetPreferredAppMode(int appMode);
803+
804+
public static void EnableWin32DarkMode()
805+
{
806+
try
807+
{
808+
// From Windows 10 1809
809+
// AppMode: 0=Default, 1=AllowDark, 2=ForceDark, 3=ForceLight, 4=Max
810+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
811+
Environment.OSVersion.Version.Build >= 17763)
812+
{
813+
_ = SetPreferredAppMode(1);
814+
}
815+
816+
}
817+
catch
818+
{
819+
// Ignore errors on unsupported OS
820+
}
821+
}
822+
823+
#endregion
794824
}
795825
}

Flow.Launcher/App.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
188188

189189
Notification.Install();
190190

191+
// Enable Win32 dark mode if the system is in dark mode before creating all windows
192+
Win32Helper.EnableWin32DarkMode();
193+
191194
Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();
192195

193196
API.LogInfo(ClassName, "Begin Flow Launcher startup ----------------------------------------------------");

0 commit comments

Comments
 (0)