From 6297d4d2e37abadfab0f7389aec9aa4af7f928bc Mon Sep 17 00:00:00 2001
From: Xaver Hugl <xaver.hugl@gmail.com>
Date: Tue, 2 Jul 2024 20:07:06 +0000
Subject: [PATCH] greeter/authenticators: add a property for if a prompt was
 shown in the past

This is needed to properly check for whether or not to show an unlock button

CCBUG: 485520


(cherry picked from commit bc1e4a18ce37d1f40cb6a50acf3d9c53b052bf5e)

Co-authored-by: Xaver Hugl <xaver.hugl@gmail.com>
---
 greeter/pamauthenticators.cpp | 14 ++++++++++++++
 greeter/pamauthenticators.h   |  5 +++++
 2 files changed, 19 insertions(+)

diff --git a/greeter/pamauthenticators.cpp b/greeter/pamauthenticators.cpp
index 8fcbb6d5..d564420 100644
--- a/greeter/pamauthenticators.cpp
+++ b/greeter/pamauthenticators.cpp
@@ -17,6 +17,7 @@ struct PamAuthenticators::Private {
     PamAuthenticator::NoninteractiveAuthenticatorTypes computedTypes = PamAuthenticator::NoninteractiveAuthenticatorType::None;
     AuthenticatorsState state = AuthenticatorsState::Idle;
     bool graceLocked = false;
+    bool hadPrompt = false;
 
     void recomputeNoninteractiveAuthenticationTypes()
     {
@@ -83,10 +84,18 @@ PamAuthenticators::PamAuthenticators(std::unique_ptr<PamAuthenticator> &&interac
         Q_EMIT busyChanged();
     });
     connect(d->interactive.get(), &PamAuthenticator::prompt, this, [this] {
+        if (!d->hadPrompt) {
+            d->hadPrompt = true;
+            Q_EMIT hadPromptChanged();
+        }
         qCDebug(KSCREENLOCKER_GREET) << "PamAuthenticators: Normal prompt from interactive authenticator" << qUtf8Printable(d->interactive->service());
         Q_EMIT promptChanged();
     });
     connect(d->interactive.get(), &PamAuthenticator::promptForSecret, this, [this] {
+        if (!d->hadPrompt) {
+            d->hadPrompt = true;
+            Q_EMIT hadPromptChanged();
+        }
         qCDebug(KSCREENLOCKER_GREET) << "PamAuthenticators: Secret prompt from interactive authenticator" << qUtf8Printable(d->interactive->service());
         Q_EMIT promptForSecretChanged();
     });
@@ -198,3 +207,8 @@ void PamAuthenticators::setGraceLocked(bool b)
 {
     d->graceLocked = b;
 }
+
+bool PamAuthenticators::hadPrompt() const
+{
+    return d->hadPrompt;
+}
diff --git a/greeter/pamauthenticators.h b/greeter/pamauthenticators.h
index e82f77b..9184e7e 100644
--- a/greeter/pamauthenticators.h
+++ b/greeter/pamauthenticators.h
@@ -31,6 +31,8 @@ class PamAuthenticators : public QObject
 
     Q_PROPERTY(AuthenticatorsState state READ state NOTIFY stateChanged)
 
+    Q_PROPERTY(bool hadPrompt READ hadPrompt NOTIFY hadPromptChanged)
+
 public:
     PamAuthenticators(std::unique_ptr<PamAuthenticator> &&interactive,
                       std::vector<std::unique_ptr<PamAuthenticator>> &&noninteractive,
@@ -78,6 +80,9 @@ public:
 
     void setGraceLocked(bool b);
 
+    bool hadPrompt() const;
+    Q_SIGNAL void hadPromptChanged();
+
 private:
     struct Private;
     QScopedPointer<Private> d;
-- 
2.45.2

