Repository: electron/electron
File: shell/browser/api/electron_api_base_window.cc (C++)

Code before:
  bool accent_color = false;
  std::string accent_color_string;
  if (args->GetNext(&accent_color_string)) {
    window_->SetAccentColor(accent_color_string);
  } else if (args->GetNext(&accent_color)) {
    window_->SetAccentColor(accent_color);
  } else {
    args->ThrowError(
        "Invalid accent color value - must be a string or boolean");
  }
}

v8::Local<v8::Value> BaseWindow::GetAccentColor() const {
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  auto accent_color = window_->GetAccentColor();

  if (std::holds_alternative<bool>(accent_color)) {
    return v8::Boolean::New(isolate, std::get<bool>(accent_color));
  } else if (std::holds_alternative<std::string>(accent_color)) {
    return gin::StringToV8(isolate, std::get<std::string>(accent_color));
  }

  return v8::Null(isolate);
}
#endif

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
void BaseWindow::SetTitleBarOverlay(const gin_helper::Dictionary& options,
                                    gin_helper::Arguments* args) {
  static_cast<NativeWindowViews*>(window_.get())
      ->SetTitleBarOverlay(options, args);
}
#endif

void BaseWindow::RemoveFromParentChildWindows() {
  if (parent_window_.IsEmpty())
    return;

  v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
  v8::HandleScope handle_scope(isolate);
  gin::Handle<BaseWindow> parent;
  if (!gin::ConvertFromV8(isolate, GetParentWindow(), &parent) ||
      parent.IsEmpty()) {
    return;
  }

  parent->child_windows_.Remove(weak_map_id());
}

// static
gin_helper::WrappableBase* BaseWindow::New(gin_helper::Arguments* args) {

Review comment (suggestion):
Can be replaced with `gin::ConvertToV8` to handle type differences.

Code after:
  bool accent_color = false;
  std::string accent_color_string;
  if (args->GetNext(&accent_color_string)) {
    std::optional<SkColor> maybe_color = ParseCSSColor(accent_color_string);
    if (maybe_color.has_value()) {
      window_->SetAccentColor(maybe_color.value());
      window_->UpdateWindowAccentColor(window_->IsActive());
    }
  } else if (args->GetNext(&accent_color)) {
    window_->SetAccentColor(accent_color);
    window_->UpdateWindowAccentColor(window_->IsActive());
  } else {
    args->ThrowError(
        "Invalid accent color value - must be a string or boolean");
  }
}

v8::Local<v8::Value> BaseWindow::GetAccentColor() const {
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  auto accent_color = window_->GetAccentColor();

  if (std::holds_alternative<bool>(accent_color))
    return v8::Boolean::New(isolate, std::get<bool>(accent_color));
  return gin::StringToV8(isolate, std::get<std::string>(accent_color));
}
#endif

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
void BaseWindow::SetTitleBarOverlay(const gin_helper::Dictionary& options,
                                    gin_helper::Arguments* args) {
  static_cast<NativeWindowViews*>(window_.get())
      ->SetTitleBarOverlay(options, args);
}
#endif

void BaseWindow::RemoveFromParentChildWindows() {
  if (parent_window_.IsEmpty())
    return;

  v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
  v8::HandleScope handle_scope(isolate);
  gin::Handle<BaseWindow> parent;
  if (!gin::ConvertFromV8(isolate, GetParentWindow(), &parent) ||
      parent.IsEmpty()) {
    return;
  }

  parent->child_windows_.Remove(weak_map_id());
}

// static