Watch for network availability changes

This commit is contained in:
Ilya Fedin 2021-04-06 00:07:23 +04:00 committed by John Preston
parent df73bda1ff
commit 3343880ed0
2 changed files with 10 additions and 2 deletions

View File

@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#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 {
@ -216,6 +217,7 @@ private:
const not_null<Instance*> _instance;
const Instance::Mode _mode = Instance::Mode::Normal;
const std::unique_ptr<Config> _config;
const std::shared_ptr<base::NetworkReachability> _networkReachability;
std::unique_ptr<QThread> _mainSessionThread;
std::unique_ptr<QThread> _otherSessionsThread;
@ -296,7 +298,8 @@ Instance::Private::Private(
: Sender(instance)
, _instance(instance)
, _mode(mode)
, _config(std::move(fields.config)) {
, _config(std::move(fields.config))
, _networkReachability(base::NetworkReachability::Instance()) {
Expects(_config != nullptr);
const auto idealThreadPoolSize = QThread::idealThreadCount();
@ -307,6 +310,11 @@ Instance::Private::Private(
unpaused();
}, _lifetime);
_networkReachability->availableChanges(
) | rpl::start_with_next([=](bool available) {
restart();
}, _lifetime);
_deviceModel = std::move(fields.deviceModel);
_systemVersion = std::move(fields.systemVersion);

@ -1 +1 @@
Subproject commit 2d51534213cf14fc816eca84f06765704a3b45d7
Subproject commit 8f0c0164cdce6bcbc7bcfe531963e2a552f6290d