lockscreen: Fix lockscreen password entry after suspend, and restore passwordless

Fixes https://invent.kde.org/plasma/plasma-mobile/-/issues/334
This commit is contained in:
Devin Lin 2024-07-02 22:10:29 -04:00
parent 3efb51279e
commit daf43eae27
3 changed files with 28 additions and 8 deletions

View file

@ -11,6 +11,8 @@ MobileShell.SwipeArea {
id: root
required property real keypadHeight
property real animationDuration
readonly property real openFactor: position / keypadHeight
property real position: 0
property bool movingUp: false
@ -47,7 +49,7 @@ MobileShell.SwipeArea {
NumberAnimation on position {
id: positionAnim
duration: 800
duration: root.animationDuration
easing.type: Easing.OutExpo
onFinished: {

View file

@ -83,9 +83,19 @@ Item {
id: flickable
anchors.fill: parent
// Speed up animation when passwordless
animationDuration: root.lockScreenState.canBeUnlocked ? 400 : 800
// Distance to swipe to fully open keypad
keypadHeight: Kirigami.Units.gridUnit * 20
// Unlock lockscreen if it's already unlocked
onOpened: {
if (root.lockScreenState.canBeUnlocked) {
Qt.quit();
}
}
// Clear entered password after closing keypad
onOpenFactorChanged: {
if (flickable.openFactor < 0.1) {
@ -142,6 +152,7 @@ Item {
Keypad {
id: keypad
visible: !root.lockScreenState.canBeUnlocked // don't show for passwordless login
anchors.fill: parent
openProgress: flickable.openFactor
lockScreenState: root.lockScreenState

View file

@ -18,8 +18,8 @@ QtObject {
// the info message given
property string info: ""
// whether the lockscreen was passwordless
property bool passwordless: false // TODO true
// whether the lockscreen can be unlocked (no password needed, passwordless login)
readonly property bool canBeUnlocked: authenticator.unlocked
// whether the device can log in with fingerprint
readonly property bool isFingerprintSupported: authenticator.authenticatorTypes & ScreenLocker.Authenticator.Fingerprint
@ -38,9 +38,14 @@ QtObject {
Component.onCompleted: authenticator.startAuthenticating();
function tryPassword() {
if (root.password !== '') { // prevent typing lock when password is empty
// ensure it's in authenticating state (it might get unset after suspend)
authenticator.startAuthenticating();
// prevent typing lock when password is empty
if (root.password !== '') {
root.waitingForAuth = true;
}
console.log('attempt password');
authenticator.respond(root.password);
}
@ -66,10 +71,12 @@ QtObject {
target: authenticator
function onSucceeded() {
console.log('login succeeded');
root.waitingForAuth = false;
root.unlockSucceeded();
Qt.quit();
if (authenticator.hadPrompt) {
console.log('login succeeded');
root.waitingForAuth = false;
root.unlockSucceeded();
Qt.quit();
}
}
function onFailed(kind: int): void {