aboutsummaryrefslogtreecommitdiff
path: root/modules/system/quickshell/LockContext.qml
blob: ea32a574fd5c71dfc5abdcde59c9d06c6f8a49f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import QtQuick
import Quickshell
import Quickshell.Services.Pam

Scope {
    id: root
    signal unlocked
    signal failed

    property string currentText: ""
    property bool unlockInProgress: false
    property string pamMessage: ""
    property bool pamError: false

    onCurrentTextChanged: {
        pamError = false;
        pamMessage = "";
    }

    function tryUnlock() {
        if (currentText === "" || unlockInProgress)
            return;
        unlockInProgress = true;
        pam.start();
    }

    function reset() {
        currentText = "";
        pamError = false;
        pamMessage = "";
        unlockInProgress = false;
    }

    PamContext {
        id: pam
        configDirectory: "pam"
        config: "password.conf"

        onPamMessage: {
            root.pamMessage = pam.message;
            root.pamError = pam.messageIsError;
            if (this.responseRequired) {
                this.respond(root.currentText);
            }
        }

        onCompleted: result => {
            if (result == PamResult.Success) {
                root.currentText = "";
                root.unlocked();
            } else {
                root.currentText = "";
                root.pamError = true;
                root.failed();
            }
            root.unlockInProgress = false;
        }
    }
}