From 9b96dae744c3ea9cd48574e00bb40381dbf2b2f8 Mon Sep 17 00:00:00 2001 From: bbedward Date: Mon, 13 Oct 2025 19:46:18 -0400 Subject: [PATCH] Sync lock/unlock events with loginctl --- Modules/Lock/Lock.qml | 45 +++++++++++++++++++++++++++++++++++------ Services/DMSService.qml | 8 ++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Modules/Lock/Lock.qml b/Modules/Lock/Lock.qml index a5eab1e3..f50fdbbc 100644 --- a/Modules/Lock/Lock.qml +++ b/Modules/Lock/Lock.qml @@ -8,26 +8,59 @@ import qs.Common import qs.Services Scope { + id: root + property string sharedPasswordBuffer: "" property bool shouldLock: false + property bool processingExternalEvent: false Component.onCompleted: { IdleService.lockComponent = this } + function lock() { + if (!processingExternalEvent && SessionData.loginctlLockIntegration && DMSService.isConnected) { + DMSService.lockSession(response => { + if (response.error) { + console.warn("Lock: Failed to call loginctl.lock:", response.error) + shouldLock = true + } + }) + } else { + shouldLock = true + } + } + + function unlock() { + if (!processingExternalEvent && SessionData.loginctlLockIntegration && DMSService.isConnected) { + DMSService.unlockSession(response => { + if (response.error) { + console.warn("Lock: Failed to call loginctl.unlock:", response.error) + shouldLock = false + } + }) + } else { + shouldLock = false + } + } + function activate() { - shouldLock = true + lock() } Connections { target: SessionService function onSessionLocked() { + processingExternalEvent = true shouldLock = true + processingExternalEvent = false } function onSessionUnlocked() { + processingExternalEvent = true shouldLock = false + processingExternalEvent = false } } @@ -35,7 +68,7 @@ Scope { target: IdleService function onLockRequested() { - shouldLock = true + lock() } } @@ -50,12 +83,12 @@ Scope { LockSurface { anchors.fill: parent lock: sessionLock - sharedPasswordBuffer: sharedPasswordBuffer + sharedPasswordBuffer: root.sharedPasswordBuffer onUnlockRequested: { - shouldLock = false + root.unlock() } onPasswordChanged: newPassword => { - sharedPasswordBuffer = newPassword + root.sharedPasswordBuffer = newPassword } } } @@ -69,7 +102,7 @@ Scope { target: "lock" function lock() { - shouldLock = true + root.lock() } function demo() { diff --git a/Services/DMSService.qml b/Services/DMSService.qml index 0ef394a6..33b66b8c 100644 --- a/Services/DMSService.qml +++ b/Services/DMSService.qml @@ -394,4 +394,12 @@ Singleton { } }) } + + function lockSession(callback) { + sendRequest("loginctl.lock", null, callback) + } + + function unlockSession(callback) { + sendRequest("loginctl.unlock", null, callback) + } }