mirror of https://github.com/procxx/kepka.git
Display connecting/online proxy state.
This commit is contained in:
parent
f794d8dbd8
commit
df4daca15b
|
@ -295,8 +295,7 @@ ProxiesBox::ProxiesBox(
|
||||||
this,
|
this,
|
||||||
object_ptr<Ui::Checkbox>(
|
object_ptr<Ui::Checkbox>(
|
||||||
this,
|
this,
|
||||||
lang(lng_proxy_use),
|
lang(lng_proxy_use)),
|
||||||
Global::UseProxy()),
|
|
||||||
st::proxyUsePadding)
|
st::proxyUsePadding)
|
||||||
, _tryIPv6(
|
, _tryIPv6(
|
||||||
this,
|
this,
|
||||||
|
@ -333,9 +332,10 @@ void ProxiesBox::setupContent() {
|
||||||
subscribe(_tryIPv6->entity()->checkedChanged, [=](bool checked) {
|
subscribe(_tryIPv6->entity()->checkedChanged, [=](bool checked) {
|
||||||
_controller->setTryIPv6(checked);
|
_controller->setTryIPv6(checked);
|
||||||
});
|
});
|
||||||
subscribe(Global::RefConnectionTypeChanged(), [=] {
|
_controller->proxyEnabledValue(
|
||||||
_useProxy->entity()->setChecked(Global::UseProxy());
|
) | rpl::start_with_next([=](bool enabled) {
|
||||||
});
|
_useProxy->entity()->setChecked(enabled);
|
||||||
|
}, _useProxy->entity()->lifetime());
|
||||||
|
|
||||||
_tryIPv6->resizeToWidth(st::boxWideWidth);
|
_tryIPv6->resizeToWidth(st::boxWideWidth);
|
||||||
|
|
||||||
|
@ -1037,14 +1037,27 @@ ProxiesBoxController::ProxiesBoxController()
|
||||||
) | ranges::view::transform([&](const ProxyData &proxy) {
|
) | ranges::view::transform([&](const ProxyData &proxy) {
|
||||||
return Item{ ++_idCounter, proxy };
|
return Item{ ++_idCounter, proxy };
|
||||||
}) | ranges::to_vector;
|
}) | ranges::to_vector;
|
||||||
for (auto &item : _list) {
|
|
||||||
if (!Global::UseProxy() || item.data != Global::SelectedProxy()) {
|
subscribe(Global::RefConnectionTypeChanged(), [=] {
|
||||||
createChecker(item);
|
_proxyEnabledChanges.fire_copy(Global::UseProxy());
|
||||||
|
const auto i = findByProxy(Global::SelectedProxy());
|
||||||
|
if (i != end(_list)) {
|
||||||
|
updateView(*i);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (auto &item : _list) {
|
||||||
|
refreshChecker(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProxiesBoxController::createChecker(Item &item) {
|
rpl::producer<bool> ProxiesBoxController::proxyEnabledValue() const {
|
||||||
|
return _proxyEnabledChanges.events_starting_with_copy(
|
||||||
|
Global::UseProxy()
|
||||||
|
) | rpl::distinct_until_changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProxiesBoxController::refreshChecker(Item &item) {
|
||||||
using Variants = MTP::DcOptions::Variants;
|
using Variants = MTP::DcOptions::Variants;
|
||||||
const auto type = (item.data.type == ProxyData::Type::Http)
|
const auto type = (item.data.type == ProxyData::Type::Http)
|
||||||
? Variants::Http
|
? Variants::Http
|
||||||
|
@ -1062,6 +1075,7 @@ void ProxiesBoxController::createChecker(Item &item) {
|
||||||
setup(item.checker);
|
setup(item.checker);
|
||||||
if (item.data.type == ProxyData::Type::Mtproto) {
|
if (item.data.type == ProxyData::Type::Mtproto) {
|
||||||
item.checkerv6 = nullptr;
|
item.checkerv6 = nullptr;
|
||||||
|
item.checker->setProxyOverride(item.data);
|
||||||
item.checker->connectToServer(
|
item.checker->connectToServer(
|
||||||
item.data.host,
|
item.data.host,
|
||||||
item.data.port,
|
item.data.port,
|
||||||
|
@ -1281,6 +1295,7 @@ void ProxiesBoxController::replaceItemValue(
|
||||||
Assert(i != end(proxies));
|
Assert(i != end(proxies));
|
||||||
*i = proxy;
|
*i = proxy;
|
||||||
which->data = proxy;
|
which->data = proxy;
|
||||||
|
refreshChecker(*which);
|
||||||
|
|
||||||
applyItem(which->id);
|
applyItem(which->id);
|
||||||
saveDelayed();
|
saveDelayed();
|
||||||
|
@ -1308,7 +1323,7 @@ void ProxiesBoxController::addNewItem(const ProxyData &proxy) {
|
||||||
proxies.push_back(proxy);
|
proxies.push_back(proxy);
|
||||||
|
|
||||||
_list.push_back({ ++_idCounter, proxy });
|
_list.push_back({ ++_idCounter, proxy });
|
||||||
createChecker(_list.back());
|
refreshChecker(_list.back());
|
||||||
applyItem(_list.back().id);
|
applyItem(_list.back().id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1367,6 +1382,14 @@ void ProxiesBoxController::updateView(const Item &item) {
|
||||||
}
|
}
|
||||||
Unexpected("Proxy type in ProxiesBoxController::updateView.");
|
Unexpected("Proxy type in ProxiesBoxController::updateView.");
|
||||||
}();
|
}();
|
||||||
|
const auto state = [&] {
|
||||||
|
if (!selected || !Global::UseProxy()) {
|
||||||
|
return item.state;
|
||||||
|
} else if (MTP::dcstate() == MTP::ConnectedState) {
|
||||||
|
return ItemState::Online;
|
||||||
|
}
|
||||||
|
return ItemState::Connecting;
|
||||||
|
}();
|
||||||
_views.fire({
|
_views.fire({
|
||||||
item.id,
|
item.id,
|
||||||
type,
|
type,
|
||||||
|
@ -1375,7 +1398,7 @@ void ProxiesBoxController::updateView(const Item &item) {
|
||||||
item.ping,
|
item.ping,
|
||||||
!deleted && selected,
|
!deleted && selected,
|
||||||
deleted,
|
deleted,
|
||||||
item.state });
|
state });
|
||||||
}
|
}
|
||||||
|
|
||||||
ProxiesBoxController::~ProxiesBoxController() {
|
ProxiesBoxController::~ProxiesBoxController() {
|
||||||
|
|
|
@ -92,7 +92,7 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProxiesBoxController {
|
class ProxiesBoxController : public base::Subscriber {
|
||||||
public:
|
public:
|
||||||
ProxiesBoxController();
|
ProxiesBoxController();
|
||||||
|
|
||||||
|
@ -125,6 +125,7 @@ public:
|
||||||
object_ptr<BoxContent> addNewItemBox();
|
object_ptr<BoxContent> addNewItemBox();
|
||||||
bool setProxyEnabled(bool enabled);
|
bool setProxyEnabled(bool enabled);
|
||||||
void setTryIPv6(bool enabled);
|
void setTryIPv6(bool enabled);
|
||||||
|
rpl::producer<bool> proxyEnabledValue() const;
|
||||||
|
|
||||||
rpl::producer<ItemView> views() const;
|
rpl::producer<ItemView> views() const;
|
||||||
|
|
||||||
|
@ -149,7 +150,7 @@ private:
|
||||||
void updateView(const Item &item);
|
void updateView(const Item &item);
|
||||||
void applyChanges();
|
void applyChanges();
|
||||||
void saveDelayed();
|
void saveDelayed();
|
||||||
void createChecker(Item &item);
|
void refreshChecker(Item &item);
|
||||||
void setupChecker(int id, const Checker &checker);
|
void setupChecker(int id, const Checker &checker);
|
||||||
|
|
||||||
void replaceItemWith(
|
void replaceItemWith(
|
||||||
|
@ -165,6 +166,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;
|
||||||
|
|
||||||
ProxyData _lastSelectedProxy;
|
ProxyData _lastSelectedProxy;
|
||||||
bool _lastSelectedProxyUsed = false;
|
bool _lastSelectedProxyUsed = false;
|
||||||
|
|
|
@ -269,9 +269,8 @@ bool ProxyData::ValidSecret(const QString &secret) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkProxy ToNetworkProxy(const ProxyData &proxy) {
|
QNetworkProxy ToNetworkProxy(const ProxyData &proxy) {
|
||||||
Expects(proxy.type != ProxyData::Type::Mtproto);
|
if (proxy.type == ProxyData::Type::None
|
||||||
|
|| proxy.type == ProxyData::Type::Mtproto) {
|
||||||
if (proxy.type == ProxyData::Type::None) {
|
|
||||||
return QNetworkProxy::NoProxy;
|
return QNetworkProxy::NoProxy;
|
||||||
}
|
}
|
||||||
return QNetworkProxy(
|
return QNetworkProxy(
|
||||||
|
|
|
@ -408,7 +408,7 @@ void MainWindow::mtpStateChanged(int32 dc, int32 state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateConnectingStatus() {
|
void MainWindow::updateConnectingStatus() {
|
||||||
auto state = MTP::dcstate();
|
const auto state = MTP::dcstate();
|
||||||
const auto throughProxy = Global::UseProxy();
|
const auto throughProxy = Global::UseProxy();
|
||||||
if (state == MTP::ConnectingState || state == MTP::DisconnectedState || (state < 0 && state > -600)) {
|
if (state == MTP::ConnectingState || state == MTP::DisconnectedState || (state < 0 && state > -600)) {
|
||||||
if (_main || getms() > 5000 || _connecting) {
|
if (_main || getms() > 5000 || _connecting) {
|
||||||
|
|
Loading…
Reference in New Issue