From 6d08542afa42c62034f5c4aac6c1b458234a63c8 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 11 Jun 2021 01:49:08 +0300 Subject: [PATCH] Moved proxy global variables from facades to core settings. --- Telegram/CMakeLists.txt | 2 + Telegram/SourceFiles/apiwrap.cpp | 9 +- Telegram/SourceFiles/boxes/connection_box.cpp | 101 ++++---- Telegram/SourceFiles/boxes/connection_box.h | 6 +- Telegram/SourceFiles/calls/calls_call.cpp | 24 +- Telegram/SourceFiles/core/application.cpp | 15 +- Telegram/SourceFiles/core/core_settings.cpp | 13 +- Telegram/SourceFiles/core/core_settings.h | 7 + .../SourceFiles/core/core_settings_proxy.cpp | 238 ++++++++++++++++++ .../SourceFiles/core/core_settings_proxy.h | 56 +++++ Telegram/SourceFiles/core/sandbox.cpp | 11 +- .../view/history_view_top_bar_widget.cpp | 4 +- Telegram/SourceFiles/main/main_account.cpp | 3 +- Telegram/SourceFiles/main/main_session.cpp | 6 - .../SourceFiles/mtproto/config_loader.cpp | 13 +- Telegram/SourceFiles/mtproto/config_loader.h | 5 +- Telegram/SourceFiles/mtproto/mtp_instance.cpp | 32 ++- Telegram/SourceFiles/mtproto/session.cpp | 18 +- .../settings/settings_advanced.cpp | 5 +- .../details/storage_settings_scheme.cpp | 65 +++-- .../storage/details/storage_settings_scheme.h | 6 +- Telegram/SourceFiles/storage/localstorage.cpp | 25 -- .../window/window_connecting_widget.cpp | 15 +- .../window/window_connecting_widget.h | 2 +- 24 files changed, 497 insertions(+), 184 deletions(-) create mode 100644 Telegram/SourceFiles/core/core_settings_proxy.cpp create mode 100644 Telegram/SourceFiles/core/core_settings_proxy.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index bd081899d..3c2ea6a73 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -373,6 +373,8 @@ PRIVATE core/core_cloud_password.h core/core_settings.cpp core/core_settings.h + core/core_settings_proxy.cpp + core/core_settings_proxy.h core/crash_report_window.cpp core/crash_report_window.h core/crash_reports.cpp diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 82c294338..e8d13c14e 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -212,6 +212,11 @@ ApiWrap::ApiWrap(not_null session) }, _session->lifetime()); setupSupportMode(); + + Core::App().settings().proxy().connectionTypeValue( + ) | rpl::start_with_next([=] { + refreshTopPromotion(); + }, _session->lifetime()); }); } @@ -261,10 +266,10 @@ void ApiWrap::refreshTopPromotion() { return; } const auto key = [&]() -> std::pair { - if (Global::ProxySettings() != MTP::ProxyData::Settings::Enabled) { + if (!Core::App().settings().proxy().isEnabled()) { return {}; } - const auto &proxy = Global::SelectedProxy(); + const auto &proxy = Core::App().settings().proxy().selected(); if (proxy.type != MTP::ProxyData::Type::Mtproto) { return {}; } diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 3818775b6..bba252e61 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -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 controller); + ProxiesBox( + QWidget*, + not_null controller, + Core::SettingsProxy &settings); protected: void prepare() override; @@ -201,6 +204,7 @@ private: void refreshProxyForCalls(); not_null _controller; + Core::SettingsProxy &_settings; QPointer _tryIPv6; std::shared_ptr> _proxySettings; QPointer> _proxyForCalls; @@ -566,8 +570,10 @@ void ProxyRow::showMenu() { ProxiesBox::ProxiesBox( QWidget*, - not_null controller) + not_null 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( inner, tr::lng_connection_try_ipv6(tr::now), - Global::TryIPv6()), + _settings.tryIPv6()), st::proxyTryIPv6Padding); _proxySettings = std::make_shared>( - Global::ProxySettings()); + _settings.settings()); inner->add( object_ptr>( inner, @@ -623,7 +629,7 @@ void ProxiesBox::setupContent() { object_ptr( 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 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 &&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 { 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 ProxiesBoxController::CreateOwningBox( } object_ptr ProxiesBoxController::create() { - auto result = Box(this); + auto result = Box(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 ProxiesBoxController::editItemBox(int id) { void ProxiesBoxController::replaceItemWith( std::vector::iterator which, std::vector::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 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 { } 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; diff --git a/Telegram/SourceFiles/boxes/connection_box.h b/Telegram/SourceFiles/boxes/connection_box.h index 8a7709f9c..26244fe50 100644 --- a/Telegram/SourceFiles/boxes/connection_box.h +++ b/Telegram/SourceFiles/boxes/connection_box.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "base/object_ptr.h" +#include "core/core_settings.h" #include "mtproto/connection_abstract.h" #include "mtproto/mtproto_proxy_data.h" @@ -28,7 +29,7 @@ namespace Main { class Account; } // namespace Main -class ProxiesBoxController : public base::Subscriber { +class ProxiesBoxController { public: using ProxyData = MTP::ProxyData; using Type = ProxyData::Type; @@ -110,6 +111,7 @@ private: void addNewItem(const ProxyData &proxy); const not_null _account; + Core::SettingsProxy &_settings; int _idCounter = 0; std::vector _list; rpl::event_stream _views; @@ -119,4 +121,6 @@ private: ProxyData _lastSelectedProxy; bool _lastSelectedProxyUsed = false; + rpl::lifetime _lifetime; + }; diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 9a304d236..41b5beb92 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -28,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "webrtc/webrtc_create_adm.h" #include "data/data_user.h" #include "data/data_session.h" -#include "facades.h" #include #include @@ -805,16 +804,19 @@ void Call::createAndStartController(const MTPDphoneCall &call) { AppendServer(descriptor.rtcServers, connection); } - if (Global::UseProxyForCalls() - && (Global::ProxySettings() == MTP::ProxyData::Settings::Enabled)) { - const auto &selected = Global::SelectedProxy(); - if (selected.supportsCalls() && !selected.host.isEmpty()) { - Assert(selected.type == MTP::ProxyData::Type::Socks5); - descriptor.proxy = std::make_unique(); - descriptor.proxy->host = selected.host.toStdString(); - descriptor.proxy->port = selected.port; - descriptor.proxy->login = selected.user.toStdString(); - descriptor.proxy->password = selected.password.toStdString(); + { + auto &settingsProxy = Core::App().settings().proxy(); + using ProxyData = MTP::ProxyData; + if (settingsProxy.useProxyForCalls() && settingsProxy.isEnabled()) { + const auto &selected = settingsProxy.selected(); + if (selected.supportsCalls() && !selected.host.isEmpty()) { + Assert(selected.type == ProxyData::Type::Socks5); + descriptor.proxy = std::make_unique(); + descriptor.proxy->host = selected.host.toStdString(); + descriptor.proxy->port = selected.port; + descriptor.proxy->login = selected.user.toStdString(); + descriptor.proxy->password = selected.password.toStdString(); + } } } diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index d9c5338f7..62eaa2ac8 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -523,17 +523,17 @@ void Application::setCurrentProxy( const MTP::ProxyData &proxy, MTP::ProxyData::Settings settings) { const auto current = [&] { - return (Global::ProxySettings() == MTP::ProxyData::Settings::Enabled) - ? Global::SelectedProxy() + return _settings.proxy().isEnabled() + ? _settings.proxy().selected() : MTP::ProxyData(); }; const auto was = current(); - Global::SetSelectedProxy(proxy); - Global::SetProxySettings(settings); + _settings.proxy().setSelected(proxy); + _settings.proxy().setSettings(settings); const auto now = current(); refreshGlobalProxy(); _proxyChanges.fire({ was, now }); - Global::RefConnectionTypeChanged().notify(); + _settings.proxy().connectionTypeChangesNotify(); } auto Application::proxyChanges() const -> rpl::producer { @@ -541,11 +541,10 @@ auto Application::proxyChanges() const -> rpl::producer { } void Application::badMtprotoConfigurationError() { - if (Global::ProxySettings() == MTP::ProxyData::Settings::Enabled - && !_badProxyDisableBox) { + if (_settings.proxy().isEnabled() && !_badProxyDisableBox) { const auto disableCallback = [=] { setCurrentProxy( - Global::SelectedProxy(), + _settings.proxy().selected(), MTP::ProxyData::Settings::System); }; _badProxyDisableBox = Ui::show(Box( diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index 546775dae..e5a1d2ef7 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -77,6 +77,7 @@ Settings::Settings() QByteArray Settings::serialize() const { const auto themesAccentColors = _themesAccentColors.serialize(); const auto windowPosition = Serialize(_windowPosition); + const auto proxy = _proxy.serialize(); auto recentEmojiPreloadGenerated = std::vector(); if (_recentEmojiPreload.empty()) { @@ -97,7 +98,8 @@ QByteArray Settings::serialize() const { + Serialize::stringSize(_callOutputDeviceId) + Serialize::stringSize(_callInputDeviceId) + Serialize::stringSize(_callVideoInputDeviceId) - + sizeof(qint32) * 5; + + sizeof(qint32) * 5 + + Serialize::bytearraySize(proxy); for (const auto &[key, value] : _soundOverrides) { size += Serialize::stringSize(key) + Serialize::stringSize(value); } @@ -198,7 +200,8 @@ QByteArray Settings::serialize() const { stream << qint32(_disableOpenGL ? 1 : 0) << qint32(_groupCallNoiseSuppression ? 1 : 0) - << _workMode.current(); + << _workMode.current() + << proxy; } return result; } @@ -277,6 +280,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 disableOpenGL = _disableOpenGL ? 1 : 0; qint32 groupCallNoiseSuppression = _groupCallNoiseSuppression ? 1 : 0; qint32 workMode = static_cast(_workMode.current()); + QByteArray proxy; stream >> themesAccentColors; if (!stream.atEnd()) { @@ -414,12 +418,17 @@ void Settings::addFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { stream >> workMode; } + if (!stream.atEnd()) { + stream >> proxy; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); return; } else if (!_themesAccentColors.setFromSerialized(themesAccentColors)) { return; + } else if (!_proxy.setFromSerialized(proxy)) { + return; } _adaptiveForWide = (adaptiveForWide == 1); _moderateModeEnabled = (moderateModeEnabled == 1); diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 544754500..de6707e23 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "core/core_settings_proxy.h" #include "window/themes/window_themes_embedded.h" #include "ui/chat/attach/attach_send_files_way.h" #include "platform/platform_notifications_manager.h" @@ -67,6 +68,10 @@ public: return _saveDelayed.events(); } + [[nodiscard]] SettingsProxy &proxy() { + return _proxy; + } + [[nodiscard]] static bool IsLeftCorner(ScreenCorner corner) { return (corner == ScreenCorner::TopLeft) || (corner == ScreenCorner::BottomLeft); @@ -597,6 +602,8 @@ private: ushort rating = 0; }; + SettingsProxy _proxy; + rpl::variable _adaptiveForWide = true; bool _moderateModeEnabled = false; rpl::variable _songVolume = kDefaultVolume; diff --git a/Telegram/SourceFiles/core/core_settings_proxy.cpp b/Telegram/SourceFiles/core/core_settings_proxy.cpp new file mode 100644 index 000000000..b219f4fca --- /dev/null +++ b/Telegram/SourceFiles/core/core_settings_proxy.cpp @@ -0,0 +1,238 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "core/core_settings_proxy.h" + +#include "base/platform/base_platform_info.h" +#include "storage/serialize_common.h" + +namespace Core { +namespace { + +[[nodiscard]] qint32 ProxySettingsToInt(MTP::ProxyData::Settings settings) { + switch(settings) { + case MTP::ProxyData::Settings::System: return 0; + case MTP::ProxyData::Settings::Enabled: return 1; + case MTP::ProxyData::Settings::Disabled: return 2; + } + Unexpected("Bad type in ProxySettingsToInt"); +} + +[[nodiscard]] MTP::ProxyData::Settings IntToProxySettings(qint32 value) { + switch(value) { + case 0: return MTP::ProxyData::Settings::System; + case 1: return MTP::ProxyData::Settings::Enabled; + case 2: return MTP::ProxyData::Settings::Disabled; + } + Unexpected("Bad type in IntToProxySettings"); +} + +[[nodiscard]] MTP::ProxyData DeserializeProxyData(const QByteArray &data) { + QDataStream stream(data); + stream.setVersion(QDataStream::Qt_5_1); + + qint32 proxyType, port; + MTP::ProxyData proxy; + stream + >> proxyType + >> proxy.host + >> port + >> proxy.user + >> proxy.password; + proxy.port = port; + proxy.type = [&] { + switch(proxyType) { + case 0: return MTP::ProxyData::Type::None; + case 1: return MTP::ProxyData::Type::Socks5; + case 2: return MTP::ProxyData::Type::Http; + case 3: return MTP::ProxyData::Type::Mtproto; + } + Unexpected("Bad type in DeserializeProxyData"); + }(); + return proxy; +} + +[[nodiscard]] QByteArray SerializeProxyData(const MTP::ProxyData &proxy) { + auto result = QByteArray(); + const auto size = 1 * sizeof(qint32) + + Serialize::stringSize(proxy.host) + + 1 * sizeof(qint32) + + Serialize::stringSize(proxy.user) + + Serialize::stringSize(proxy.password); + + result.reserve(size); + { + const auto proxyType = [&] { + switch(proxy.type) { + case MTP::ProxyData::Type::None: return 0; + case MTP::ProxyData::Type::Socks5: return 1; + case MTP::ProxyData::Type::Http: return 2; + case MTP::ProxyData::Type::Mtproto: return 3; + } + Unexpected("Bad type in SerializeProxyData"); + }(); + + QDataStream stream(&result, QIODevice::WriteOnly); + stream.setVersion(QDataStream::Qt_5_1); + stream + << qint32(proxyType) + << proxy.host + << qint32(proxy.port) + << proxy.user + << proxy.password; + } + return result; +} + +} // namespace + +SettingsProxy::SettingsProxy() +: _tryIPv6(!Platform::IsWindows()) { +} + +QByteArray SettingsProxy::serialize() const { + auto result = QByteArray(); + auto stream = QDataStream(&result, QIODevice::WriteOnly); + + const auto serializedSelected = SerializeProxyData(_selected); + const auto serializedList = ranges::views::all( + _list + ) | ranges::views::transform(SerializeProxyData) | ranges::to_vector; + + const auto size = 3 * sizeof(qint32) + + Serialize::bytearraySize(serializedSelected) + + 1 * sizeof(qint32) + + ranges::accumulate( + serializedList, + 0, + ranges::plus(), + &Serialize::bytearraySize); + result.reserve(size); + + stream.setVersion(QDataStream::Qt_5_1); + stream + << qint32(_tryIPv6 ? 1 : 0) + << qint32(_useProxyForCalls ? 1 : 0) + << ProxySettingsToInt(_settings) + << serializedSelected + << qint32(_list.size()); + for (const auto &i : serializedList) { + stream << i; + } + + stream.device()->close(); + return result; +} + +bool SettingsProxy::setFromSerialized(const QByteArray &serialized) { + if (serialized.isEmpty()) { + return true; + } + + auto stream = QDataStream(serialized); + + auto tryIPv6 = qint32(_tryIPv6 ? 1 : 0); + auto useProxyForCalls = qint32(_useProxyForCalls ? 1 : 0); + auto settings = ProxySettingsToInt(_settings); + auto listCount = qint32(_list.size()); + auto selectedProxy = QByteArray(); + + if (!stream.atEnd()) { + stream + >> tryIPv6 + >> useProxyForCalls + >> settings + >> selectedProxy + >> listCount; + if (stream.status() == QDataStream::Ok) { + for (auto i = 0; i != listCount; ++i) { + QByteArray data; + stream >> data; + _list.push_back(DeserializeProxyData(data)); + } + } + } + + if (stream.status() != QDataStream::Ok) { + LOG(("App Error: " + "Bad data for Core::SettingsProxy::setFromSerialized()")); + return false; + } + + _tryIPv6 = (tryIPv6 == 1); + _useProxyForCalls = (useProxyForCalls == 1); + _settings = IntToProxySettings(settings); + _selected = DeserializeProxyData(selectedProxy); + + return true; +} + +bool SettingsProxy::isEnabled() const { + return _settings == MTP::ProxyData::Settings::Enabled; +} + +bool SettingsProxy::isSystem() const { + return _settings == MTP::ProxyData::Settings::System; +} + +bool SettingsProxy::isDisabled() const { + return _settings == MTP::ProxyData::Settings::Disabled; +} + +bool SettingsProxy::tryIPv6() const { + return _tryIPv6; +} + +void SettingsProxy::setTryIPv6(bool value) { + _tryIPv6 = value; +} + +bool SettingsProxy::useProxyForCalls() const { + return _useProxyForCalls; +} + +void SettingsProxy::setUseProxyForCalls(bool value) { + _useProxyForCalls = value; +} + +MTP::ProxyData::Settings SettingsProxy::settings() const { + return _settings; +} + +void SettingsProxy::setSettings(MTP::ProxyData::Settings value) { + _settings = value; +} + +MTP::ProxyData SettingsProxy::selected() const { + return _selected; +} + +void SettingsProxy::setSelected(MTP::ProxyData value) { + _selected = value; +} + +const std::vector &SettingsProxy::list() const { + return _list; +} + +std::vector &SettingsProxy::list() { + return _list; +} + +rpl::producer<> SettingsProxy::connectionTypeValue() const { + return _connectionTypeChanges.events_starting_with({}); +} + +rpl::producer<> SettingsProxy::connectionTypeChanges() const { + return _connectionTypeChanges.events(); +} + +void SettingsProxy::connectionTypeChangesNotify() { + _connectionTypeChanges.fire({}); +} + +} // namespace Core diff --git a/Telegram/SourceFiles/core/core_settings_proxy.h b/Telegram/SourceFiles/core/core_settings_proxy.h new file mode 100644 index 000000000..bd709c230 --- /dev/null +++ b/Telegram/SourceFiles/core/core_settings_proxy.h @@ -0,0 +1,56 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "mtproto/mtproto_proxy_data.h" + +namespace Core { + +class SettingsProxy final { +public: + SettingsProxy(); + + [[nodiscard]] bool isEnabled() const; + [[nodiscard]] bool isSystem() const; + [[nodiscard]] bool isDisabled() const; + + [[nodiscard]] rpl::producer<> connectionTypeChanges() const; + [[nodiscard]] rpl::producer<> connectionTypeValue() const; + void connectionTypeChangesNotify(); + + [[nodiscard]] bool tryIPv6() const; + void setTryIPv6(bool value); + + [[nodiscard]] bool useProxyForCalls() const; + void setUseProxyForCalls(bool value); + + [[nodiscard]] MTP::ProxyData::Settings settings() const; + void setSettings(MTP::ProxyData::Settings value); + + [[nodiscard]] MTP::ProxyData selected() const; + void setSelected(MTP::ProxyData value); + + [[nodiscard]] const std::vector &list() const; + [[nodiscard]] std::vector &list(); + + [[nodiscard]] QByteArray serialize() const; + bool setFromSerialized(const QByteArray &serialized); + +private: + bool _tryIPv6 = false; + bool _useProxyForCalls = false; + MTP::ProxyData::Settings _settings = MTP::ProxyData::Settings::System; + MTP::ProxyData _selected; + std::vector _list; + + rpl::event_stream<> _connectionTypeChanges; + +}; + +} // namespace Core + diff --git a/Telegram/SourceFiles/core/sandbox.cpp b/Telegram/SourceFiles/core/sandbox.cpp index 299f1084c..8b4c8eb16 100644 --- a/Telegram/SourceFiles/core/sandbox.cpp +++ b/Telegram/SourceFiles/core/sandbox.cpp @@ -26,7 +26,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qthelp_regex.h" #include "base/qt_adapters.h" #include "ui/effects/animations.h" -#include "facades.h" #include "app.h" #include @@ -450,17 +449,17 @@ void Sandbox::checkForQuit() { } void Sandbox::refreshGlobalProxy() { - const auto proxy = !Global::started() + const auto proxy = !Core::IsAppLaunched() ? _sandboxProxy - : (Global::ProxySettings() == MTP::ProxyData::Settings::Enabled) - ? Global::SelectedProxy() + : Core::App().settings().proxy().isEnabled() + ? Core::App().settings().proxy().selected() : MTP::ProxyData(); if (proxy.type == MTP::ProxyData::Type::Socks5 || proxy.type == MTP::ProxyData::Type::Http) { QNetworkProxy::setApplicationProxy( MTP::ToNetworkProxy(MTP::ToDirectIpProxy(proxy))); - } else if (!Global::started() - || Global::ProxySettings() == MTP::ProxyData::Settings::System) { + } else if (!Core::IsAppLaunched() + || Core::App().settings().proxy().isSystem()) { QNetworkProxyFactory::setUseSystemConfiguration(true); } else { QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 48e52129b..b78ec99ca 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -47,7 +47,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "support/support_helper.h" #include "apiwrap.h" -#include "facades.h" #include "styles/style_window.h" #include "styles/style_dialogs.h" #include "styles/style_chat.h" @@ -172,8 +171,7 @@ TopBarWidget::TopBarWidget( updateInfoToggleActive(); }, lifetime()); - rpl::single(rpl::empty_value()) | rpl::then( - base::ObservableViewer(Global::RefConnectionTypeChanged()) + Core::App().settings().proxy().connectionTypeValue( ) | rpl::start_with_next([=] { updateConnectingState(); }, lifetime()); diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp index ccb2a3455..93ab7f99a 100644 --- a/Telegram/SourceFiles/main/main_account.cpp +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -30,7 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "main/main_domain.h" #include "main/main_session_settings.h" -#include "facades.h" namespace Main { namespace { @@ -448,7 +447,7 @@ void Account::startMtp(std::unique_ptr config) { }); _mtp->setStateChangedHandler([=](MTP::ShiftedDcId dc, int32 state) { if (dc == _mtp->mainDcId()) { - Global::RefConnectionTypeChanged().notify(); + Core::App().settings().proxy().connectionTypeChangesNotify(); } }); _mtp->setSessionResetHandler([=](MTP::ShiftedDcId shiftedDcId) { diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index 62e7584dc..ef71eb359 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "api/api_updates.h" #include "api/api_send_progress.h" -#include "core/application.h" #include "main/main_account.h" #include "main/main_domain.h" #include "main/main_session_settings.h" @@ -34,7 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "calls/calls_instance.h" #include "support/support_helper.h" -#include "facades.h" #ifndef TDESKTOP_DISABLE_SPELLCHECK #include "chat_helpers/spellchecker_common.h" @@ -88,10 +86,6 @@ Session::Session( , _saveSettingsTimer([=] { saveSettings(); }) { Expects(_settings != nullptr); - subscribe(Global::RefConnectionTypeChanged(), [=] { - _api->refreshTopPromotion(); - }); - _api->refreshTopPromotion(); _api->requestTermsUpdate(); _api->requestFullPeer(_user); diff --git a/Telegram/SourceFiles/mtproto/config_loader.cpp b/Telegram/SourceFiles/mtproto/config_loader.cpp index 0177a4019..d9f55fac8 100644 --- a/Telegram/SourceFiles/mtproto/config_loader.cpp +++ b/Telegram/SourceFiles/mtproto/config_loader.cpp @@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/mtproto_dc_options.h" #include "mtproto/mtproto_config.h" #include "mtproto/mtp_instance.h" -#include "facades.h" namespace MTP { namespace details { @@ -28,9 +27,11 @@ ConfigLoader::ConfigLoader( not_null instance, const QString &phone, Fn onDone, - FailHandler onFail) + FailHandler onFail, + bool proxyEnabled) : _instance(instance) , _phone(phone) +, _proxyEnabled(proxyEnabled) , _doneHandler(onDone) , _failHandler(onFail) { _enumDCTimer.setCallback([this] { enumerate(); }); @@ -115,7 +116,7 @@ void ConfigLoader::enumerate() { } void ConfigLoader::refreshSpecialLoader() { - if (Global::ProxySettings() == ProxyData::Settings::Enabled) { + if (_proxyEnabled) { _specialLoader.reset(); return; } @@ -174,7 +175,7 @@ void ConfigLoader::addSpecialEndpoint( void ConfigLoader::sendSpecialRequest() { terminateSpecialRequest(); - if (Global::ProxySettings() == ProxyData::Settings::Enabled) { + if (_proxyEnabled) { _specialLoader.reset(); return; } @@ -233,5 +234,9 @@ void ConfigLoader::specialConfigLoaded(const MTPConfig &result) { _instance->dcOptions().setFromList(data.vdc_options()); } +void ConfigLoader::setProxyEnabled(bool value) { + _proxyEnabled = value; +} + } // namespace details } // namespace MTP diff --git a/Telegram/SourceFiles/mtproto/config_loader.h b/Telegram/SourceFiles/mtproto/config_loader.h index 9a0feb915..13a80b1b0 100644 --- a/Telegram/SourceFiles/mtproto/config_loader.h +++ b/Telegram/SourceFiles/mtproto/config_loader.h @@ -26,11 +26,13 @@ public: not_null instance, const QString &phone, Fn onDone, - FailHandler onFail); + FailHandler onFail, + bool proxyEnabled); ~ConfigLoader(); void load(); void setPhone(const QString &phone); + void setProxyEnabled(bool value); private: mtpRequestId sendRequest(ShiftedDcId shiftedDcId); @@ -67,6 +69,7 @@ private: DcId _specialEnumCurrent = 0; mtpRequestId _specialEnumRequest = 0; QString _phone; + bool _proxyEnabled = false; Fn _doneHandler; FailHandler _failHandler; diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index e2cca13f5..795e1c729 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -20,13 +20,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_account.h" // Account::configUpdated. #include "apiwrap.h" #include "core/application.h" +#include "core/core_settings.h" #include "lang/lang_instance.h" #include "lang/lang_cloud_manager.h" #include "base/unixtime.h" #include "base/call_delayed.h" #include "base/timer.h" #include "base/network_reachability.h" -#include "facades.h" // Proxies list. namespace MTP { namespace { @@ -279,6 +279,8 @@ private: base::Timer _checkDelayedTimer; + Core::SettingsProxy &_proxySettings; + rpl::lifetime _lifetime; }; @@ -299,7 +301,8 @@ Instance::Private::Private( , _instance(instance) , _mode(mode) , _config(std::move(fields.config)) -, _networkReachability(base::NetworkReachability::Instance()) { +, _networkReachability(base::NetworkReachability::Instance()) +, _proxySettings(Core::App().settings().proxy()) { Expects(_config != nullptr); const auto idealThreadPoolSize = QThread::idealThreadCount(); @@ -338,6 +341,13 @@ Instance::Private::Private( _mainDcId = fields.mainDcId; _mainDcIdForced = true; } + + _proxySettings.connectionTypeChanges( + ) | rpl::start_with_next([=] { + if (_configLoader) { + _configLoader->setProxyEnabled(_proxySettings.isEnabled()); + } + }, _lifetime); } void Instance::Private::start() { @@ -397,11 +407,12 @@ void Instance::Private::applyDomainIps( } return true; }; - for (auto &proxy : Global::RefProxiesList()) { + for (auto &proxy : _proxySettings.list()) { applyToProxy(proxy); } - if (applyToProxy(Global::RefSelectedProxy()) - && (Global::ProxySettings() == ProxyData::Settings::Enabled)) { + auto selected = _proxySettings.selected(); + if (applyToProxy(selected) && _proxySettings.isEnabled()) { + _proxySettings.setSelected(selected); for (const auto &[shiftedDcId, session] : _sessions) { session->refreshOptions(); } @@ -427,11 +438,13 @@ void Instance::Private::setGoodProxyDomain( } return true; }; - for (auto &proxy : Global::RefProxiesList()) { + for (auto &proxy : _proxySettings.list()) { applyToProxy(proxy); } - if (applyToProxy(Global::RefSelectedProxy()) - && (Global::ProxySettings() == ProxyData::Settings::Enabled)) { + + auto selected = _proxySettings.selected(); + if (applyToProxy(selected) && _proxySettings.isEnabled()) { + _proxySettings.setSelected(selected); Core::App().refreshGlobalProxy(); } } @@ -473,7 +486,8 @@ void Instance::Private::requestConfig() { [=](const MTPConfig &result) { configLoadDone(result); }, [=](const Error &error, const Response &) { return configLoadFail(error); - }); + }, + _proxySettings.isEnabled()); _configLoader->load(); } diff --git a/Telegram/SourceFiles/mtproto/session.cpp b/Telegram/SourceFiles/mtproto/session.cpp index a52efb0ae..0148ff112 100644 --- a/Telegram/SourceFiles/mtproto/session.cpp +++ b/Telegram/SourceFiles/mtproto/session.cpp @@ -10,9 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/details/mtproto_dcenter.h" #include "mtproto/session_private.h" #include "mtproto/mtproto_auth_key.h" +#include "core/application.h" +#include "core/core_settings.h" #include "base/unixtime.h" #include "base/openssl_help.h" -#include "facades.h" namespace MTP { namespace details { @@ -238,22 +239,19 @@ void Session::restart() { } void Session::refreshOptions() { - const auto &proxy = Global::SelectedProxy(); - const auto proxyType = - (Global::ProxySettings() == ProxyData::Settings::Enabled - ? proxy.type - : ProxyData::Type::None); + auto &settings = Core::App().settings().proxy(); + const auto &proxy = settings.selected(); + const auto isEnabled = settings.isEnabled(); + const auto proxyType = (isEnabled ? proxy.type : ProxyData::Type::None); const auto useTcp = (proxyType != ProxyData::Type::Http); const auto useHttp = (proxyType != ProxyData::Type::Mtproto); const auto useIPv4 = true; - const auto useIPv6 = Global::TryIPv6(); + const auto useIPv6 = settings.tryIPv6(); _data->setOptions(SessionOptions( _instance->systemLangCode(), _instance->cloudLangCode(), _instance->langPackName(), - (Global::ProxySettings() == ProxyData::Settings::Enabled - ? proxy - : ProxyData()), + (isEnabled ? proxy : ProxyData()), useIPv4, useIPv6, useHttp, diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index cc06f1725..3bf3d6363 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -33,7 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_domain.h" #include "main/main_session.h" #include "mtproto/facade.h" -#include "facades.h" #include "app.h" #include "styles/style_settings.h" @@ -50,7 +49,7 @@ void SetupConnectionType( not_null container) { const auto connectionType = [=] { const auto transport = account->mtp().dctransport(); - if (Global::ProxySettings() != MTP::ProxyData::Settings::Enabled) { + if (!Core::App().settings().proxy().isEnabled()) { return transport.isEmpty() ? tr::lng_connection_auto_connecting(tr::now) : tr::lng_connection_auto(tr::now, lt_transport, transport); @@ -64,7 +63,7 @@ void SetupConnectionType( container, tr::lng_settings_connection_type(), rpl::merge( - base::ObservableViewer(Global::RefConnectionTypeChanged()), + Core::App().settings().proxy().connectionTypeChanges(), // Handle language switch. tr::lng_connection_auto_connecting() | rpl::to_empty ) | rpl::map(connectionType), diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index 44cc82694..3b9c63603 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/update_checker.h" #include "platform/platform_specific.h" #include "boxes/send_files_box.h" -#include "facades.h" namespace Storage { namespace details { @@ -457,7 +456,7 @@ bool ReadSetting( context.legacyRead = true; } break; - case dbiConnectionTypeOld: { + case dbiConnectionTypeOldOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; @@ -476,26 +475,27 @@ bool ReadSetting( : MTP::ProxyData::Type::Http; } break; }; - Global::SetSelectedProxy(proxy ? proxy : MTP::ProxyData()); - Global::SetProxySettings(proxy + auto &proxySettings = Core::App().settings().proxy(); + proxySettings.setSelected(proxy ? proxy : MTP::ProxyData()); + proxySettings.setSettings(proxy ? MTP::ProxyData::Settings::Enabled : MTP::ProxyData::Settings::System); - if (proxy) { - Global::SetProxiesList({ 1, proxy }); - } else { - Global::SetProxiesList({}); - } + proxySettings.list() = proxy + ? std::vector{ 1, proxy } + : std::vector{}; Core::App().refreshGlobalProxy(); context.legacyRead = true; } break; - case dbiConnectionType: { + case dbiConnectionTypeOld: { qint32 connectionType; stream >> connectionType; if (!CheckStreamStatus(stream)) { return false; } + auto &proxySettings = Core::App().settings().proxy(); + const auto readProxy = [&] { qint32 proxyType, port; MTP::ProxyData proxy; @@ -540,7 +540,7 @@ bool ReadSetting( if (!CheckStreamStatus(stream)) { return false; } - Global::SetProxiesList(list); + proxySettings.list() = list; if (connectionType == dbictProxiesListOld) { settings = static_cast( (index > 0 && index <= list.size() @@ -548,49 +548,47 @@ bool ReadSetting( : MTP::ProxyData::Settings::System)); index = std::abs(index); } - if (index > 0 && index <= list.size()) { - Global::SetSelectedProxy(list[index - 1]); - } else { - Global::SetSelectedProxy(MTP::ProxyData()); - } + proxySettings.setSelected((index > 0 && index <= list.size()) + ? list[index - 1] + : MTP::ProxyData()); const auto unchecked = static_cast(settings); switch (unchecked) { case MTP::ProxyData::Settings::Enabled: - Global::SetProxySettings(Global::SelectedProxy() + proxySettings.setSettings(proxySettings.selected() ? MTP::ProxyData::Settings::Enabled : MTP::ProxyData::Settings::System); break; case MTP::ProxyData::Settings::Disabled: case MTP::ProxyData::Settings::System: - Global::SetProxySettings(unchecked); + proxySettings.setSettings(unchecked); break; default: - Global::SetProxySettings(MTP::ProxyData::Settings::System); + proxySettings.setSettings(MTP::ProxyData::Settings::System); break; } - Global::SetUseProxyForCalls(calls == 1); + proxySettings.setUseProxyForCalls(calls == 1); } else { const auto proxy = readProxy(); if (!CheckStreamStatus(stream)) { return false; } if (proxy) { - Global::SetProxiesList({ 1, proxy }); - Global::SetSelectedProxy(proxy); - if (connectionType == dbictTcpProxy - || connectionType == dbictHttpProxy) { - Global::SetProxySettings(MTP::ProxyData::Settings::Enabled); - } else { - Global::SetProxySettings(MTP::ProxyData::Settings::System); - } + proxySettings.list() = { 1, proxy }; + proxySettings.setSelected(proxy); + proxySettings.setSettings((connectionType == dbictTcpProxy + || connectionType == dbictHttpProxy) + ? MTP::ProxyData::Settings::Enabled + : MTP::ProxyData::Settings::System); } else { - Global::SetProxiesList({}); - Global::SetSelectedProxy(MTP::ProxyData()); - Global::SetProxySettings(MTP::ProxyData::Settings::System); + proxySettings.list() = {}; + proxySettings.setSelected(MTP::ProxyData()); + proxySettings.setSettings(MTP::ProxyData::Settings::System); } } Core::App().refreshGlobalProxy(); + + context.legacyRead = true; } break; case dbiThemeKeyOld: { @@ -639,12 +637,13 @@ bool ReadSetting( context.languagesKey = languagesKey; } break; - case dbiTryIPv6: { + case dbiTryIPv6Old: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; + Core::App().settings().proxy().setTryIPv6(v == 1); - Global::SetTryIPv6(v == 1); + context.legacyRead = true; } break; case dbiSeenTrayTooltip: { diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h index 2462cd09c..cbe96a975 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h @@ -92,7 +92,7 @@ enum { dbiAutoUpdate = 0x0c, dbiLastUpdateCheck = 0x0d, dbiWindowPositionOld = 0x0e, - dbiConnectionTypeOld = 0x0f, + dbiConnectionTypeOldOld = 0x0f, // 0x10 reserved dbiDefaultAttach = 0x11, dbiCatsAndDogsOld = 0x12, @@ -117,7 +117,7 @@ enum { dbiEmojiVariantsOldOld = 0x25, dbiRecentStickers = 0x26, dbiDcOptionOld = 0x27, - dbiTryIPv6 = 0x28, + dbiTryIPv6Old = 0x28, dbiSongVolumeOld = 0x29, dbiWindowsNotificationsOld = 0x30, dbiIncludeMutedOld = 0x31, @@ -146,7 +146,7 @@ enum { dbiLastSeenWarningSeenOld = 0x4c, dbiSessionSettings = 0x4d, dbiLangPackKey = 0x4e, - dbiConnectionType = 0x4f, + dbiConnectionTypeOld = 0x4f, dbiStickersFavedLimitOld = 0x50, dbiSuggestStickersByEmojiOld = 0x51, dbiSuggestEmojiOld = 0x52, diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 1558b546e..41610ed84 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "window/themes/window_theme.h" #include "lang/lang_instance.h" -#include "facades.h" #include @@ -466,19 +465,6 @@ void writeSettings() { size += sizeof(quint32) + Serialize::bytearraySize(applicationSettings); size += sizeof(quint32) + Serialize::stringSize(cDialogLastPath()); - auto &proxies = Global::RefProxiesList(); - const auto &proxy = Global::SelectedProxy(); - auto proxyIt = ranges::find(proxies, proxy); - if (proxy.type != MTP::ProxyData::Type::None - && proxyIt == end(proxies)) { - proxies.push_back(proxy); - proxyIt = end(proxies) - 1; - } - size += sizeof(quint32) + sizeof(qint32) + sizeof(qint32) + sizeof(qint32); - for (const auto &proxy : proxies) { - size += sizeof(qint32) + Serialize::stringSize(proxy.host) + sizeof(qint32) + Serialize::stringSize(proxy.user) + Serialize::stringSize(proxy.password); - } - // Theme keys and night mode. size += sizeof(quint32) + sizeof(quint64) * 2 + sizeof(quint32); size += sizeof(quint32) + sizeof(quint64) * 2; @@ -500,17 +486,6 @@ void writeSettings() { data.stream << quint32(dbiDialogLastPath) << cDialogLastPath(); data.stream << quint32(dbiAnimationsDisabled) << qint32(anim::Disabled() ? 1 : 0); - data.stream << quint32(dbiConnectionType) << qint32(dbictProxiesList); - data.stream << qint32(proxies.size()); - data.stream << qint32(proxyIt - begin(proxies)) + 1; - data.stream << qint32(Global::ProxySettings()); - data.stream << qint32(Global::UseProxyForCalls() ? 1 : 0); - for (const auto &proxy : proxies) { - data.stream << qint32(kProxyTypeShift + int(proxy.type)); - data.stream << proxy.host << qint32(proxy.port) << proxy.user << proxy.password; - } - - data.stream << quint32(dbiTryIPv6) << qint32(Global::TryIPv6()); data.stream << quint32(dbiThemeKey) << quint64(_themeKeyDay) diff --git a/Telegram/SourceFiles/window/window_connecting_widget.cpp b/Telegram/SourceFiles/window/window_connecting_widget.cpp index d3a31cd38..f9b77b152 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.cpp +++ b/Telegram/SourceFiles/window/window_connecting_widget.cpp @@ -13,12 +13,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/mtp_instance.h" #include "mtproto/facade.h" #include "main/main_account.h" +#include "core/application.h" +#include "core/core_settings.h" #include "core/update_checker.h" #include "window/themes/window_theme.h" #include "boxes/connection_box.h" #include "boxes/abstract_box.h" #include "lang/lang_keys.h" -#include "facades.h" #include "app.h" #include "styles/style_window.h" @@ -224,9 +225,6 @@ ConnectionState::ConnectionState( } }, _lifetime); - subscribe(Global::RefConnectionTypeChanged(), [=] { - refreshState(); - }); if (!Core::UpdaterDisabled()) { Core::UpdateChecker checker; rpl::merge( @@ -236,7 +234,11 @@ ConnectionState::ConnectionState( refreshState(); }, _lifetime); } - refreshState(); + + Core::App().settings().proxy().connectionTypeValue( + ) | rpl::start_with_next([=] { + refreshState(); + }, _lifetime); } void ConnectionState::createWidget() { @@ -291,8 +293,7 @@ void ConnectionState::refreshState() { const auto under = _widget && _widget->isOver(); const auto ready = (Checker().state() == Checker::State::Ready); const auto state = _account->mtp().dcstate(); - const auto proxy - = (Global::ProxySettings() == MTP::ProxyData::Settings::Enabled); + const auto proxy = Core::App().settings().proxy().isEnabled(); if (state == MTP::ConnectingState || state == MTP::DisconnectedState || (state < 0 && state > -600)) { diff --git a/Telegram/SourceFiles/window/window_connecting_widget.h b/Telegram/SourceFiles/window/window_connecting_widget.h index 5d362179b..2aeb310df 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.h +++ b/Telegram/SourceFiles/window/window_connecting_widget.h @@ -21,7 +21,7 @@ class Account; namespace Window { -class ConnectionState : private base::Subscriber { +class ConnectionState { public: ConnectionState( not_null parent,