diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 1ef1e5795..e4ebbeec7 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -155,6 +155,8 @@ "ktg_channel_status_not_in": "not subscribed", "ktg_group_status_owner": "is owner", "ktg_group_status_admin": "is admin", + "ktg_too_many_accounts_warning": "Warning! Using too many accounts at the same time is not recommended due to higher memory comsumption and possible crashes because of it.\n\nYou sure you want to add a new account?", + "ktg_account_add_anyway": "Add anyway", "ktg_forward_go_to_chat": "Go to chat", "ktg_settings_forward": "Forward", "ktg_settings_forward_retain_selection": "Retain selection after forward", diff --git a/Telegram/SourceFiles/main/main_domain.h b/Telegram/SourceFiles/main/main_domain.h index ad4d6f11f..71e5392ee 100644 --- a/Telegram/SourceFiles/main/main_domain.h +++ b/Telegram/SourceFiles/main/main_domain.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/timer.h" +#include "base/build_config.h" namespace Storage { class Domain; @@ -30,7 +31,12 @@ public: std::unique_ptr account; }; - static constexpr auto kMaxAccounts = 3; + static constexpr auto kMaxAccountsWarn = 3; +#ifdef ARCH_CPU_64_BITS + static constexpr auto kMaxAccounts = 100; +#else + static constexpr auto kMaxAccounts = 10; +#endif explicit Domain(const QString &dataName); ~Domain(); diff --git a/Telegram/SourceFiles/settings/settings_common.cpp b/Telegram/SourceFiles/settings/settings_common.cpp index 1cba2c4dd..f46efb5e2 100644 --- a/Telegram/SourceFiles/settings/settings_common.cpp +++ b/Telegram/SourceFiles/settings/settings_common.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "boxes/abstract_box.h" #include "boxes/sessions_box.h" +#include "ui/boxes/confirm_box.h" #include "window/themes/window_theme_editor_box.h" #include "window/window_session_controller.h" #include "window/window_controller.h" @@ -222,11 +223,24 @@ void FillMenu( [=] { window->show(Box(Window::Theme::CreateBox, window)); }, &st::menuIconChangeColors); } else { - const auto &list = Core::App().domain().accounts(); - if (list.size() < ::Main::Domain::kMaxAccounts) { - addAction(tr::lng_menu_add_account(tr::now), [=] { - Core::App().domain().addActivated(MTP::Environment{}); - }, &st::menuIconAddAccount); + if (type != Type::Kotato) { + const auto &list = Core::App().domain().accounts(); + if (list.size() < ::Main::Domain::kMaxAccountsWarn) { + addAction(tr::lng_menu_add_account(tr::now), [=] { + Core::App().domain().addActivated(MTP::Environment{}); + }, &st::menuIconAddAccount); + } else if (list.size() < ::Main::Domain::kMaxAccounts) { + addAction(tr::lng_menu_add_account(tr::now), [=] { + Ui::show( + Box( + ktr("ktg_too_many_accounts_warning"), + ktr("ktg_account_add_anyway"), + [=] { + Core::App().domain().addActivated(MTP::Environment{}); + }), + Ui::LayerOption::KeepOther); + }, &st::menuIconAddAccount); + } } const auto customSettingsFile = cWorkingDir() + "tdata/kotato-settings-custom.json"; if (type != Type::Kotato && !controller->session().supportMode()) { diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index ca0e6ab45..16471cba9 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_main_menu.h" #include "kotato/kotato_settings.h" +#include "kotato/kotato_lang.h" #include "window/themes/window_theme.h" #include "window/window_peer_menu.h" #include "window/window_session_controller.h" @@ -892,6 +893,7 @@ void MainMenu::rebuildAccounts() { (inner->count() < Main::Domain::kMaxAccounts), anim::type::instant); + _accountsCount = inner->count() ; _reorder->start(); } @@ -930,9 +932,21 @@ not_null*> MainMenu::setupAddAccount( }, button->lifetime()); const auto add = [=](MTP::Environment environment) { - Core::App().preventOrInvoke([=] { - Core::App().domain().addActivated(environment); - }); + const auto sure = [=] { + Core::App().preventOrInvoke([=] { + Core::App().domain().addActivated(environment); + }); + }; + if (_accountsCount >= Main::Domain::kMaxAccountsWarn) { + Ui::show( + Box( + ktr("ktg_too_many_accounts_warning"), + ktr("ktg_account_add_anyway"), + sure), + Ui::LayerOption::KeepOther); + } else { + sure(); + } }; button->setAcceptBoth(true); diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index af64cdcd5..a2f274c8c 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -85,6 +85,7 @@ private: not_null, base::unique_qptr> _watched; not_null*> _accounts; + int _accountsCount = 0; Ui::SlideWrap *_addAccount = nullptr; not_null*> _shadow; not_null _menu;