feat: honor nativeTheme.themeSource = 'dark' before creating BrowserWindow on Windows (#25373)

* fix: support 'dark' theme before creating windows.
This commit is contained in:
Charles Kerr 2020-10-28 15:00:21 -05:00 committed by GitHub
parent d3f32c7502
commit f489e3054a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 241 additions and 0 deletions

View file

@ -5,9 +5,15 @@
#include "shell/browser/ui/win/electron_desktop_window_tree_host_win.h"
#include "base/win/windows_version.h"
#include "electron/buildflags/buildflags.h"
#include "shell/browser/ui/views/win_frame_view.h"
#include "ui/base/win/hwnd_metrics.h"
#include "ui/base/win/shell.h"
#if BUILDFLAG(ENABLE_WIN_DARK_MODE_WINDOW_UI)
#include "shell/browser/win/dark_mode.h"
#endif
namespace electron {
ElectronDesktopWindowTreeHostWin::ElectronDesktopWindowTreeHostWin(
@ -23,6 +29,15 @@ bool ElectronDesktopWindowTreeHostWin::PreHandleMSG(UINT message,
WPARAM w_param,
LPARAM l_param,
LRESULT* result) {
#if BUILDFLAG(ENABLE_WIN_DARK_MODE_WINDOW_UI)
if (message == WM_NCCREATE) {
HWND const hwnd = GetAcceleratedWidget();
auto const theme_source =
ui::NativeTheme::GetInstanceForNativeUi()->theme_source();
win::SetDarkModeForWindow(hwnd, theme_source);
}
#endif
return native_window_view_->PreHandleMSG(message, w_param, l_param, result);
}