diff options
author | Petr Mrázek <peterix@gmail.com> | 2021-07-26 21:44:11 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2021-08-15 23:18:50 +0200 |
commit | 3a53349e332599221bc325f7fac9dc7927194bc2 (patch) | |
tree | 2ee40fa6044c241b3b7db27fe0b83931b453c2b2 /launcher/minecraft/auth/flows/MSAHelper.txt | |
parent | fca2e9e44cb44004eec7f47c03b186bd5e44dc32 (diff) | |
download | PrismLauncher-3a53349e332599221bc325f7fac9dc7927194bc2.tar.gz PrismLauncher-3a53349e332599221bc325f7fac9dc7927194bc2.tar.bz2 PrismLauncher-3a53349e332599221bc325f7fac9dc7927194bc2.zip |
GH-3392 dirty initial MSA support that shares logic with Mojang flows
Both act as the first step of AuthContext.
Diffstat (limited to 'launcher/minecraft/auth/flows/MSAHelper.txt')
-rw-r--r-- | launcher/minecraft/auth/flows/MSAHelper.txt | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/launcher/minecraft/auth/flows/MSAHelper.txt b/launcher/minecraft/auth/flows/MSAHelper.txt new file mode 100644 index 00000000..dfaec374 --- /dev/null +++ b/launcher/minecraft/auth/flows/MSAHelper.txt @@ -0,0 +1,51 @@ +class Helper : public QObject { + Q_OBJECT + +public: + Helper(MSAFlows * context) : QObject(), context_(context), msg_(QString()) { + QFile tokenCache("usercache.dat"); + if(tokenCache.open(QIODevice::ReadOnly)) { + context_->resumeFromState(tokenCache.readAll()); + } + } + +public slots: + void run() { + connect(context_, &MSAFlows::activityChanged, this, &Helper::onActivityChanged); + context_->silentSignIn(); + } + + void onFailed() { + qDebug() << "Login failed"; + } + + void onActivityChanged(Katabasis::Activity activity) { + if(activity == Katabasis::Activity::Idle) { + switch(context_->validity()) { + case Katabasis::Validity::None: { + // account is gone, remove it. + QFile::remove("usercache.dat"); + } + break; + case Katabasis::Validity::Assumed: { + // this is basically a soft-failed refresh. do nothing. + } + break; + case Katabasis::Validity::Certain: { + // stuff got refreshed / signed in. Save. + auto data = context_->saveState(); + QSaveFile tokenCache("usercache.dat"); + if(tokenCache.open(QIODevice::WriteOnly)) { + tokenCache.write(context_->saveState()); + tokenCache.commit(); + } + } + break; + } + } + } + +private: + MSAFlows *context_; + QString msg_; +}; |