diff --git a/Dotnet/Cef/WinformThemer.cs b/Dotnet/Cef/WinformThemer.cs index 16490c5d..da3b5c2d 100644 --- a/Dotnet/Cef/WinformThemer.cs +++ b/Dotnet/Cef/WinformThemer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -24,15 +24,19 @@ namespace VRCX /// /// Private holder of current theme /// - private static int currentTheme; + private static int currentTheme = -1; /// /// Sets the global theme of the app /// Light = 0 /// Dark = 1 + /// Midnight = 2 /// public static void SetGlobalTheme(int theme) { + if (currentTheme == theme) + return; + currentTheme = theme; //Make a seperate list for all current forms (causes issues otherwise) @@ -91,18 +95,20 @@ namespace VRCX private static void SetThemeToGlobal(IntPtr handle) { - int whiteColor = 0xFFFFFF; - int blackColor = 0x000000; - if (GetTheme(handle) != currentTheme) - { - if (PInvoke.DwmSetWindowAttribute(handle, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, ref currentTheme, sizeof(int)) != 0) - PInvoke.DwmSetWindowAttribute(handle, DWMWA_USE_IMMERSIVE_DARK_MODE, ref currentTheme, sizeof(int)); + var whiteColor = 0xFFFFFF; + var blackColor = 0x000000; + var greyColor = 0x2B2B2B; + + var isDark = currentTheme > 0 ? 1 : 0; + if (PInvoke.DwmSetWindowAttribute(handle, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, ref isDark, sizeof(int)) != 0) + PInvoke.DwmSetWindowAttribute(handle, DWMWA_USE_IMMERSIVE_DARK_MODE, ref isDark, sizeof(int)); - if (currentTheme == 1) - PInvoke.DwmSetWindowAttribute(handle, DWMWA_CAPTION_COLOR, ref blackColor, sizeof(int)); - else - PInvoke.DwmSetWindowAttribute(handle, DWMWA_CAPTION_COLOR, ref whiteColor, sizeof(int)); - } + if (currentTheme == 2) + PInvoke.DwmSetWindowAttribute(handle, DWMWA_CAPTION_COLOR, ref blackColor, sizeof(int)); + else if (currentTheme == 1) + PInvoke.DwmSetWindowAttribute(handle, DWMWA_CAPTION_COLOR, ref greyColor, sizeof(int)); + else + PInvoke.DwmSetWindowAttribute(handle, DWMWA_CAPTION_COLOR, ref whiteColor, sizeof(int)); } private static int GetTheme(IntPtr handle) diff --git a/src/shared/utils/base/ui.js b/src/shared/utils/base/ui.js index 0c653754..c6e15ddc 100644 --- a/src/shared/utils/base/ui.js +++ b/src/shared/utils/base/ui.js @@ -106,18 +106,6 @@ function systemIsDarkMode() { return window.matchMedia('(prefers-color-scheme: dark)').matches; } -/** - * - * @param {boolean}isDark - */ -function changeAppDarkStyle(isDark) { - if (isDark) { - AppApi.ChangeTheme(1); - } else { - AppApi.ChangeTheme(0); - } -} - function applyThemeFonts(themeKey, fontLinks = []) { document .querySelectorAll('link[data-theme-font]') @@ -247,7 +235,13 @@ function changeAppThemeStyle(themeMode) { } else { document.documentElement.classList.remove('dark'); } - changeAppDarkStyle(themeConfig.isDark); + if (themeConfig.name === 'Midnight') { + AppApi.ChangeTheme(2); + } else if (themeConfig.isDark) { + AppApi.ChangeTheme(1); + } else { + AppApi.ChangeTheme(0); + } return { isDark: themeConfig.isDark }; @@ -462,7 +456,6 @@ function redirectToToolsTab() { export { systemIsDarkMode, - changeAppDarkStyle, changeAppThemeStyle, useThemeColor, applyThemeColor,