Improve handling of closed keychain
This commit is contained in:
@@ -335,7 +335,7 @@ Kirigami.ApplicationWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onGlobalErrorOccured(error, detail) {
|
function onGlobalErrorOccured(error, detail) {
|
||||||
showPassiveNotification(i18nc("%1: %2", error, detail));
|
showPassiveNotification(i18n("%1: %2", error, detail));
|
||||||
}
|
}
|
||||||
|
|
||||||
function onShowWindow() {
|
function onShowWindow() {
|
||||||
|
|||||||
@@ -311,23 +311,30 @@ QByteArray Controller::loadAccessTokenFromFile(const AccountSettings &account)
|
|||||||
|
|
||||||
QByteArray Controller::loadAccessTokenFromKeyChain(const AccountSettings &account)
|
QByteArray Controller::loadAccessTokenFromKeyChain(const AccountSettings &account)
|
||||||
{
|
{
|
||||||
qDebug() << "Read the access token from the keychain for " << account.userId();
|
QKeychain::Error error;
|
||||||
QKeychain::ReadPasswordJob job(qAppName());
|
QString errorString;
|
||||||
job.setAutoDelete(false);
|
do {
|
||||||
job.setKey(account.userId());
|
qDebug() << "Reading access token from the keychain for" << account.userId();
|
||||||
QEventLoop loop;
|
QKeychain::ReadPasswordJob job(qAppName());
|
||||||
QKeychain::ReadPasswordJob::connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
|
job.setAutoDelete(false);
|
||||||
job.start();
|
job.setKey(account.userId());
|
||||||
loop.exec();
|
QEventLoop loop;
|
||||||
|
QKeychain::ReadPasswordJob::connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
|
||||||
|
job.start();
|
||||||
|
loop.exec();
|
||||||
|
|
||||||
if (job.error() == QKeychain::Error::NoError) {
|
if (job.error() == QKeychain::Error::NoError) {
|
||||||
return job.binaryData();
|
return job.binaryData();
|
||||||
}
|
}
|
||||||
|
Q_EMIT globalErrorOccured(i18n("Unable to read access token"), i18n("Please make sure that the keychain is opened."));
|
||||||
|
error = job.error();
|
||||||
|
errorString = job.errorString();
|
||||||
|
} while (error == QKeychain::Error::OtherError);
|
||||||
|
|
||||||
qWarning() << "Could not read the access token from the keychain: " << qPrintable(job.errorString());
|
qWarning() << "Could not read the access token from the keychain:" << errorString;
|
||||||
// no access token from the keychain, try token file
|
// no access token from the keychain, try token file
|
||||||
auto accessToken = loadAccessTokenFromFile(account);
|
auto accessToken = loadAccessTokenFromFile(account);
|
||||||
if (job.error() == QKeychain::Error::EntryNotFound) {
|
if (error == QKeychain::Error::EntryNotFound) {
|
||||||
if (!accessToken.isEmpty()) {
|
if (!accessToken.isEmpty()) {
|
||||||
qDebug() << "Migrating the access token from file to the keychain for " << account.userId();
|
qDebug() << "Migrating the access token from file to the keychain for " << account.userId();
|
||||||
bool removed = false;
|
bool removed = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user