From a9c214523088be3231ed3393a149a041c70760b7 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Thu, 28 Nov 2024 13:54:23 +0900 Subject: [PATCH] FRAMEWORK: getting user info at startup --- functions/framework.sh | 30 ++++++++++++++++++++++++++++++ functions/other_functions.sh | 1 + 2 files changed, 31 insertions(+) diff --git a/functions/framework.sh b/functions/framework.sh index 08e736f3..fdda1be8 100644 --- a/functions/framework.sh +++ b/functions/framework.sh @@ -513,3 +513,33 @@ do fi done < "$1" } + +get_steam_user() { + # This function populates environment variables with the actual logged Steam user data + if [ -f "$HOME/.steam/steam/config/loginusers.vdf" ]; then + # Extract the Steam ID of the most recent user + export steam_id=$(awk ' + /"users"/ {flag=1} + flag && /^[ \t]*"[0-9]+"/ {id=$1} + flag && /"MostRecent".*"1"/ {print id; exit}' "$HOME/.steam/steam/config/loginusers.vdf" | tr -d '"') + + # Extract the Steam username (AccountName) + export steam_username=$(awk -v steam_id="$steam_id" ' + $0 ~ steam_id {flag=1} + flag && /"AccountName"/ {gsub(/"/, "", $2); print $2; exit}' "$HOME/.steam/steam/config/loginusers.vdf") + + # Extract the Steam pretty name (PersonaName) + export steam_prettyname=$(awk -v steam_id="$steam_id" ' + $0 ~ steam_id {flag=1} + flag && /"PersonaName"/ {gsub(/"/, "", $2); print $2; exit}' "$HOME/.steam/steam/config/loginusers.vdf") + + # Log success + log i "Steam user found:" + log i "SteamID:\t$steam_id" + log i "Username:\t$steam_username" + log i "Name:\t\t$steam_prettyname" + else + # Log warning if file not found + log w "No Steam user found, proceeding" >&2 + fi +} diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 40b6e3e4..f249d8d8 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -936,6 +936,7 @@ quit_retrodeck() { } start_retrodeck() { + get_steam_user # get steam user info splash_screen # Check if today has a surprise splashscreen and load it if so ponzu log i "Starting RetroDECK v$version"