diff options
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_; +}; |