mirror of https://github.com/procxx/kepka.git
parent
ef64d9c188
commit
e482f041a8
|
@ -491,7 +491,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_connection_save" = "Save";
|
"lng_connection_save" = "Save";
|
||||||
|
|
||||||
"lng_proxy_settings" = "Proxy settings";
|
"lng_proxy_settings" = "Proxy settings";
|
||||||
"lng_proxy_use" = "Use proxy";
|
"lng_proxy_disable" = "Disable proxy";
|
||||||
|
"lng_proxy_use_system_settings" = "Use system proxy settings";
|
||||||
|
"lng_proxy_use_custom" = "Use custom proxy";
|
||||||
"lng_proxy_use_for_calls" = "Use proxy for calls";
|
"lng_proxy_use_for_calls" = "Use proxy for calls";
|
||||||
"lng_proxy_about" = "Proxy servers may be helpful in accessing Telegram if there is no connection in a specific region.";
|
"lng_proxy_about" = "Proxy servers may be helpful in accessing Telegram if there is no connection in a specific region.";
|
||||||
"lng_proxy_add" = "Add proxy";
|
"lng_proxy_add" = "Add proxy";
|
||||||
|
|
|
@ -195,11 +195,8 @@ void ApiWrap::refreshProxyPromotion() {
|
||||||
getProxyPromotionDelayed(now, next);
|
getProxyPromotionDelayed(now, next);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto proxy = Global::UseProxy()
|
|
||||||
? Global::SelectedProxy()
|
|
||||||
: ProxyData();
|
|
||||||
const auto key = [&]() -> std::pair<QString, uint32> {
|
const auto key = [&]() -> std::pair<QString, uint32> {
|
||||||
if (!Global::UseProxy()) {
|
if (Global::ProxySettings() != ProxyData::Settings::Enabled) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const auto &proxy = Global::SelectedProxy();
|
const auto &proxy = Global::SelectedProxy();
|
||||||
|
|
|
@ -362,7 +362,7 @@ void Application::refreshGlobalProxy() {
|
||||||
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
||||||
const auto proxy = [&] {
|
const auto proxy = [&] {
|
||||||
if (Global::started()) {
|
if (Global::started()) {
|
||||||
return Global::UseProxy()
|
return (Global::ProxySettings() == ProxyData::Settings::Enabled)
|
||||||
? Global::SelectedProxy()
|
? Global::SelectedProxy()
|
||||||
: ProxyData();
|
: ProxyData();
|
||||||
}
|
}
|
||||||
|
@ -372,8 +372,11 @@ void Application::refreshGlobalProxy() {
|
||||||
|| proxy.type == ProxyData::Type::Http) {
|
|| proxy.type == ProxyData::Type::Http) {
|
||||||
QNetworkProxy::setApplicationProxy(
|
QNetworkProxy::setApplicationProxy(
|
||||||
ToNetworkProxy(ToDirectIpProxy(proxy)));
|
ToNetworkProxy(ToDirectIpProxy(proxy)));
|
||||||
} else {
|
} else if (!Global::started()
|
||||||
|
|| Global::ProxySettings() == ProxyData::Settings::System) {
|
||||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||||
|
} else {
|
||||||
|
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
|
||||||
}
|
}
|
||||||
#endif // TDESKTOP_DISABLE_NETWORK_PROXY
|
#endif // TDESKTOP_DISABLE_NETWORK_PROXY
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ private:
|
||||||
|
|
||||||
not_null<ProxiesBoxController*> _controller;
|
not_null<ProxiesBoxController*> _controller;
|
||||||
QPointer<Ui::Checkbox> _tryIPv6;
|
QPointer<Ui::Checkbox> _tryIPv6;
|
||||||
QPointer<Ui::Checkbox> _useProxy;
|
std::shared_ptr<Ui::RadioenumGroup<ProxyData::Settings>> _proxySettings;
|
||||||
QPointer<Ui::SlideWrap<Ui::Checkbox>> _proxyForCalls;
|
QPointer<Ui::SlideWrap<Ui::Checkbox>> _proxyForCalls;
|
||||||
QPointer<Ui::DividerLabel> _about;
|
QPointer<Ui::DividerLabel> _about;
|
||||||
base::unique_qptr<Ui::RpWidget> _noRows;
|
base::unique_qptr<Ui::RpWidget> _noRows;
|
||||||
|
@ -504,10 +504,29 @@ void ProxiesBox::setupContent() {
|
||||||
lang(lng_connection_try_ipv6),
|
lang(lng_connection_try_ipv6),
|
||||||
Global::TryIPv6()),
|
Global::TryIPv6()),
|
||||||
st::proxyTryIPv6Padding);
|
st::proxyTryIPv6Padding);
|
||||||
_useProxy = inner->add(
|
_proxySettings
|
||||||
object_ptr<Ui::Checkbox>(
|
= std::make_shared<Ui::RadioenumGroup<ProxyData::Settings>>(
|
||||||
|
Global::ProxySettings());
|
||||||
|
inner->add(
|
||||||
|
object_ptr<Ui::Radioenum<ProxyData::Settings>>(
|
||||||
inner,
|
inner,
|
||||||
lang(lng_proxy_use)),
|
_proxySettings,
|
||||||
|
ProxyData::Settings::Disabled,
|
||||||
|
lang(lng_proxy_disable)),
|
||||||
|
st::proxyUsePadding);
|
||||||
|
inner->add(
|
||||||
|
object_ptr<Ui::Radioenum<ProxyData::Settings>>(
|
||||||
|
inner,
|
||||||
|
_proxySettings,
|
||||||
|
ProxyData::Settings::System,
|
||||||
|
lang(lng_proxy_use_system_settings)),
|
||||||
|
st::proxyUsePadding);
|
||||||
|
inner->add(
|
||||||
|
object_ptr<Ui::Radioenum<ProxyData::Settings>>(
|
||||||
|
inner,
|
||||||
|
_proxySettings,
|
||||||
|
ProxyData::Settings::Enabled,
|
||||||
|
lang(lng_proxy_use_custom)),
|
||||||
st::proxyUsePadding);
|
st::proxyUsePadding);
|
||||||
_proxyForCalls = inner->add(
|
_proxyForCalls = inner->add(
|
||||||
object_ptr<Ui::SlideWrap<Ui::Checkbox>>(
|
object_ptr<Ui::SlideWrap<Ui::Checkbox>>(
|
||||||
|
@ -543,9 +562,9 @@ void ProxiesBox::setupContent() {
|
||||||
inner,
|
inner,
|
||||||
st::proxyRowPadding.bottom()));
|
st::proxyRowPadding.bottom()));
|
||||||
|
|
||||||
subscribe(_useProxy->checkedChanged, [=](bool checked) {
|
_proxySettings->setChangedCallback([=](ProxyData::Settings value) {
|
||||||
if (!_controller->setProxyEnabled(checked)) {
|
if (!_controller->setProxySettings(value)) {
|
||||||
_useProxy->setChecked(false);
|
_proxySettings->setValue(Global::ProxySettings());
|
||||||
addNewProxy();
|
addNewProxy();
|
||||||
}
|
}
|
||||||
refreshProxyForCalls();
|
refreshProxyForCalls();
|
||||||
|
@ -553,11 +572,11 @@ void ProxiesBox::setupContent() {
|
||||||
subscribe(_tryIPv6->checkedChanged, [=](bool checked) {
|
subscribe(_tryIPv6->checkedChanged, [=](bool checked) {
|
||||||
_controller->setTryIPv6(checked);
|
_controller->setTryIPv6(checked);
|
||||||
});
|
});
|
||||||
_controller->proxyEnabledValue(
|
_controller->proxySettingsValue(
|
||||||
) | rpl::start_with_next([=](bool enabled) {
|
) | rpl::start_with_next([=](ProxyData::Settings value) {
|
||||||
_useProxy->setChecked(enabled);
|
_proxySettings->setValue(value);
|
||||||
}, _useProxy->lifetime());
|
}, inner->lifetime());
|
||||||
_useProxy->finishAnimating();
|
|
||||||
subscribe(_proxyForCalls->entity()->checkedChanged, [=](bool checked) {
|
subscribe(_proxyForCalls->entity()->checkedChanged, [=](bool checked) {
|
||||||
_controller->setProxyForCalls(checked);
|
_controller->setProxyForCalls(checked);
|
||||||
});
|
});
|
||||||
|
@ -588,7 +607,8 @@ void ProxiesBox::refreshProxyForCalls() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_proxyForCalls->toggle(
|
_proxyForCalls->toggle(
|
||||||
_useProxy->checked() && _currentProxySupportsCallsId != 0,
|
(_proxySettings->value() == ProxyData::Settings::Enabled
|
||||||
|
&& _currentProxySupportsCallsId != 0),
|
||||||
anim::type::normal);
|
anim::type::normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1032,7 +1052,7 @@ ProxiesBoxController::ProxiesBoxController()
|
||||||
}) | ranges::to_vector;
|
}) | ranges::to_vector;
|
||||||
|
|
||||||
subscribe(Global::RefConnectionTypeChanged(), [=] {
|
subscribe(Global::RefConnectionTypeChanged(), [=] {
|
||||||
_proxyEnabledChanges.fire_copy(Global::UseProxy());
|
_proxySettingsChanges.fire_copy(Global::ProxySettings());
|
||||||
const auto i = findByProxy(Global::SelectedProxy());
|
const auto i = findByProxy(Global::SelectedProxy());
|
||||||
if (i != end(_list)) {
|
if (i != end(_list)) {
|
||||||
updateView(*i);
|
updateView(*i);
|
||||||
|
@ -1074,7 +1094,9 @@ void ProxiesBoxController::ShowApplyConfirmation(
|
||||||
if (ranges::find(proxies, proxy) == end(proxies)) {
|
if (ranges::find(proxies, proxy) == end(proxies)) {
|
||||||
proxies.push_back(proxy);
|
proxies.push_back(proxy);
|
||||||
}
|
}
|
||||||
Messenger::Instance().setCurrentProxy(proxy, true);
|
Messenger::Instance().setCurrentProxy(
|
||||||
|
proxy,
|
||||||
|
ProxyData::Settings::Enabled);
|
||||||
Local::writeSettings();
|
Local::writeSettings();
|
||||||
if (const auto strong = box->data()) {
|
if (const auto strong = box->data()) {
|
||||||
strong->closeBox();
|
strong->closeBox();
|
||||||
|
@ -1083,9 +1105,10 @@ void ProxiesBoxController::ShowApplyConfirmation(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<bool> ProxiesBoxController::proxyEnabledValue() const {
|
auto ProxiesBoxController::proxySettingsValue() const
|
||||||
return _proxyEnabledChanges.events_starting_with_copy(
|
-> rpl::producer<ProxyData::Settings> {
|
||||||
Global::UseProxy()
|
return _proxySettingsChanges.events_starting_with_copy(
|
||||||
|
Global::ProxySettings()
|
||||||
) | rpl::distinct_until_changed();
|
) | rpl::distinct_until_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1227,7 +1250,8 @@ void ProxiesBoxController::shareItem(int id) {
|
||||||
|
|
||||||
void ProxiesBoxController::applyItem(int id) {
|
void ProxiesBoxController::applyItem(int id) {
|
||||||
auto item = findById(id);
|
auto item = findById(id);
|
||||||
if (Global::UseProxy() && Global::SelectedProxy() == item->data) {
|
if ((Global::ProxySettings() == ProxyData::Settings::Enabled)
|
||||||
|
&& Global::SelectedProxy() == item->data) {
|
||||||
return;
|
return;
|
||||||
} else if (item->deleted) {
|
} else if (item->deleted) {
|
||||||
return;
|
return;
|
||||||
|
@ -1235,7 +1259,9 @@ void ProxiesBoxController::applyItem(int id) {
|
||||||
|
|
||||||
auto j = findByProxy(Global::SelectedProxy());
|
auto j = findByProxy(Global::SelectedProxy());
|
||||||
|
|
||||||
Messenger::Instance().setCurrentProxy(item->data, true);
|
Messenger::Instance().setCurrentProxy(
|
||||||
|
item->data,
|
||||||
|
ProxyData::Settings::Enabled);
|
||||||
saveDelayed();
|
saveDelayed();
|
||||||
|
|
||||||
if (j != end(_list)) {
|
if (j != end(_list)) {
|
||||||
|
@ -1254,11 +1280,11 @@ void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
||||||
|
|
||||||
if (item->data == Global::SelectedProxy()) {
|
if (item->data == Global::SelectedProxy()) {
|
||||||
_lastSelectedProxy = base::take(Global::RefSelectedProxy());
|
_lastSelectedProxy = base::take(Global::RefSelectedProxy());
|
||||||
if (Global::UseProxy()) {
|
if (Global::ProxySettings() == ProxyData::Settings::Enabled) {
|
||||||
_lastSelectedProxyUsed = true;
|
_lastSelectedProxyUsed = true;
|
||||||
Messenger::Instance().setCurrentProxy(
|
Messenger::Instance().setCurrentProxy(
|
||||||
ProxyData(),
|
ProxyData(),
|
||||||
false);
|
ProxyData::Settings::System);
|
||||||
saveDelayed();
|
saveDelayed();
|
||||||
} else {
|
} else {
|
||||||
_lastSelectedProxyUsed = false;
|
_lastSelectedProxyUsed = false;
|
||||||
|
@ -1278,12 +1304,12 @@ void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Global::SelectedProxy() && _lastSelectedProxy == item->data) {
|
if (!Global::SelectedProxy() && _lastSelectedProxy == item->data) {
|
||||||
Assert(!Global::UseProxy());
|
Assert(Global::ProxySettings() != ProxyData::Settings::Enabled);
|
||||||
|
|
||||||
if (base::take(_lastSelectedProxyUsed)) {
|
if (base::take(_lastSelectedProxyUsed)) {
|
||||||
Messenger::Instance().setCurrentProxy(
|
Messenger::Instance().setCurrentProxy(
|
||||||
base::take(_lastSelectedProxy),
|
base::take(_lastSelectedProxy),
|
||||||
true);
|
ProxyData::Settings::Enabled);
|
||||||
} else {
|
} else {
|
||||||
Global::SetSelectedProxy(base::take(_lastSelectedProxy));
|
Global::SetSelectedProxy(base::take(_lastSelectedProxy));
|
||||||
}
|
}
|
||||||
|
@ -1372,10 +1398,10 @@ void ProxiesBoxController::addNewItem(const ProxyData &proxy) {
|
||||||
applyItem(_list.back().id);
|
applyItem(_list.back().id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProxiesBoxController::setProxyEnabled(bool enabled) {
|
bool ProxiesBoxController::setProxySettings(ProxyData::Settings value) {
|
||||||
if (Global::UseProxy() == enabled) {
|
if (Global::ProxySettings() == value) {
|
||||||
return true;
|
return true;
|
||||||
} else if (enabled) {
|
} else if (value == ProxyData::Settings::Enabled) {
|
||||||
if (Global::ProxiesList().empty()) {
|
if (Global::ProxiesList().empty()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (!Global::SelectedProxy()) {
|
} else if (!Global::SelectedProxy()) {
|
||||||
|
@ -1388,7 +1414,7 @@ bool ProxiesBoxController::setProxyEnabled(bool enabled) {
|
||||||
}
|
}
|
||||||
Messenger::Instance().setCurrentProxy(
|
Messenger::Instance().setCurrentProxy(
|
||||||
Global::SelectedProxy(),
|
Global::SelectedProxy(),
|
||||||
enabled);
|
value);
|
||||||
saveDelayed();
|
saveDelayed();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1398,7 +1424,8 @@ void ProxiesBoxController::setProxyForCalls(bool enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Global::SetUseProxyForCalls(enabled);
|
Global::SetUseProxyForCalls(enabled);
|
||||||
if (Global::UseProxy() && Global::SelectedProxy().supportsCalls()) {
|
if ((Global::ProxySettings() == ProxyData::Settings::Enabled)
|
||||||
|
&& Global::SelectedProxy().supportsCalls()) {
|
||||||
Global::RefConnectionTypeChanged().notify();
|
Global::RefConnectionTypeChanged().notify();
|
||||||
}
|
}
|
||||||
saveDelayed();
|
saveDelayed();
|
||||||
|
@ -1438,7 +1465,8 @@ void ProxiesBoxController::updateView(const Item &item) {
|
||||||
Unexpected("Proxy type in ProxiesBoxController::updateView.");
|
Unexpected("Proxy type in ProxiesBoxController::updateView.");
|
||||||
}();
|
}();
|
||||||
const auto state = [&] {
|
const auto state = [&] {
|
||||||
if (!selected || !Global::UseProxy()) {
|
if (!selected
|
||||||
|
|| (Global::ProxySettings() != ProxyData::Settings::Enabled)) {
|
||||||
return item.state;
|
return item.state;
|
||||||
} else if (MTP::dcstate() == MTP::ConnectedState) {
|
} else if (MTP::dcstate() == MTP::ConnectedState) {
|
||||||
return ItemState::Online;
|
return ItemState::Online;
|
||||||
|
|
|
@ -74,10 +74,10 @@ public:
|
||||||
void applyItem(int id);
|
void applyItem(int id);
|
||||||
object_ptr<BoxContent> editItemBox(int id);
|
object_ptr<BoxContent> editItemBox(int id);
|
||||||
object_ptr<BoxContent> addNewItemBox();
|
object_ptr<BoxContent> addNewItemBox();
|
||||||
bool setProxyEnabled(bool enabled);
|
bool setProxySettings(ProxyData::Settings value);
|
||||||
void setProxyForCalls(bool enabled);
|
void setProxyForCalls(bool enabled);
|
||||||
void setTryIPv6(bool enabled);
|
void setTryIPv6(bool enabled);
|
||||||
rpl::producer<bool> proxyEnabledValue() const;
|
rpl::producer<ProxyData::Settings> proxySettingsValue() const;
|
||||||
|
|
||||||
rpl::producer<ItemView> views() const;
|
rpl::producer<ItemView> views() const;
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ private:
|
||||||
std::vector<Item> _list;
|
std::vector<Item> _list;
|
||||||
rpl::event_stream<ItemView> _views;
|
rpl::event_stream<ItemView> _views;
|
||||||
base::Timer _saveTimer;
|
base::Timer _saveTimer;
|
||||||
rpl::event_stream<bool> _proxyEnabledChanges;
|
rpl::event_stream<ProxyData::Settings> _proxySettingsChanges;
|
||||||
|
|
||||||
ProxyData _lastSelectedProxy;
|
ProxyData _lastSelectedProxy;
|
||||||
bool _lastSelectedProxyUsed = false;
|
bool _lastSelectedProxyUsed = false;
|
||||||
|
|
|
@ -597,7 +597,8 @@ void Call::createAndStartController(const MTPDphoneCall &call) {
|
||||||
_controller->SetConfig(config);
|
_controller->SetConfig(config);
|
||||||
_controller->SetEncryptionKey(reinterpret_cast<char*>(_authKey.data()), (_type == Type::Outgoing));
|
_controller->SetEncryptionKey(reinterpret_cast<char*>(_authKey.data()), (_type == Type::Outgoing));
|
||||||
_controller->SetCallbacks(callbacks);
|
_controller->SetCallbacks(callbacks);
|
||||||
if (Global::UseProxy() && Global::UseProxyForCalls()) {
|
if (Global::UseProxyForCalls()
|
||||||
|
&& (Global::ProxySettings() == ProxyData::Settings::Enabled)) {
|
||||||
const auto proxy = Global::SelectedProxy();
|
const auto proxy = Global::SelectedProxy();
|
||||||
if (proxy.supportsCalls()) {
|
if (proxy.supportsCalls()) {
|
||||||
Assert(proxy.type == ProxyData::Type::Socks5);
|
Assert(proxy.type == ProxyData::Type::Socks5);
|
||||||
|
|
|
@ -334,6 +334,11 @@ enum DBIWorkMode {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProxyData {
|
struct ProxyData {
|
||||||
|
enum class Settings {
|
||||||
|
System,
|
||||||
|
Enabled,
|
||||||
|
Disabled,
|
||||||
|
};
|
||||||
enum class Type {
|
enum class Type {
|
||||||
None,
|
None,
|
||||||
Socks5,
|
Socks5,
|
||||||
|
|
|
@ -662,7 +662,7 @@ struct Data {
|
||||||
bool TryIPv6 = (cPlatform() == dbipWindows) ? false : true;
|
bool TryIPv6 = (cPlatform() == dbipWindows) ? false : true;
|
||||||
std::vector<ProxyData> ProxiesList;
|
std::vector<ProxyData> ProxiesList;
|
||||||
ProxyData SelectedProxy;
|
ProxyData SelectedProxy;
|
||||||
bool UseProxy = false;
|
ProxyData::Settings ProxySettings = ProxyData::Settings::System;
|
||||||
bool UseProxyForCalls = false;
|
bool UseProxyForCalls = false;
|
||||||
base::Observable<void> ConnectionTypeChanged;
|
base::Observable<void> ConnectionTypeChanged;
|
||||||
|
|
||||||
|
@ -791,7 +791,7 @@ DefineVar(Global, bool, NotificationsDemoIsShown);
|
||||||
DefineVar(Global, bool, TryIPv6);
|
DefineVar(Global, bool, TryIPv6);
|
||||||
DefineVar(Global, std::vector<ProxyData>, ProxiesList);
|
DefineVar(Global, std::vector<ProxyData>, ProxiesList);
|
||||||
DefineVar(Global, ProxyData, SelectedProxy);
|
DefineVar(Global, ProxyData, SelectedProxy);
|
||||||
DefineVar(Global, bool, UseProxy);
|
DefineVar(Global, ProxyData::Settings, ProxySettings);
|
||||||
DefineVar(Global, bool, UseProxyForCalls);
|
DefineVar(Global, bool, UseProxyForCalls);
|
||||||
DefineRefVar(Global, base::Observable<void>, ConnectionTypeChanged);
|
DefineRefVar(Global, base::Observable<void>, ConnectionTypeChanged);
|
||||||
|
|
||||||
|
|
|
@ -317,7 +317,7 @@ DeclareVar(bool, NotificationsDemoIsShown);
|
||||||
DeclareVar(bool, TryIPv6);
|
DeclareVar(bool, TryIPv6);
|
||||||
DeclareVar(std::vector<ProxyData>, ProxiesList);
|
DeclareVar(std::vector<ProxyData>, ProxiesList);
|
||||||
DeclareVar(ProxyData, SelectedProxy);
|
DeclareVar(ProxyData, SelectedProxy);
|
||||||
DeclareVar(bool, UseProxy);
|
DeclareVar(ProxyData::Settings, ProxySettings);
|
||||||
DeclareVar(bool, UseProxyForCalls);
|
DeclareVar(bool, UseProxyForCalls);
|
||||||
DeclareRefVar(base::Observable<void>, ConnectionTypeChanged);
|
DeclareRefVar(base::Observable<void>, ConnectionTypeChanged);
|
||||||
|
|
||||||
|
|
|
@ -283,18 +283,19 @@ bool Messenger::eventFilter(QObject *object, QEvent *e) {
|
||||||
|
|
||||||
void Messenger::setCurrentProxy(
|
void Messenger::setCurrentProxy(
|
||||||
const ProxyData &proxy,
|
const ProxyData &proxy,
|
||||||
bool enabled) {
|
ProxyData::Settings settings) {
|
||||||
const auto key = [&](const ProxyData &proxy) {
|
const auto key = [&](const ProxyData &proxy) {
|
||||||
if (proxy.type == ProxyData::Type::Mtproto) {
|
if (proxy.type == ProxyData::Type::Mtproto) {
|
||||||
return std::make_pair(proxy.host, proxy.port);
|
return std::make_pair(proxy.host, proxy.port);
|
||||||
}
|
}
|
||||||
return std::make_pair(QString(), uint32(0));
|
return std::make_pair(QString(), uint32(0));
|
||||||
};
|
};
|
||||||
const auto previousKey = key(Global::UseProxy()
|
const auto previousKey = key(
|
||||||
? Global::SelectedProxy()
|
(Global::ProxySettings() == ProxyData::Settings::Enabled
|
||||||
: ProxyData());
|
? Global::SelectedProxy()
|
||||||
|
: ProxyData()));
|
||||||
Global::SetSelectedProxy(proxy);
|
Global::SetSelectedProxy(proxy);
|
||||||
Global::SetUseProxy(enabled);
|
Global::SetProxySettings(settings);
|
||||||
Sandbox::refreshGlobalProxy();
|
Sandbox::refreshGlobalProxy();
|
||||||
if (_mtproto) {
|
if (_mtproto) {
|
||||||
_mtproto->restart();
|
_mtproto->restart();
|
||||||
|
@ -309,10 +310,16 @@ void Messenger::setCurrentProxy(
|
||||||
}
|
}
|
||||||
|
|
||||||
void Messenger::badMtprotoConfigurationError() {
|
void Messenger::badMtprotoConfigurationError() {
|
||||||
if (Global::UseProxy() && !_badProxyDisableBox) {
|
if (Global::ProxySettings() == ProxyData::Settings::Enabled
|
||||||
|
&& !_badProxyDisableBox) {
|
||||||
|
const auto disableCallback = [=] {
|
||||||
|
setCurrentProxy(
|
||||||
|
Global::SelectedProxy(),
|
||||||
|
ProxyData::Settings::System);
|
||||||
|
};
|
||||||
_badProxyDisableBox = Ui::show(Box<InformBox>(
|
_badProxyDisableBox = Ui::show(Box<InformBox>(
|
||||||
Lang::Hard::ProxyConfigError(),
|
Lang::Hard::ProxyConfigError(),
|
||||||
[=] { setCurrentProxy(Global::SelectedProxy(), false); }));
|
disableCallback));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,9 @@ public:
|
||||||
MTP::DcOptions *dcOptions() {
|
MTP::DcOptions *dcOptions() {
|
||||||
return _dcOptions.get();
|
return _dcOptions.get();
|
||||||
}
|
}
|
||||||
void setCurrentProxy(const ProxyData &proxy, bool enabled);
|
void setCurrentProxy(
|
||||||
|
const ProxyData &proxy,
|
||||||
|
ProxyData::Settings settings);
|
||||||
void badMtprotoConfigurationError();
|
void badMtprotoConfigurationError();
|
||||||
|
|
||||||
// Set from legacy storage.
|
// Set from legacy storage.
|
||||||
|
|
|
@ -102,7 +102,7 @@ void ConfigLoader::enumerate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigLoader::refreshSpecialLoader() {
|
void ConfigLoader::refreshSpecialLoader() {
|
||||||
if (Global::UseProxy()) {
|
if (Global::ProxySettings() == ProxyData::Settings::Enabled) {
|
||||||
_specialLoader.reset();
|
_specialLoader.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ void ConfigLoader::addSpecialEndpoint(
|
||||||
|
|
||||||
void ConfigLoader::sendSpecialRequest() {
|
void ConfigLoader::sendSpecialRequest() {
|
||||||
terminateSpecialRequest();
|
terminateSpecialRequest();
|
||||||
if (Global::UseProxy()) {
|
if (Global::ProxySettings() == ProxyData::Settings::Enabled) {
|
||||||
_specialLoader.reset();
|
_specialLoader.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -329,7 +329,8 @@ void Instance::Private::applyDomainIps(
|
||||||
for (auto &proxy : Global::RefProxiesList()) {
|
for (auto &proxy : Global::RefProxiesList()) {
|
||||||
applyToProxy(proxy);
|
applyToProxy(proxy);
|
||||||
}
|
}
|
||||||
if (applyToProxy(Global::RefSelectedProxy()) && Global::UseProxy()) {
|
if (applyToProxy(Global::RefSelectedProxy())
|
||||||
|
&& (Global::ProxySettings() == ProxyData::Settings::Enabled)) {
|
||||||
for (auto &session : _sessions) {
|
for (auto &session : _sessions) {
|
||||||
session.second->refreshOptions();
|
session.second->refreshOptions();
|
||||||
}
|
}
|
||||||
|
@ -358,7 +359,8 @@ void Instance::Private::setGoodProxyDomain(
|
||||||
for (auto &proxy : Global::RefProxiesList()) {
|
for (auto &proxy : Global::RefProxiesList()) {
|
||||||
applyToProxy(proxy);
|
applyToProxy(proxy);
|
||||||
}
|
}
|
||||||
if (applyToProxy(Global::RefSelectedProxy()) && Global::UseProxy()) {
|
if (applyToProxy(Global::RefSelectedProxy())
|
||||||
|
&& (Global::ProxySettings() == ProxyData::Settings::Enabled)) {
|
||||||
Sandbox::refreshGlobalProxy();
|
Sandbox::refreshGlobalProxy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,9 +171,10 @@ void Session::restart() {
|
||||||
|
|
||||||
void Session::refreshOptions() {
|
void Session::refreshOptions() {
|
||||||
const auto &proxy = Global::SelectedProxy();
|
const auto &proxy = Global::SelectedProxy();
|
||||||
const auto proxyType = Global::UseProxy()
|
const auto proxyType =
|
||||||
? proxy.type
|
(Global::ProxySettings() == ProxyData::Settings::Enabled
|
||||||
: ProxyData::Type::None;
|
? proxy.type
|
||||||
|
: ProxyData::Type::None);
|
||||||
const auto useTcp = (proxyType != ProxyData::Type::Http);
|
const auto useTcp = (proxyType != ProxyData::Type::Http);
|
||||||
const auto useHttp = (proxyType != ProxyData::Type::Mtproto);
|
const auto useHttp = (proxyType != ProxyData::Type::Mtproto);
|
||||||
const auto useIPv4 = true;
|
const auto useIPv4 = true;
|
||||||
|
@ -182,7 +183,9 @@ void Session::refreshOptions() {
|
||||||
_instance->systemLangCode(),
|
_instance->systemLangCode(),
|
||||||
_instance->cloudLangCode(),
|
_instance->cloudLangCode(),
|
||||||
_instance->langPackName(),
|
_instance->langPackName(),
|
||||||
Global::UseProxy() ? proxy : ProxyData(),
|
(Global::ProxySettings() == ProxyData::Settings::Enabled
|
||||||
|
? proxy
|
||||||
|
: ProxyData()),
|
||||||
useIPv4,
|
useIPv4,
|
||||||
useIPv6,
|
useIPv6,
|
||||||
useHttp,
|
useHttp,
|
||||||
|
|
|
@ -43,7 +43,7 @@ void SetupConnectionType(not_null<Ui::VerticalLayout*> container) {
|
||||||
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
||||||
const auto connectionType = [] {
|
const auto connectionType = [] {
|
||||||
const auto transport = MTP::dctransport();
|
const auto transport = MTP::dctransport();
|
||||||
if (!Global::UseProxy()) {
|
if (Global::ProxySettings() != ProxyData::Settings::Enabled) {
|
||||||
return transport.isEmpty()
|
return transport.isEmpty()
|
||||||
? lang(lng_connection_auto_connecting)
|
? lang(lng_connection_auto_connecting)
|
||||||
: lng_connection_auto(lt_transport, transport);
|
: lng_connection_auto(lt_transport, transport);
|
||||||
|
|
|
@ -612,7 +612,8 @@ enum {
|
||||||
dbictHttpAuto = 1, // not used
|
dbictHttpAuto = 1, // not used
|
||||||
dbictHttpProxy = 2,
|
dbictHttpProxy = 2,
|
||||||
dbictTcpProxy = 3,
|
dbictTcpProxy = 3,
|
||||||
dbictProxiesList = 4,
|
dbictProxiesListOld = 4,
|
||||||
|
dbictProxiesList = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QMap<PeerId, FileKey> DraftsMap;
|
typedef QMap<PeerId, FileKey> DraftsMap;
|
||||||
|
@ -1214,7 +1215,9 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
||||||
} break;
|
} break;
|
||||||
};
|
};
|
||||||
Global::SetSelectedProxy(proxy ? proxy : ProxyData());
|
Global::SetSelectedProxy(proxy ? proxy : ProxyData());
|
||||||
Global::SetUseProxy(proxy ? true : false);
|
Global::SetProxySettings(proxy
|
||||||
|
? ProxyData::Settings::Enabled
|
||||||
|
: ProxyData::Settings::System);
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
Global::SetProxiesList({ 1, proxy });
|
Global::SetProxiesList({ 1, proxy });
|
||||||
} else {
|
} else {
|
||||||
|
@ -1248,14 +1251,16 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
||||||
: ProxyData::Type::None;
|
: ProxyData::Type::None;
|
||||||
return proxy;
|
return proxy;
|
||||||
};
|
};
|
||||||
if (connectionType == dbictProxiesList) {
|
if (connectionType == dbictProxiesListOld
|
||||||
|
|| connectionType == dbictProxiesList) {
|
||||||
qint32 count = 0, index = 0;
|
qint32 count = 0, index = 0;
|
||||||
stream >> count >> index;
|
stream >> count >> index;
|
||||||
if (std::abs(index) > count) {
|
qint32 settings = 0, calls = 0;
|
||||||
Global::SetUseProxyForCalls(true);
|
if (connectionType == dbictProxiesList) {
|
||||||
|
stream >> settings >> calls;
|
||||||
|
} else if (std::abs(index) > count) {
|
||||||
|
calls = 1;
|
||||||
index -= (index > 0 ? count : -count);
|
index -= (index > 0 ? count : -count);
|
||||||
} else {
|
|
||||||
Global::SetUseProxyForCalls(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto list = std::vector<ProxyData>();
|
auto list = std::vector<ProxyData>();
|
||||||
|
@ -1273,13 +1278,31 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Global::SetProxiesList(list);
|
Global::SetProxiesList(list);
|
||||||
Global::SetUseProxy(index > 0 && index <= list.size());
|
if (connectionType == dbictProxiesListOld) {
|
||||||
index = std::abs(index);
|
settings = static_cast<qint32>(
|
||||||
|
(index > 0 && index <= list.size()
|
||||||
|
? ProxyData::Settings::Enabled
|
||||||
|
: ProxyData::Settings::System));
|
||||||
|
index = std::abs(index);
|
||||||
|
}
|
||||||
if (index > 0 && index <= list.size()) {
|
if (index > 0 && index <= list.size()) {
|
||||||
Global::SetSelectedProxy(list[index - 1]);
|
Global::SetSelectedProxy(list[index - 1]);
|
||||||
} else {
|
} else {
|
||||||
Global::SetSelectedProxy(ProxyData());
|
Global::SetSelectedProxy(ProxyData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto unchecked = static_cast<ProxyData::Settings>(settings);
|
||||||
|
switch (unchecked) {
|
||||||
|
case ProxyData::Settings::Disabled:
|
||||||
|
case ProxyData::Settings::System:
|
||||||
|
case ProxyData::Settings::Enabled:
|
||||||
|
Global::SetProxySettings(unchecked);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Global::SetProxySettings(ProxyData::Settings::System);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Global::SetUseProxyForCalls(calls == 1);
|
||||||
} else {
|
} else {
|
||||||
const auto proxy = readProxy();
|
const auto proxy = readProxy();
|
||||||
if (!_checkStreamStatus(stream)) {
|
if (!_checkStreamStatus(stream)) {
|
||||||
|
@ -1290,14 +1313,14 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
||||||
Global::SetSelectedProxy(proxy);
|
Global::SetSelectedProxy(proxy);
|
||||||
if (connectionType == dbictTcpProxy
|
if (connectionType == dbictTcpProxy
|
||||||
|| connectionType == dbictHttpProxy) {
|
|| connectionType == dbictHttpProxy) {
|
||||||
Global::SetUseProxy(true);
|
Global::SetProxySettings(ProxyData::Settings::Enabled);
|
||||||
} else {
|
} else {
|
||||||
Global::SetUseProxy(false);
|
Global::SetProxySettings(ProxyData::Settings::System);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Global::SetProxiesList({});
|
Global::SetProxiesList({});
|
||||||
Global::SetSelectedProxy(ProxyData());
|
Global::SetSelectedProxy(ProxyData());
|
||||||
Global::SetUseProxy(false);
|
Global::SetProxySettings(ProxyData::Settings::System);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Sandbox::refreshGlobalProxy();
|
Sandbox::refreshGlobalProxy();
|
||||||
|
@ -2576,10 +2599,9 @@ void writeSettings() {
|
||||||
|
|
||||||
data.stream << quint32(dbiConnectionType) << qint32(dbictProxiesList);
|
data.stream << quint32(dbiConnectionType) << qint32(dbictProxiesList);
|
||||||
data.stream << qint32(proxies.size());
|
data.stream << qint32(proxies.size());
|
||||||
const auto index = qint32(proxyIt - begin(proxies))
|
data.stream << qint32(proxyIt - begin(proxies)) + 1;
|
||||||
+ qint32(Global::UseProxyForCalls() ? proxies.size() : 0)
|
data.stream << qint32(Global::ProxySettings());
|
||||||
+ 1;
|
data.stream << qint32(Global::UseProxyForCalls() ? 1 : 0);
|
||||||
data.stream << (Global::UseProxy() ? index : -index);
|
|
||||||
for (const auto &proxy : proxies) {
|
for (const auto &proxy : proxies) {
|
||||||
data.stream << qint32(kProxyTypeShift + int(proxy.type));
|
data.stream << qint32(kProxyTypeShift + int(proxy.type));
|
||||||
data.stream << proxy.host << qint32(proxy.port) << proxy.user << proxy.password;
|
data.stream << proxy.host << qint32(proxy.port) << proxy.user << proxy.password;
|
||||||
|
|
|
@ -345,7 +345,8 @@ void ConnectingWidget::refreshState() {
|
||||||
const auto state = [&]() -> State {
|
const auto state = [&]() -> State {
|
||||||
const auto under = isOver();
|
const auto under = isOver();
|
||||||
const auto mtp = MTP::dcstate();
|
const auto mtp = MTP::dcstate();
|
||||||
const auto throughProxy = Global::UseProxy();
|
const auto throughProxy
|
||||||
|
= (Global::ProxySettings() == ProxyData::Settings::Enabled);
|
||||||
if (mtp == MTP::ConnectingState
|
if (mtp == MTP::ConnectingState
|
||||||
|| mtp == MTP::DisconnectedState
|
|| mtp == MTP::DisconnectedState
|
||||||
|| (mtp < 0 && mtp > -600)) {
|
|| (mtp < 0 && mtp > -600)) {
|
||||||
|
|
Loading…
Reference in New Issue