Wrap LockScreen in NLoader

This commit is contained in:
Ly-sec 2025-08-18 16:26:45 +02:00
parent 622c34a551
commit d688d04b77
2 changed files with 36 additions and 8 deletions

View file

@ -12,8 +12,35 @@ import qs.Commons
import qs.Services
import qs.Widgets
WlSessionLock {
id: lock
NLoader {
id: lockScreen
// External API
property bool locked: false
// Internal loader control; keep content alive briefly after unlocking
property bool _isLoadedInternal: false
// Only load when explicitly requested (locked) or while waiting to safely unload
isLoaded: _isLoadedInternal
onLockedChanged: {
if (locked) {
_isLoadedInternal = true
}
}
// Allow a small grace period after unlocking so the compositor releases the lock surfaces
Timer {
id: unloadAfterUnlockTimer
interval: 250
repeat: false
onTriggered: lockScreen._isLoadedInternal = false
}
function scheduleUnloadAfterUnlock() {
unloadAfterUnlockTimer.start()
}
content: Component {
WlSessionLock {
id: lock
// Keep inner lock state in sync with wrapper
locked: lockScreen.locked
onLockedChanged: lockScreen.locked = locked
// Lockscreen is a different beast, needs a capital 'S' in 'Screen' to get the current screen
readonly property real scaling: ScalingService.scale(Screen)
@ -22,7 +49,7 @@ WlSessionLock {
property bool authenticating: false
property string password: ""
property bool pamAvailable: typeof PamContext !== "undefined"
locked: false
function unlockAttempt() {
Logger.log("LockScreen", "Unlock attempt started")
@ -53,7 +80,10 @@ WlSessionLock {
lock.authenticating = false
if (result === PamResult.Success) {
Logger.log("LockScreen", "Authentication successful, unlocking")
// First release the Wayland session lock, then unload after a short delay
lock.locked = false
lockScreen.locked = false
lockScreen.scheduleUnloadAfterUnlock()
lock.password = ""
lock.errorMessage = ""
} else {
@ -865,5 +895,8 @@ WlSessionLock {
dateText.text = Qt.formatDateTime(new Date(), "dddd, MMMM d")
}
}
}
}
}
}