Decouple MTP::Instance from Core::App.

This commit is contained in:
John Preston 2019-02-01 10:48:31 +03:00
parent 4f3263d979
commit f5cc93ec64
5 changed files with 44 additions and 5 deletions

View File

@ -440,10 +440,13 @@ void Application::setMtpAuthorization(const QByteArray &serialized) {
void Application::startMtp() { void Application::startMtp() {
Expects(!_mtproto); Expects(!_mtproto);
auto config = base::take(_private->mtpConfig);
config.deviceModel = _launcher->deviceModel();
config.systemVersion = _launcher->systemVersion();
_mtproto = std::make_unique<MTP::Instance>( _mtproto = std::make_unique<MTP::Instance>(
_dcOptions.get(), _dcOptions.get(),
MTP::Instance::Mode::Normal, MTP::Instance::Mode::Normal,
base::take(_private->mtpConfig)); std::move(config));
_mtproto->setUserPhone(cLoggedPhoneNumber()); _mtproto->setUserPhone(cLoggedPhoneNumber());
_private->mtpConfig.mainDcId = _mtproto->mainDcId(); _private->mtpConfig.mainDcId = _mtproto->mainDcId();
@ -526,7 +529,12 @@ void Application::destroyMtpKeys(MTP::AuthKeysList &&keys) {
auto destroyConfig = MTP::Instance::Config(); auto destroyConfig = MTP::Instance::Config();
destroyConfig.mainDcId = MTP::Instance::Config::kNoneMainDc; destroyConfig.mainDcId = MTP::Instance::Config::kNoneMainDc;
destroyConfig.keys = std::move(keys); destroyConfig.keys = std::move(keys);
_mtprotoForKeysDestroy = std::make_unique<MTP::Instance>(_dcOptions.get(), MTP::Instance::Mode::KeysDestroyer, std::move(destroyConfig)); destroyConfig.deviceModel = _launcher->deviceModel();
destroyConfig.systemVersion = _launcher->systemVersion();
_mtprotoForKeysDestroy = std::make_unique<MTP::Instance>(
_dcOptions.get(),
MTP::Instance::Mode::KeysDestroyer,
std::move(destroyConfig));
connect( connect(
_mtprotoForKeysDestroy.get(), _mtprotoForKeysDestroy.get(),
&MTP::Instance::allKeysDestroyed, &MTP::Instance::allKeysDestroyed,

View File

@ -24,7 +24,6 @@ public:
QString argumentsString() const; QString argumentsString() const;
bool customWorkingDir() const; bool customWorkingDir() const;
// Thread safe.
QString deviceModel() const; QString deviceModel() const;
QString systemVersion() const; QString systemVersion() const;
uint64 installationTag() const; uint64 installationTag() const;

View File

@ -820,10 +820,10 @@ void ConnectionPrivate::tryToSend() {
const auto langPackName = _connectionOptions->langPackName; const auto langPackName = _connectionOptions->langPackName;
const auto deviceModel = (_dcType == DcType::Cdn) const auto deviceModel = (_dcType == DcType::Cdn)
? "n/a" ? "n/a"
: Core::App().launcher()->deviceModel(); : _instance->deviceModel();
const auto systemVersion = (_dcType == DcType::Cdn) const auto systemVersion = (_dcType == DcType::Cdn)
? "n/a" ? "n/a"
: Core::App().launcher()->systemVersion(); : _instance->systemVersion();
#if defined OS_MAC_STORE || defined OS_WIN_STORE #if defined OS_MAC_STORE || defined OS_WIN_STORE
const auto appVersion = QString::fromLatin1(AppVersionStr) const auto appVersion = QString::fromLatin1(AppVersionStr)
+ " store"; + " store";

View File

@ -50,6 +50,10 @@ public:
not_null<DcOptions*> dcOptions(); not_null<DcOptions*> dcOptions();
// Thread safe.
QString deviceModel() const;
QString systemVersion() const;
void requestConfig(); void requestConfig();
void requestConfigIfOld(); void requestConfigIfOld();
void requestCDNConfig(); void requestCDNConfig();
@ -171,6 +175,9 @@ private:
bool _mainDcIdForced = false; bool _mainDcIdForced = false;
std::map<DcId, std::shared_ptr<internal::Dcenter>> _dcenters; std::map<DcId, std::shared_ptr<internal::Dcenter>> _dcenters;
QString _deviceModel;
QString _systemVersion;
internal::Session *_mainSession = nullptr; internal::Session *_mainSession = nullptr;
std::map<ShiftedDcId, std::unique_ptr<internal::Session>> _sessions; std::map<ShiftedDcId, std::unique_ptr<internal::Session>> _sessions;
std::vector<std::unique_ptr<internal::Session>> _killedSessions; // delayed delete std::vector<std::unique_ptr<internal::Session>> _killedSessions; // delayed delete
@ -232,6 +239,9 @@ Instance::Private::Private(
} }
void Instance::Private::start(Config &&config) { void Instance::Private::start(Config &&config) {
_deviceModel = std::move(config.deviceModel);
_systemVersion = std::move(config.systemVersion);
if (isKeysDestroyer()) { if (isKeysDestroyer()) {
_instance->connect(_instance, SIGNAL(keyDestroyed(qint32)), _instance, SLOT(onKeyDestroyed(qint32)), Qt::QueuedConnection); _instance->connect(_instance, SIGNAL(keyDestroyed(qint32)), _instance, SLOT(onKeyDestroyed(qint32)), Qt::QueuedConnection);
} else if (isNormal()) { } else if (isNormal()) {
@ -705,6 +715,14 @@ not_null<DcOptions*> Instance::Private::dcOptions() {
return _dcOptions; return _dcOptions;
} }
QString Instance::Private::deviceModel() const {
return _deviceModel;
}
QString Instance::Private::systemVersion() const {
return _systemVersion;
}
void Instance::Private::unpaused() { void Instance::Private::unpaused() {
for (auto &session : _sessions) { for (auto &session : _sessions) {
session.second->unpaused(); session.second->unpaused();
@ -1638,6 +1656,14 @@ not_null<DcOptions*> Instance::dcOptions() {
return _private->dcOptions(); return _private->dcOptions();
} }
QString Instance::deviceModel() const {
return _private->deviceModel();
}
QString Instance::systemVersion() const {
return _private->systemVersion();
}
void Instance::unpaused() { void Instance::unpaused() {
_private->unpaused(); _private->unpaused();
} }

View File

@ -35,6 +35,8 @@ public:
DcId mainDcId = kNotSetMainDc; DcId mainDcId = kNotSetMainDc;
AuthKeysList keys; AuthKeysList keys;
QString deviceModel;
QString systemVersion;
}; };
enum class Mode { enum class Mode {
Normal, Normal,
@ -55,6 +57,10 @@ public:
QString cloudLangCode() const; QString cloudLangCode() const;
QString langPackName() const; QString langPackName() const;
// Thread safe.
QString deviceModel() const;
QString systemVersion() const;
void setKeyForWrite(DcId dcId, const AuthKeyPtr &key); void setKeyForWrite(DcId dcId, const AuthKeyPtr &key);
AuthKeysList getKeysForWrite() const; AuthKeysList getKeysForWrite() const;
void addKeysForDestroy(AuthKeysList &&keys); void addKeysForDestroy(AuthKeysList &&keys);