mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-02 15:45:12 +00:00
Moved proxy global variables from facades to core settings.
This commit is contained in:
@@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "base/qthelp_url.h"
|
||||
#include "base/call_delayed.h"
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "main/main_account.h"
|
||||
#include "mtproto/facade.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
@@ -27,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/effects/radial_animation.h"
|
||||
#include "ui/text/text_options.h"
|
||||
#include "ui/basic_click_handlers.h"
|
||||
#include "facades.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_chat_helpers.h"
|
||||
@@ -186,7 +186,10 @@ class ProxiesBox : public Ui::BoxContent {
|
||||
public:
|
||||
using View = ProxiesBoxController::ItemView;
|
||||
|
||||
ProxiesBox(QWidget*, not_null<ProxiesBoxController*> controller);
|
||||
ProxiesBox(
|
||||
QWidget*,
|
||||
not_null<ProxiesBoxController*> controller,
|
||||
Core::SettingsProxy &settings);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
@@ -201,6 +204,7 @@ private:
|
||||
void refreshProxyForCalls();
|
||||
|
||||
not_null<ProxiesBoxController*> _controller;
|
||||
Core::SettingsProxy &_settings;
|
||||
QPointer<Ui::Checkbox> _tryIPv6;
|
||||
std::shared_ptr<Ui::RadioenumGroup<ProxyData::Settings>> _proxySettings;
|
||||
QPointer<Ui::SlideWrap<Ui::Checkbox>> _proxyForCalls;
|
||||
@@ -566,8 +570,10 @@ void ProxyRow::showMenu() {
|
||||
|
||||
ProxiesBox::ProxiesBox(
|
||||
QWidget*,
|
||||
not_null<ProxiesBoxController*> controller)
|
||||
not_null<ProxiesBoxController*> controller,
|
||||
Core::SettingsProxy &settings)
|
||||
: _controller(controller)
|
||||
, _settings(settings)
|
||||
, _initialWrap(this) {
|
||||
_controller->views(
|
||||
) | rpl::start_with_next([=](View &&view) {
|
||||
@@ -591,11 +597,11 @@ void ProxiesBox::setupContent() {
|
||||
object_ptr<Ui::Checkbox>(
|
||||
inner,
|
||||
tr::lng_connection_try_ipv6(tr::now),
|
||||
Global::TryIPv6()),
|
||||
_settings.tryIPv6()),
|
||||
st::proxyTryIPv6Padding);
|
||||
_proxySettings
|
||||
= std::make_shared<Ui::RadioenumGroup<ProxyData::Settings>>(
|
||||
Global::ProxySettings());
|
||||
_settings.settings());
|
||||
inner->add(
|
||||
object_ptr<Ui::Radioenum<ProxyData::Settings>>(
|
||||
inner,
|
||||
@@ -623,7 +629,7 @@ void ProxiesBox::setupContent() {
|
||||
object_ptr<Ui::Checkbox>(
|
||||
inner,
|
||||
tr::lng_proxy_use_for_calls(tr::now),
|
||||
Global::UseProxyForCalls()),
|
||||
_settings.useProxyForCalls()),
|
||||
style::margins(
|
||||
0,
|
||||
st::proxyUsePadding.top(),
|
||||
@@ -652,7 +658,7 @@ void ProxiesBox::setupContent() {
|
||||
|
||||
_proxySettings->setChangedCallback([=](ProxyData::Settings value) {
|
||||
if (!_controller->setProxySettings(value)) {
|
||||
_proxySettings->setValue(Global::ProxySettings());
|
||||
_proxySettings->setValue(_settings.settings());
|
||||
addNewProxy();
|
||||
}
|
||||
refreshProxyForCalls();
|
||||
@@ -1051,20 +1057,22 @@ void ProxyBox::addLabel(
|
||||
|
||||
ProxiesBoxController::ProxiesBoxController(not_null<Main::Account*> account)
|
||||
: _account(account)
|
||||
, _settings(Core::App().settings().proxy())
|
||||
, _saveTimer([] { Local::writeSettings(); }) {
|
||||
_list = ranges::views::all(
|
||||
Global::ProxiesList()
|
||||
_settings.list()
|
||||
) | ranges::views::transform([&](const ProxyData &proxy) {
|
||||
return Item{ ++_idCounter, proxy };
|
||||
}) | ranges::to_vector;
|
||||
|
||||
subscribe(Global::RefConnectionTypeChanged(), [=] {
|
||||
_proxySettingsChanges.fire_copy(Global::ProxySettings());
|
||||
const auto i = findByProxy(Global::SelectedProxy());
|
||||
_settings.connectionTypeChanges(
|
||||
) | rpl::start_with_next([=] {
|
||||
_proxySettingsChanges.fire_copy(_settings.settings());
|
||||
const auto i = findByProxy(_settings.selected());
|
||||
if (i != end(_list)) {
|
||||
updateView(*i);
|
||||
}
|
||||
});
|
||||
}, _lifetime);
|
||||
|
||||
for (auto &item : _list) {
|
||||
refreshChecker(item);
|
||||
@@ -1112,7 +1120,7 @@ void ProxiesBoxController::ShowApplyConfirmation(
|
||||
? "\n\n" + tr::lng_proxy_sponsor_warning(tr::now)
|
||||
: QString());
|
||||
auto callback = [=](Fn<void()> &&close) {
|
||||
auto &proxies = Global::RefProxiesList();
|
||||
auto &proxies = Core::App().settings().proxy().list();
|
||||
if (!ranges::contains(proxies, proxy)) {
|
||||
proxies.push_back(proxy);
|
||||
}
|
||||
@@ -1139,7 +1147,7 @@ void ProxiesBoxController::ShowApplyConfirmation(
|
||||
auto ProxiesBoxController::proxySettingsValue() const
|
||||
-> rpl::producer<ProxyData::Settings> {
|
||||
return _proxySettingsChanges.events_starting_with_copy(
|
||||
Global::ProxySettings()
|
||||
_settings.settings()
|
||||
) | rpl::distinct_until_changed();
|
||||
}
|
||||
|
||||
@@ -1182,7 +1190,8 @@ void ProxiesBoxController::refreshChecker(Item &item) {
|
||||
Variants::Address address) {
|
||||
const auto &list = options.data[address][type];
|
||||
if (list.empty()
|
||||
|| (address == Variants::IPv6 && !Global::TryIPv6())) {
|
||||
|| ((address == Variants::IPv6)
|
||||
&& !Core::App().settings().proxy().tryIPv6())) {
|
||||
checker = nullptr;
|
||||
return;
|
||||
}
|
||||
@@ -1244,7 +1253,7 @@ object_ptr<Ui::BoxContent> ProxiesBoxController::CreateOwningBox(
|
||||
}
|
||||
|
||||
object_ptr<Ui::BoxContent> ProxiesBoxController::create() {
|
||||
auto result = Box<ProxiesBox>(this);
|
||||
auto result = Box<ProxiesBox>(this, _settings);
|
||||
for (const auto &item : _list) {
|
||||
updateView(item);
|
||||
}
|
||||
@@ -1282,14 +1291,13 @@ void ProxiesBoxController::shareItem(int id) {
|
||||
|
||||
void ProxiesBoxController::applyItem(int id) {
|
||||
auto item = findById(id);
|
||||
if ((Global::ProxySettings() == ProxyData::Settings::Enabled)
|
||||
&& Global::SelectedProxy() == item->data) {
|
||||
if (_settings.isEnabled() && (_settings.selected() == item->data)) {
|
||||
return;
|
||||
} else if (item->deleted) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto j = findByProxy(Global::SelectedProxy());
|
||||
auto j = findByProxy(_settings.selected());
|
||||
|
||||
Core::App().setCurrentProxy(
|
||||
item->data,
|
||||
@@ -1307,12 +1315,13 @@ void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
||||
item->deleted = deleted;
|
||||
|
||||
if (deleted) {
|
||||
auto &proxies = Global::RefProxiesList();
|
||||
auto &proxies = _settings.list();
|
||||
proxies.erase(ranges::remove(proxies, item->data), end(proxies));
|
||||
|
||||
if (item->data == Global::SelectedProxy()) {
|
||||
_lastSelectedProxy = base::take(Global::RefSelectedProxy());
|
||||
if (Global::ProxySettings() == ProxyData::Settings::Enabled) {
|
||||
if (item->data == _settings.selected()) {
|
||||
_lastSelectedProxy = _settings.selected();
|
||||
_settings.setSelected(MTP::ProxyData());
|
||||
if (_settings.isEnabled()) {
|
||||
_lastSelectedProxyUsed = true;
|
||||
Core::App().setCurrentProxy(
|
||||
ProxyData(),
|
||||
@@ -1323,7 +1332,7 @@ void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto &proxies = Global::RefProxiesList();
|
||||
auto &proxies = _settings.list();
|
||||
if (ranges::find(proxies, item->data) == end(proxies)) {
|
||||
auto insertBefore = item + 1;
|
||||
while (insertBefore != end(_list) && insertBefore->deleted) {
|
||||
@@ -1335,15 +1344,15 @@ void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
||||
proxies.insert(insertBeforeIt, item->data);
|
||||
}
|
||||
|
||||
if (!Global::SelectedProxy() && _lastSelectedProxy == item->data) {
|
||||
Assert(Global::ProxySettings() != ProxyData::Settings::Enabled);
|
||||
if (!_settings.selected() && _lastSelectedProxy == item->data) {
|
||||
Assert(!_settings.isEnabled());
|
||||
|
||||
if (base::take(_lastSelectedProxyUsed)) {
|
||||
Core::App().setCurrentProxy(
|
||||
base::take(_lastSelectedProxy),
|
||||
ProxyData::Settings::Enabled);
|
||||
} else {
|
||||
Global::SetSelectedProxy(base::take(_lastSelectedProxy));
|
||||
_settings.setSelected(base::take(_lastSelectedProxy));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1371,7 +1380,7 @@ object_ptr<Ui::BoxContent> ProxiesBoxController::editItemBox(int id) {
|
||||
void ProxiesBoxController::replaceItemWith(
|
||||
std::vector<Item>::iterator which,
|
||||
std::vector<Item>::iterator with) {
|
||||
auto &proxies = Global::RefProxiesList();
|
||||
auto &proxies = _settings.list();
|
||||
proxies.erase(ranges::remove(proxies, which->data), end(proxies));
|
||||
|
||||
_views.fire({ which->id });
|
||||
@@ -1391,7 +1400,7 @@ void ProxiesBoxController::replaceItemValue(
|
||||
restoreItem(which->id);
|
||||
}
|
||||
|
||||
auto &proxies = Global::RefProxiesList();
|
||||
auto &proxies = _settings.list();
|
||||
const auto i = ranges::find(proxies, which->data);
|
||||
Assert(i != end(proxies));
|
||||
*i = proxy;
|
||||
@@ -1422,7 +1431,7 @@ object_ptr<Ui::BoxContent> ProxiesBoxController::addNewItemBox() {
|
||||
}
|
||||
|
||||
void ProxiesBoxController::addNewItem(const ProxyData &proxy) {
|
||||
auto &proxies = Global::RefProxiesList();
|
||||
auto &proxies = _settings.list();
|
||||
proxies.push_back(proxy);
|
||||
|
||||
_list.push_back({ ++_idCounter, proxy });
|
||||
@@ -1431,43 +1440,42 @@ void ProxiesBoxController::addNewItem(const ProxyData &proxy) {
|
||||
}
|
||||
|
||||
bool ProxiesBoxController::setProxySettings(ProxyData::Settings value) {
|
||||
if (Global::ProxySettings() == value) {
|
||||
if (_settings.settings() == value) {
|
||||
return true;
|
||||
} else if (value == ProxyData::Settings::Enabled) {
|
||||
if (Global::ProxiesList().empty()) {
|
||||
if (_settings.list().empty()) {
|
||||
return false;
|
||||
} else if (!Global::SelectedProxy()) {
|
||||
Global::SetSelectedProxy(Global::ProxiesList().back());
|
||||
auto j = findByProxy(Global::SelectedProxy());
|
||||
} else if (!_settings.selected()) {
|
||||
_settings.setSelected(_settings.list().back());
|
||||
auto j = findByProxy(_settings.selected());
|
||||
if (j != end(_list)) {
|
||||
updateView(*j);
|
||||
}
|
||||
}
|
||||
}
|
||||
Core::App().setCurrentProxy(Global::SelectedProxy(), value);
|
||||
Core::App().setCurrentProxy(_settings.selected(), value);
|
||||
saveDelayed();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProxiesBoxController::setProxyForCalls(bool enabled) {
|
||||
if (Global::UseProxyForCalls() == enabled) {
|
||||
if (_settings.useProxyForCalls() == enabled) {
|
||||
return;
|
||||
}
|
||||
Global::SetUseProxyForCalls(enabled);
|
||||
if ((Global::ProxySettings() == ProxyData::Settings::Enabled)
|
||||
&& Global::SelectedProxy().supportsCalls()) {
|
||||
Global::RefConnectionTypeChanged().notify();
|
||||
_settings.setUseProxyForCalls(enabled);
|
||||
if (_settings.isEnabled() && _settings.selected().supportsCalls()) {
|
||||
_settings.connectionTypeChangesNotify();
|
||||
}
|
||||
saveDelayed();
|
||||
}
|
||||
|
||||
void ProxiesBoxController::setTryIPv6(bool enabled) {
|
||||
if (Global::TryIPv6() == enabled) {
|
||||
if (Core::App().settings().proxy().tryIPv6() == enabled) {
|
||||
return;
|
||||
}
|
||||
Global::SetTryIPv6(enabled);
|
||||
Core::App().settings().proxy().setTryIPv6(enabled);
|
||||
_account->mtp().restart();
|
||||
Global::RefConnectionTypeChanged().notify();
|
||||
_settings.connectionTypeChangesNotify();
|
||||
saveDelayed();
|
||||
}
|
||||
|
||||
@@ -1480,7 +1488,7 @@ auto ProxiesBoxController::views() const -> rpl::producer<ItemView> {
|
||||
}
|
||||
|
||||
void ProxiesBoxController::updateView(const Item &item) {
|
||||
const auto selected = (Global::SelectedProxy() == item.data);
|
||||
const auto selected = (_settings.selected() == item.data);
|
||||
const auto deleted = item.deleted;
|
||||
const auto type = [&] {
|
||||
switch (item.data.type) {
|
||||
@@ -1494,8 +1502,7 @@ void ProxiesBoxController::updateView(const Item &item) {
|
||||
Unexpected("Proxy type in ProxiesBoxController::updateView.");
|
||||
}();
|
||||
const auto state = [&] {
|
||||
if (!selected
|
||||
|| (Global::ProxySettings() != ProxyData::Settings::Enabled)) {
|
||||
if (!selected || !_settings.isEnabled()) {
|
||||
return item.state;
|
||||
} else if (_account->mtp().dcstate() == MTP::ConnectedState) {
|
||||
return ItemState::Online;
|
||||
|
Reference in New Issue
Block a user