#!/bin/bash
# Usage: wait-for-keyring <command...>
# Wait (up to 60 s) for the login keyring to be unlocked, then exec the command,
# so autostarted apps don't trigger the keyring password prompt while the
# YubiKey unlock is still in progress.
for _ in $(seq 120); do
  [[ $(busctl --user get-property org.freedesktop.secrets /org/freedesktop/secrets/collection/login \
       org.freedesktop.Secret.Collection Locked 2>/dev/null) == "b false" ]] && break
  sleep 0.5
done
exec "$@"
