calcurse: one-click Google login renewal

On expiry calcurse-sync starts calcurse-relogin, a notification that opens the consent page when clicked and catches the OAuth code on 127.0.0.1:8749. dunst's left-click now runs a notification's action before closing it.
This commit is contained in:
Daniele Fucini committed 2026-11-12 14:35:56 +01:00
1 parent 3bb25669ea
commit 566ac562bd
4 files changed
+121 -8

No files matched your search

+12 -7
View File
@@ -1,13 +1,18 @@
#!/bin/bash
# Sync calcurse with Google Calendar via calcurse-caldav; notify once when the weekly OAuth login expires.
# Sync calcurse with Google Calendar via calcurse-caldav; start the login prompt when the weekly OAuth login expires.
# --now: called from the UI's pre-load hook (skip the UI check, shorter timeout, no daemon restart).
# --authcode CODE: finish a login (from calcurse-relogin, which checks for the UI itself).
set -uo pipefail
data=${XDG_DATA_HOME:-$HOME/.local/share}/calcurse
state=${XDG_STATE_HOME:-$HOME/.local/state}/calcurse-sync
expired_flag=$state/login-expired
now=false
[[ ${1:-} == --now ]] && now=true
authcode=()
case ${1:-} in
--now) now=true ;;
--authcode) authcode=(--authcode "$2") ;;
esac
# The UI keeps the data in memory, so syncing under it would lose changes; its post-save hook syncs after it exits.
ui_running() {
@@ -15,22 +20,22 @@ ui_running() {
ps -C calcurse -o tty= | grep -qv '?'
}
if ! $now && ui_running; then
if ! $now && ((${#authcode[@]} == 0)) && ui_running; then
echo "calcurse UI is running, skipping"
exit 0
fi
mkdir -p "$state"
# BROWSER=true: an expired login must not open browser tabs on its own.
out=$(BROWSER=true timeout "$($now && echo 15 || echo 60)" calcurse-caldav 2>&1)
out=$(BROWSER=true timeout "$($now && echo 15 || echo 60)" calcurse-caldav "${authcode[@]}" 2>&1)
rc=$?
printf '%s\n' "$out"
if ((rc != 0)); then
if grep -q 'Access token is missing or refresh token is expired' <<<"$out"; then
if [[ ! -e $expired_flag ]]; then
notify-send -a calcurse -u critical -i x-office-calendar "Google Calendar login expired" \
"Run calcurse-caldav in a terminal, allow access in the browser, then calcurse-caldav --authcode '<code>'."
# Prompt via calcurse-relogin, again daily if the prompt was dismissed.
if [[ ! -e $expired_flag || -n $(find "$expired_flag" -mmin +1440) ]]; then
systemctl --user start --no-block calcurse-relogin.service
touch "$expired_flag"
fi
elif grep -q 'Another synchronization instance' <<<"$out"; then