mirror of
https://github.com/hyprwm/hyprpolkitagent.git
synced 2024-12-25 20:59:49 +01:00
qml/core: minor improvements
This commit is contained in:
parent
e714ed59ac
commit
848239ce4b
6 changed files with 26 additions and 15 deletions
10
qml/main.qml
10
qml/main.qml
|
@ -13,6 +13,9 @@ ApplicationWindow {
|
|||
minimumWidth: windowWidth
|
||||
minimumHeight: windowHeight
|
||||
visible: true
|
||||
onClosing: {
|
||||
hpa.setResult("fail");
|
||||
}
|
||||
|
||||
FontMetrics {
|
||||
id: fontMetrics
|
||||
|
@ -71,6 +74,13 @@ ApplicationWindow {
|
|||
onFocusField: () => {
|
||||
passwordField.focus = true;
|
||||
}
|
||||
onBlockInput: (block) => {
|
||||
passwordField.readOnly = block;
|
||||
if (!block) {
|
||||
passwordField.focus = true;
|
||||
passwordField.selectAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,3 +27,7 @@ void CQMLIntegration::setError(QString str) {
|
|||
void CQMLIntegration::focus() {
|
||||
emit focusField();
|
||||
}
|
||||
|
||||
void CQMLIntegration::setInputBlocked(bool blocked) {
|
||||
emit blockInput(blocked);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ class CQMLIntegration : public QObject {
|
|||
|
||||
void setError(QString str);
|
||||
void focus();
|
||||
void setInputBlocked(bool blocked);
|
||||
|
||||
QString result = "fail", errorText = "";
|
||||
|
||||
|
@ -33,4 +34,5 @@ class CQMLIntegration : public QObject {
|
|||
signals:
|
||||
void setErrorString(QString err);
|
||||
void focusField();
|
||||
void blockInput(bool block);
|
||||
};
|
||||
|
|
|
@ -73,13 +73,10 @@ void CAgent::initAuthPrompt() {
|
|||
}
|
||||
|
||||
bool CAgent::resultReady() {
|
||||
std::lock_guard<std::mutex> lg(lastAuthResult.resultMutex);
|
||||
|
||||
return !lastAuthResult.used;
|
||||
}
|
||||
|
||||
void CAgent::submitResultThreadSafe(const std::string& result) {
|
||||
std::lock_guard<std::mutex> lg(lastAuthResult.resultMutex);
|
||||
lastAuthResult.used = false;
|
||||
lastAuthResult.result = result;
|
||||
|
||||
|
@ -92,10 +89,3 @@ void CAgent::submitResultThreadSafe(const std::string& result) {
|
|||
else
|
||||
listener.cancelPending();
|
||||
}
|
||||
|
||||
void CAgent::setAuthError(const QString& err) {
|
||||
if (!authState.qmlIntegration)
|
||||
return;
|
||||
|
||||
authState.qmlIntegration->setErrorString(err);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ class CAgent {
|
|||
void resetAuthState();
|
||||
bool start();
|
||||
void initAuthPrompt();
|
||||
void setAuthError(const QString& err);
|
||||
|
||||
private:
|
||||
struct {
|
||||
|
@ -36,7 +35,6 @@ class CAgent {
|
|||
} authState;
|
||||
|
||||
struct {
|
||||
std::mutex resultMutex;
|
||||
std::string result;
|
||||
bool used = true;
|
||||
} lastAuthResult;
|
||||
|
@ -48,6 +46,7 @@ class CAgent {
|
|||
bool resultReady();
|
||||
|
||||
friend class CQMLIntegration;
|
||||
friend class CPolkitListener;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CAgent> g_pAgent;
|
|
@ -2,6 +2,7 @@
|
|||
#include <QInputDialog>
|
||||
|
||||
#include "PolkitListener.hpp"
|
||||
#include "../QMLIntegration.hpp"
|
||||
#include "Agent.hpp"
|
||||
#include <polkitqt1-agent-session.h>
|
||||
|
||||
|
@ -81,8 +82,8 @@ void CPolkitListener::completed(bool gainedAuthorization) {
|
|||
|
||||
session.gainedAuth = gainedAuthorization;
|
||||
|
||||
if (!gainedAuthorization)
|
||||
g_pAgent->setAuthError("Authentication failed");
|
||||
if (!gainedAuthorization && g_pAgent->authState.qmlIntegration)
|
||||
g_pAgent->authState.qmlIntegration->setError("Authentication failed");
|
||||
|
||||
finishAuth();
|
||||
}
|
||||
|
@ -90,7 +91,8 @@ void CPolkitListener::completed(bool gainedAuthorization) {
|
|||
void CPolkitListener::showError(const QString& text) {
|
||||
std::print("> PKS showError: {}\n", text.toStdString());
|
||||
|
||||
g_pAgent->setAuthError(text);
|
||||
if (g_pAgent->authState.qmlIntegration)
|
||||
g_pAgent->authState.qmlIntegration->setError(text);
|
||||
}
|
||||
|
||||
void CPolkitListener::showInfo(const QString& text) {
|
||||
|
@ -105,6 +107,8 @@ void CPolkitListener::finishAuth() {
|
|||
|
||||
if (!session.gainedAuth && !session.cancelled) {
|
||||
std::print("> finishAuth: Did not gain auth. Reattempting.\n");
|
||||
if (g_pAgent->authState.qmlIntegration)
|
||||
g_pAgent->authState.qmlIntegration->blockInput(false);
|
||||
session.session->deleteLater();
|
||||
reattempt();
|
||||
return;
|
||||
|
@ -128,6 +132,8 @@ void CPolkitListener::submitPassword(const QString& pass) {
|
|||
return;
|
||||
|
||||
session.session->setResponse(pass);
|
||||
if (g_pAgent->authState.qmlIntegration)
|
||||
g_pAgent->authState.qmlIntegration->blockInput(true);
|
||||
}
|
||||
|
||||
void CPolkitListener::cancelPending() {
|
||||
|
|
Loading…
Reference in a new issue