|
| 1 | +/* Copyright (c) 2023 The Brave Authors. All rights reserved. |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | + * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 4 | + * You can obtain one at https://mozilla.org/MPL/2.0/. */ |
| 5 | + |
| 6 | +#include "brave/browser/ui/views/brave_dark_mode_manager_linux.h" |
| 7 | + |
| 8 | +#include "brave/browser/themes/brave_dark_mode_utils.h" |
| 9 | +#include "ui/linux/linux_ui_factory.h" |
| 10 | + |
| 11 | +namespace ui { |
| 12 | + |
| 13 | +BraveDarkModeManagerLinux::BraveDarkModeManagerLinux() |
| 14 | + : DarkModeManagerLinux() { |
| 15 | + // In base class' ctor, |prefer_dark_theme_| is set by calling |
| 16 | + // SetColorScheme() when ui::GetDefaultLinuxUiTheme() |
| 17 | + if (ui::GetDefaultLinuxUiTheme()) { |
| 18 | + dark_mode::CacheSystemDarkModePrefs(prefer_dark_theme_); |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +BraveDarkModeManagerLinux::~BraveDarkModeManagerLinux() = default; |
| 23 | + |
| 24 | +void BraveDarkModeManagerLinux::SetColorScheme(bool prefer_dark_theme, |
| 25 | + bool from_toolkit_theme) { |
| 26 | + dark_mode::CacheSystemDarkModePrefs(prefer_dark_theme); |
| 27 | + if (dark_mode::GetBraveDarkModeType() == |
| 28 | + dark_mode::BraveDarkModeType::BRAVE_DARK_MODE_TYPE_DEFAULT) { |
| 29 | + DarkModeManagerLinux::SetColorScheme(prefer_dark_theme, from_toolkit_theme); |
| 30 | + } else { |
| 31 | + // Make |prefer_dark_theme_| stores latest system theme even brave theme( |
| 32 | + // dark or light) is set. If not, system theme change could not be applied |
| 33 | + // properly later. |
| 34 | + prefer_dark_theme_ = prefer_dark_theme; |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +} // namespace ui |
0 commit comments