From 6aded403b8e43704c2c8b0fa752f2b24242b36ad Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 20 Jul 2022 09:25:57 +0200 Subject: [PATCH] qml: pin lock after inactivity --- electrum/gui/qml/components/Pin.qml | 7 +++++-- electrum/gui/qml/components/main.qml | 30 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/electrum/gui/qml/components/Pin.qml b/electrum/gui/qml/components/Pin.qml index 9c1948af6..7c7b94cd8 100644 --- a/electrum/gui/qml/components/Pin.qml +++ b/electrum/gui/qml/components/Pin.qml @@ -21,12 +21,15 @@ Dialog { modal: true parent: Overlay.overlay Overlay.modal: Rectangle { - color: "#aa000000" + color: canCancel ? "#aa000000" : "#ff000000" } focus: true - standardButtons: Dialog.Cancel + standardButtons: canCancel ? Dialog.Cancel : 0 + closePolicy: canCancel ? Popup.CloseOnEscape | Popup.CloseOnPressOutside : Popup.NoAutoClose + + property bool canCancel: true property string mode // [check, enter, change] property string pincode // old one passed in when change, new one passed out diff --git a/electrum/gui/qml/components/main.qml b/electrum/gui/qml/components/main.qml index b496a4026..819eada00 100644 --- a/electrum/gui/qml/components/main.qml +++ b/electrum/gui/qml/components/main.qml @@ -275,7 +275,7 @@ ApplicationWindow } function handleAuthRequired(qtobject, method) { - console.log('AUTHENTICATING USING METHOD ' + method) + console.log('auth using method ' + method) if (method == 'wallet') { if (Daemon.currentWallet.verify_password('')) { // wallet has no password @@ -309,6 +309,34 @@ ApplicationWindow }) dialog.open() } + } else { + console.log('unknown auth method ' + method) + qtobject.authCancel() + } + } + + property var _lastActive: 0 // record time of last activity + property int _maxInactive: 30 // seconds + property bool _lockDialogShown: false + + onActiveChanged: { + console.log('active='+active) + if (!active) { + // deactivated + _lastActive = Date.now() + } else { + // activated + if (_lastActive != 0 && Date.now() - _lastActive > _maxInactive * 1000) { + if (_lockDialogShown || Config.pinCode == '') + return + var dialog = app.pinDialog.createObject(app, {mode: 'check', canCancel: false, pincode: Config.pinCode}) + dialog.accepted.connect(function() { + dialog.close() + _lockDialogShown = false + }) + dialog.open() + _lockDialogShown = true + } } }