Repository: electron/electron
Pull request: fix: accent color should reflect system settings without restart

#### Description of Change

Closes https://github.com/electron/electron/issues/47626.
Refs https://github.com/electron/electron/pull/47285#issuecomment-3012764206.

Fixes an issue where a window's accent color didn't reflect system settings without restart.

After this PR:

* System Accent Disabled and `accentColor: undefined` => ❌  Frame does NOT have accent color
* System Accent Disabled and `accentColor: true` => ✅ Frame has accent color
* System Accent Disabled and `accentColor: #rrggbb` => ✅  Frame has accent color
* System Accent Disabled and `accentColor: false` => ❌  Frame does NOT have accent color
* System Accent Enabled and `accentColor: undefined` => ✅ Frame has accent color
* System Accent Enabled and `accentColor: true` => ✅ Frame has accent color
* System Accent Enabled and `accentColor: #rrggbb` => ✅ Frame has accent color
* System Accent Enabled and `accentColor: false` => ❌ Frame does NOT have accent color

cc @bpasero 

#### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] PR description included and stakeholders cc'd
- [x] `npm test` passes
- [x] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).

#### Release Notes

Notes: Fixed an issue where the window required restart in order to recognize system accent color setting change.


Changed files:
filename: shell/browser/native_window_views.h
patch: @@ -319,7 +319,7 @@ class NativeWindowViews : public NativeWindow,
   // Whether the window is currently being moved.
   bool is_moving_ = false;
 
-  std::variant<bool, SkColor> accent_color_ = true;
+  std::variant<std::monostate, bool, SkColor> accent_color_;
 
   std::optional<gfx::Rect> pending_bounds_change_;
 

filename: shell/browser/native_window_views_win.cc
patch: @@ -574,28 +574,42 @@ void NativeWindowViews::UpdateWindowAccentColor() {
   if (base::win::GetVersion() < base::win::Version::WIN11)
     return;
 
-  if (!IsAccentColorOnTitleBarsEnabled())
-    return;
-
   COLORREF border_color;
-  if (std::holds_alternative<bool>(accent_color_)) {
-    // Don't set accent color if the user has disabled it.
-    if (!std::get<bool>(accent_color_))
-      return;
+  bool should_apply_accent = false;
 
-    std::optional<DWORD> accent_color = GetAccentColor();
-    if (!accent_color.has_value())
-      return;
-
-    border_color =
-        RGB(GetRValue(accent_color.value()), GetGValue(accent_color.value()),
-            GetBValue(accent_color.value()));
-  } else {
+  if (std::holds_alternative<bool>(accent_color_)) {
+    bool force_accent = std::get<bool>(accent_color_);
+    if (!force_accent) {
+      should_apply_accent = false;
+    } else {
+      std::optional<DWORD> accent_color = GetAccentColor();
+      if (accent_color.has_value()) {
+        border_color = RGB(GetRValue(accent_color.value()),
+                           GetGValue(accent_color.value()),
+                           GetBValue(accent_color.value()));
+        should_apply_accent = true;
+      }
+    }
+  } else if (std::holds_alternative<SkColor>(accent_color_)) {
     SkColor color = std::get<SkColor>(accent_color_);
     border_color =
         RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color));
+    should_apply_accent = true;
+  } else if (std::holds_alternative<std::monostate>(accent_color_)) {
+    if (IsAccentColorOnTitleBarsEnabled()) {
+      std::optional<DWORD> accent_color = GetAccentColor();
+      if (accent_color.has_value()) {
+        border_color = RGB(GetRValue(accent_color.value()),
+                           GetGValue(accent_color.value()),
+                           GetBValue(accent_color.value()));
+        should_apply_accent = true;
+      }
+    }
   }
 
+  // Reset to default system colors when accent color should not be applied.
+  if (!should_apply_accent)
+    border_color = DWMWA_COLOR_DEFAULT;
   SetWindowBorderAndCaptionColor(GetAcceleratedWidget(), border_color);
 }