feat: Add getAccentColor on Linux (#48628)

* feat: Implement `getAccentColor` on Linux

Co-authored-by: Tau Gärtli <git@tau.garden>

* doc: Update OS support for accent color APIs

Co-authored-by: Tau Gärtli <git@tau.garden>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Tau Gärtli <git@tau.garden>
This commit is contained in:
trop[bot]
2025-10-23 16:07:40 +02:00
committed by GitHub
parent e3715b0538
commit 4fda94be9b
4 changed files with 65 additions and 7 deletions

View File

@@ -18,6 +18,11 @@
#include "shell/browser/browser.h"
#include "shell/browser/browser_observer.h"
#endif
#if BUILDFLAG(IS_LINUX)
#include "base/memory/raw_ptr.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_observer.h"
#endif
namespace gin_helper {
template <typename T>
@@ -44,6 +49,9 @@ class SystemPreferences final
#if BUILDFLAG(IS_WIN)
,
public BrowserObserver
#elif BUILDFLAG(IS_LINUX)
,
public ui::NativeThemeObserver
#endif
{
public:
@@ -55,8 +63,8 @@ class SystemPreferences final
v8::Isolate* isolate) override;
const char* GetTypeName() override;
std::string GetAccentColor();
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
static std::string GetAccentColor();
std::string GetColor(gin_helper::ErrorThrower thrower,
const std::string& color);
std::string GetMediaAccessStatus(gin_helper::ErrorThrower thrower,
@@ -117,6 +125,10 @@ class SystemPreferences final
// TODO(MarshallOfSound): Write tests for these methods once we
// are running tests on a Mojave machine
v8::Local<v8::Value> GetEffectiveAppearance(v8::Isolate* isolate);
#elif BUILDFLAG(IS_LINUX)
// ui::NativeThemeObserver:
void OnNativeThemeUpdated(ui::NativeTheme* theme) override;
#endif
v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);
@@ -162,6 +174,12 @@ class SystemPreferences final
// Color/high contrast mode change observer.
base::CallbackListSubscription hwnd_subscription_;
#endif
#if BUILDFLAG(IS_LINUX)
void OnNativeThemeUpdatedOnUI();
raw_ptr<ui::NativeTheme> ui_theme_;
std::string current_accent_color_;
#endif
};
} // namespace electron::api