Skip to content

Commit

Permalink
Merge branch 'rabbit_boost' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xmdnx committed Nov 22, 2023
2 parents 437bd1e + 302a583 commit ebe1d98
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 37 deletions.
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/rabbit/settings/rabbit_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
{ "side_menu_saved_messages", {
.type = SettingType::BoolSetting,
.defaultValue = true, }},
{ "side_menu_night_mode", {
.type = SettingType::BoolSetting,
.defaultValue = true, }},
// Chats
{ "sticker_height", {
.type = SettingType::IntSetting,
Expand Down
15 changes: 15 additions & 0 deletions Telegram/SourceFiles/rabbit/settings_menu/rabbit_settings_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ namespace Settings {
::RabbitSettings::JsonSettings::Set("side_menu_saved_messages", enabled);
::RabbitSettings::JsonSettings::Write();
}, container->lifetime());

AddButtonWithIcon(
container,
tr::lng_menu_night_mode(),
st::settingsButton,
IconDescriptor{ &st::menuIconNightMode }
)->toggleOn(
rpl::single(::RabbitSettings::JsonSettings::GetBool("side_menu_night_mode"))
)->toggledValue(
) | rpl::filter([](bool enabled) {
return (enabled != ::RabbitSettings::JsonSettings::GetBool("side_menu_night_mode"));
}) | rpl::start_with_next([](bool enabled) {
::RabbitSettings::JsonSettings::Set("side_menu_night_mode", enabled);
::RabbitSettings::JsonSettings::Write();
}, container->lifetime());
}

void Rabbit::SetupChats(not_null<Ui::VerticalLayout *> container) {
Expand Down
76 changes: 39 additions & 37 deletions Telegram/SourceFiles/window/window_main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,44 +955,46 @@ void MainMenu::setupMenu() {
controller->showSettings();
});

_nightThemeToggle = addAction(
tr::lng_menu_night_mode(),
{ &st::menuIconNightMode }
)->toggleOn(_nightThemeSwitches.events_starting_with(
Window::Theme::IsNightMode()
));
_nightThemeToggle->toggledChanges(
) | rpl::filter([=](bool night) {
return (night != Window::Theme::IsNightMode());
}) | rpl::start_with_next([=](bool night) {
if (Window::Theme::Background()->editingTheme()) {
_nightThemeSwitches.fire(!night);
controller->show(Ui::MakeInformBox(
tr::lng_theme_editor_cant_change_theme()));
return;
}
const auto weak = MakeWeak(this);
const auto toggle = [=] {
if (!weak) {
Window::Theme::ToggleNightMode();
Window::Theme::KeepApplied();
} else {
_nightThemeSwitch.callOnce(st::mainMenu.itemToggle.duration);
if (RabbitSettings::JsonSettings::GetBool("side_menu_night_mode")) {
_nightThemeToggle = addAction(
tr::lng_menu_night_mode(),
{ &st::menuIconNightMode }
)->toggleOn(_nightThemeSwitches.events_starting_with(
Window::Theme::IsNightMode()
));
_nightThemeToggle->toggledChanges(
) | rpl::filter([=](bool night) {
return (night != Window::Theme::IsNightMode());
}) | rpl::start_with_next([=](bool night) {
if (Window::Theme::Background()->editingTheme()) {
_nightThemeSwitches.fire(!night);
controller->show(Ui::MakeInformBox(
tr::lng_theme_editor_cant_change_theme()));
return;
}
};
Window::Theme::ToggleNightModeWithConfirmation(
&_controller->window(),
toggle);
}, _nightThemeToggle->lifetime());

Core::App().settings().systemDarkModeValue(
) | rpl::start_with_next([=](std::optional<bool> darkMode) {
const auto darkModeEnabled
= Core::App().settings().systemDarkModeEnabled();
if (darkModeEnabled && darkMode.has_value()) {
_nightThemeSwitches.fire_copy(*darkMode);
}
}, _nightThemeToggle->lifetime());
const auto weak = MakeWeak(this);
const auto toggle = [=] {
if (!weak) {
Window::Theme::ToggleNightMode();
Window::Theme::KeepApplied();
} else {
_nightThemeSwitch.callOnce(st::mainMenu.itemToggle.duration);
}
};
Window::Theme::ToggleNightModeWithConfirmation(
&_controller->window(),
toggle);
}, _nightThemeToggle->lifetime());

Core::App().settings().systemDarkModeValue(
) | rpl::start_with_next([=](std::optional<bool> darkMode) {
const auto darkModeEnabled
= Core::App().settings().systemDarkModeEnabled();
if (darkModeEnabled && darkMode.has_value()) {
_nightThemeSwitches.fire_copy(*darkMode);
}
}, _nightThemeToggle->lifetime());
}
}

void MainMenu::resizeEvent(QResizeEvent *e) {
Expand Down

0 comments on commit ebe1d98

Please sign in to comment.