mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-23 03:58:49 +00:00
feat: detect if biometrics was enabled
This commit is contained in:
parent
1f0d65ada5
commit
dcdb910f4f
@ -14,7 +14,7 @@ class Keychain : public QObject {
|
||||
|
||||
Q_PROPERTY(QString service READ service WRITE setService NOTIFY serviceChanged)
|
||||
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
|
||||
Q_PROPERTY(bool available READ available CONSTANT)
|
||||
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
|
||||
|
||||
public:
|
||||
explicit Keychain(QObject *parent = nullptr);
|
||||
@ -50,6 +50,7 @@ signals:
|
||||
void serviceChanged();
|
||||
void reasonChanged();
|
||||
void loadingChanged();
|
||||
void availableChanged();
|
||||
|
||||
private:
|
||||
QString m_service;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <QDebug>
|
||||
#include <QEventLoop>
|
||||
#include <QFuture>
|
||||
#include <QGuiApplication>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
@ -50,6 +51,15 @@ Keychain::Keychain(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
reevaluateAvailability();
|
||||
|
||||
connect(qApp,
|
||||
&QGuiApplication::applicationStateChanged,
|
||||
this,
|
||||
[this](Qt::ApplicationState state) {
|
||||
if (state == Qt::ApplicationActive) {
|
||||
reevaluateAvailability();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Keychain::~Keychain()
|
||||
@ -213,12 +223,17 @@ void Keychain::reevaluateAvailability()
|
||||
auto context = [[LAContext alloc] init];
|
||||
NSError *authError = nil;
|
||||
|
||||
m_available = [context canEvaluatePolicy:authPolicy error:&authError];
|
||||
const auto available = [context canEvaluatePolicy:authPolicy error:&authError];
|
||||
|
||||
if (!m_available) {
|
||||
const auto description = QString::fromNSString(authError.localizedDescription);
|
||||
qDebug() << "Keychain is not available" << description;
|
||||
// Later this description can be used if needed:
|
||||
// const auto description = QString::fromNSString(authError.localizedDescription);
|
||||
|
||||
if (m_available == available) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_available = available;
|
||||
emit availableChanged();
|
||||
}
|
||||
|
||||
Keychain::Status Keychain::hasCredential(const QString &account) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user