[Improvement] Increase account limit

This commit is contained in:
Eric Kotato 2022-09-11 02:22:41 +03:00
parent a254d406e7
commit fb7d376fe8
5 changed files with 46 additions and 9 deletions

View file

@ -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",

View file

@ -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> 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();

View file

@ -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<Ui::ConfirmBox>(
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()) {

View file

@ -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<Ui::SlideWrap<Ui::RippleButton>*> 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<Ui::ConfirmBox>(
ktr("ktg_too_many_accounts_warning"),
ktr("ktg_account_add_anyway"),
sure),
Ui::LayerOption::KeepOther);
} else {
sure();
}
};
button->setAcceptBoth(true);

View file

@ -85,6 +85,7 @@ private:
not_null<Main::Account*>,
base::unique_qptr<AccountButton>> _watched;
not_null<Ui::SlideWrap<Ui::VerticalLayout>*> _accounts;
int _accountsCount = 0;
Ui::SlideWrap<Ui::RippleButton> *_addAccount = nullptr;
not_null<Ui::SlideWrap<Ui::PlainShadow>*> _shadow;
not_null<Ui::Menu::Menu*> _menu;