diff --git a/.config/quickshell/ii/modules/common/Config.qml b/.config/quickshell/ii/modules/common/Config.qml index b59cc31dc..00e0afd2a 100644 --- a/.config/quickshell/ii/modules/common/Config.qml +++ b/.config/quickshell/ii/modules/common/Config.qml @@ -268,6 +268,7 @@ Singleton { } property bool centerClock: true property bool showLockedText: true + property bool unlockKeyring: true } property JsonObject media: JsonObject { diff --git a/.config/quickshell/ii/modules/lock/LockContext.qml b/.config/quickshell/ii/modules/lock/LockContext.qml index 976aa9c6a..f48b84057 100644 --- a/.config/quickshell/ii/modules/lock/LockContext.qml +++ b/.config/quickshell/ii/modules/lock/LockContext.qml @@ -1,4 +1,5 @@ import qs +import qs.modules.common import QtQuick import Quickshell import Quickshell.Services.Pam @@ -55,6 +56,7 @@ Scope { onCompleted: result => { if (result == PamResult.Success) { root.unlocked(); + if (Config.options.lock.unlockKeyring) root.unlockKeyring(); } else { root.showFailure = true; GlobalStates.screenUnlockFailed = true; @@ -64,4 +66,13 @@ Scope { root.unlockInProgress = false; } } + + function unlockKeyring() { + Quickshell.execDetached({ + environment: ({ + UNLOCK_PASSWORD: root.currentText + }), + command: ["bash", "-c", Quickshell.shellPath("scripts/keyring/unlock.sh")] + }) + } } diff --git a/.config/quickshell/ii/scripts/keyring/unlock.sh b/.config/quickshell/ii/scripts/keyring/unlock.sh new file mode 100755 index 000000000..b255f8e0f --- /dev/null +++ b/.config/quickshell/ii/scripts/keyring/unlock.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Based on https://unix.stackexchange.com/a/602935 + +# Skip if already unlocked +locked_state=$(busctl --user get-property org.freedesktop.secrets \ + /org/freedesktop/secrets/collection/login \ + org.freedesktop.Secret.Collection Locked) +if [[ "${locked_state}" == "b false" ]]; then + echo 'Keyring is already unlocked.' >&2 + exit 1 +fi + +# Prompt for password if not provided +if [[ -z "${UNLOCK_PASSWORD}" ]]; then + echo -n 'Login password: ' >&2 + read -s UNLOCK_PASSWORD || return +fi + +# Unlock +killall -q -u "$(whoami)" gnome-keyring-daemon +eval $(echo -n "${UNLOCK_PASSWORD}" \ + | gnome-keyring-daemon --daemonize --login \ + | sed -e 's/^/export /') +unset UNLOCK_PASSWORD +echo '' >&2