From 511067981dcf546c40adc0289420fe88d2a635d3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 24 Jul 2020 10:01:37 +0400 Subject: [PATCH] Forbid auto-night mode with theme editor. --- Telegram/SourceFiles/core/application.cpp | 3 +++ Telegram/SourceFiles/settings/settings_chat.cpp | 10 ++++++++-- .../window/themes/window_theme_editor_box.cpp | 4 ++++ Telegram/SourceFiles/window/window_main_menu.cpp | 5 +++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index ecb5677028..bddaaf9792 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -309,6 +309,9 @@ void Application::checkSystemDarkMode() { } void Application::startSystemDarkModeViewer() { + if (Window::Theme::Background()->editingTheme()) { + _settings.setSystemDarkModeEnabled(false); + } rpl::merge( _settings.systemDarkModeChanges() | rpl::to_empty, _settings.systemDarkModeEnabledChanges() | rpl::to_empty diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 1ac1c4b940..8633a560e0 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -1294,8 +1294,14 @@ void SetupAutoNightMode(not_null container) { ) | rpl::filter([=](bool checked) { return (checked != Core::App().settings().systemDarkModeEnabled()); }) | rpl::start_with_next([=](bool checked) { - Core::App().settings().setSystemDarkModeEnabled(checked); - Core::App().saveSettingsDelayed(); + if (checked && Window::Theme::Background()->editingTheme()) { + autoNight->setChecked(false); + Ui::show(Box( + tr::lng_theme_editor_cant_change_theme(tr::now))); + } else { + Core::App().settings().setSystemDarkModeEnabled(checked); + Core::App().saveSettingsDelayed(); + } }, autoNight->lifetime()); Core::App().settings().systemDarkModeEnabledChanges( diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index 7c6ad57901..4afde74c40 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -676,6 +676,10 @@ void StartEditor( window->show(Box(tr::lng_theme_editor_error(tr::now))); return; } + if (Core::App().settings().systemDarkModeEnabled()) { + Core::App().settings().setSystemDarkModeEnabled(false); + Core::App().saveSettingsDelayed(); + } Background()->setEditingTheme(cloud); window->showRightColumn(Box(window, cloud)); } diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 28be35d9c4..5836cf69f6 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -880,6 +880,11 @@ void MainMenu::refreshMenu() { _nightThemeAction = std::make_shared>(); auto action = _menu->addAction(tr::lng_menu_night_mode(tr::now), [=] { + if (Window::Theme::Background()->editingTheme()) { + Ui::show(Box( + tr::lng_theme_editor_cant_change_theme(tr::now))); + return; + } const auto weak = MakeWeak(this); const auto toggle = [=] { if (!weak) {