From cab1c772abaf380f30a504231fc06b070feb09ec Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 15 Nov 2021 21:35:11 +0100 Subject: Save olm account on shutdown --- lib/connection.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'lib/connection.cpp') diff --git a/lib/connection.cpp b/lib/connection.cpp index f36166ff..20b4a113 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -270,6 +270,9 @@ Connection::Connection(const QUrl& server, QObject* parent) { #ifdef Quotient_E2EE_ENABLED d->encryptionManager = new EncryptionManager(this); + connect(qApp, &QCoreApplication::aboutToQuit, this, [this](){ + saveOlmAccount(); + }); #endif d->q = this; // All d initialization should occur before this line } @@ -498,11 +501,8 @@ void Connection::Private::completeSetup(const QString& mxId) // init olmAccount olmAccount = std::make_unique(data->userId(), data->deviceId(), q); - connect(olmAccount.get(), &QOlmAccount::needsSave, q, [=](){ - auto pickle = olmAccount->pickle(picklingMode); - AccountSettings(data->userId()).setEncryptionAccountPickle(std::get(pickle)); - //TODO handle errors - }); + connect(olmAccount.get(), &QOlmAccount::needsSave, q, &Connection::saveOlmAccount); + encryptionManager = new EncryptionManager(q); if (accountSettings.encryptionAccountPickle().isEmpty()) { @@ -2042,3 +2042,11 @@ PicklingMode Connection::picklingMode() const return d->picklingMode; } #endif + +void Connection::saveOlmAccount() +{ + qCDebug(E2EE) << "Saving olm account"; + auto pickle = d->olmAccount->pickle(d->picklingMode); + AccountSettings(d->data->userId()).setEncryptionAccountPickle(std::get(pickle)); + //TODO handle errors +} -- cgit v1.2.3