From 020ad0e51ff5845de9f056fc44e287e73c5e9439 Mon Sep 17 00:00:00 2001 From: icenine451 Date: Wed, 26 Mar 2025 11:47:06 -0400 Subject: [PATCH] Update steam_sync to only run SRM add process if new games were favorited in ES-DE --- functions/global.sh | 1 + functions/steam_sync.sh | 87 +++++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/functions/global.sh b/functions/global.sh index 8948b352..b2420606 100644 --- a/functions/global.sh +++ b/functions/global.sh @@ -262,6 +262,7 @@ fi steamsync_folder="$rdhome/.sync" # Folder containing favorites manifest for SRM retrodeck_favorites_file="$steamsync_folder/retrodeck_favorites.json" # The current SRM manifest of all games that have been favorited in ES-DE srm_log="$logs_folder/srm_log.log" # Log file for capturing the output of the most recent SRM run, for debugging purposes +retrodeck_added_favorites="$steamsync_folder/retrodeck_added_favorites.json" # Temporary manifest of any games that were newly added to the ES-DE favorites and should be added to Steam retrodeck_removed_favorites="$steamsync_folder/retrodeck_removed_favorites.json" # Temporary manifest of any games that were unfavorited in ES-DE and should be removed from Steam export GLOBAL_SOURCED=true diff --git a/functions/steam_sync.sh b/functions/steam_sync.sh index 5a34e290..522fd94f 100644 --- a/functions/steam_sync.sh +++ b/functions/steam_sync.sh @@ -61,12 +61,26 @@ steam_sync() { '[$source[0][] | select(. as $item | ($target[0] | map(. == $item) | any | not))]') fi + if [[ -f "$retrodeck_favorites_file" && -f "${retrodeck_favorites_file}.new" ]]; then + # Look for new favorites added between steam_sync runs, if any + added_items=$(jq -n \ + --slurpfile source "${retrodeck_favorites_file}.new" \ + --slurpfile target "$retrodeck_favorites_file" \ + '[$source[0][] | select(. as $item | ($target[0] | map(. == $item) | any | not))]') + fi + # Check if there are any missing objects if [[ "$(echo "$removed_items" | jq 'length')" -gt 0 ]]; then log d "Some favorites were removed between sync, writing to $retrodeck_removed_favorites" echo "$removed_items" > "$retrodeck_removed_favorites" fi + # Check if any new favorites were added + if [[ "$(echo "$added_items" | jq 'length')" -gt 0 ]]; then + log d "Some new favorites were added between sync, writing to $retrodeck_added_favorites" + echo "$added_items" > "$retrodeck_added_favorites" + fi + # Decide if sync needs to happen if [[ -f "$retrodeck_favorites_file" ]]; then # If an existing favorites manifest exists if [[ ! "$(cat "${retrodeck_favorites_file}.new" | jq 'length')" -gt 0 ]]; then # If all favorites were removed from all gamelists, meaning new manifest is empty @@ -74,9 +88,7 @@ steam_sync() { if [[ "$CONFIGURATOR_GUI" == "zenity" ]]; then ( # Remove old entries - steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 - steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 - steam-rom-manager remove >> "$srm_log" 2>&1 + steam_sync_remove ) | rd_zenity --progress \ --title="Syncing with Steam" \ @@ -85,9 +97,7 @@ steam_sync() { --pulsate --width=500 --height=150 --auto-close --no-cancel else # Remove old entries - steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 - steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 - steam-rom-manager remove >> "$srm_log" 2>&1 + steam_sync_remove fi # Old manifest cleanup rm "$retrodeck_favorites_file" @@ -104,9 +114,7 @@ steam_sync() { mv "$retrodeck_removed_favorites" "$retrodeck_favorites_file" if [[ "$CONFIGURATOR_GUI" == "zenity" ]]; then ( - steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 - steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 - steam-rom-manager remove >> "$srm_log" 2>&1 + steam_sync_remove ) | rd_zenity --progress \ --title="Syncing with Steam" \ @@ -114,32 +122,29 @@ steam_sync() { --text="\t\t\t\tRemoving unfavorited games from Steam\n\nNOTE: This operation may take some time depending on the size of your library.\nFeel free to leave this in the background and switch to another application.\n\n" \ --pulsate --width=500 --height=150 --auto-close --no-cancel else - steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 - steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 - steam-rom-manager remove >> "$srm_log" 2>&1 + steam_sync_remove + fi + fi + if [[ -f "$retrodeck_added_favorites" ]]; then # If some new favorites were added between syncs + log d "Some new favorites added between syncs, adding new favorited games" + # Load added favorites as manifest and run SRM add + mv "$retrodeck_added_favorites" "$retrodeck_favorites_file" + if [[ "$CONFIGURATOR_GUI" == "zenity" ]]; then + ( + steam_sync_add + ) | + rd_zenity --progress \ + --title="Syncing with Steam" \ + --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ + --text="\t\t\t\tAdding new favorited games to Steam\n\nNOTE: This operation may take some time depending on the size of your library.\nFeel free to leave this in the background and switch to another application.\n\n" \ + --pulsate --width=500 --height=150 --auto-close --no-cancel + else + steam_sync_add fi fi - # Load new favorites manifest as games to add during sync + # Make new favorites manifest the current one mv "${retrodeck_favorites_file}.new" "$retrodeck_favorites_file" - - if [[ "$CONFIGURATOR_GUI" == "zenity" ]]; then - ( - # Add new favorites manifest - steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 - steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 - steam-rom-manager add >> "$srm_log" 2>&1 - ) | - rd_zenity --progress \ - --title="Syncing with Steam" \ - --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ - --text="\t\t\t\tSyncing favorite games with Steam\n\nNOTE: This operation may take some time depending on the size of your library.\nFeel free to leave this in the background and switch to another application.\n\n" \ - --pulsate --width=500 --height=150 --auto-close --no-cancel - else - steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 - steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 - steam-rom-manager add >> "$srm_log" 2>&1 - fi fi fi elif [[ "$(cat "${retrodeck_favorites_file}.new" | jq 'length')" -gt 0 ]]; then # No existing favorites manifest was found, so check if new manifest has entries @@ -148,9 +153,7 @@ steam_sync() { if [[ "$CONFIGURATOR_GUI" == "zenity" ]]; then ( # Add new favorites manifest - steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 - steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 - steam-rom-manager add >> "$srm_log" 2>&1 + steam_sync_add ) | rd_zenity --progress \ --title="Syncing with Steam" \ @@ -159,9 +162,19 @@ steam_sync() { --pulsate --width=500 --height=150 --auto-close --no-cancel else # Add new favorites manifest - steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 - steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 - steam-rom-manager add >> "$srm_log" 2>&1 + steam_sync_add fi fi } + +steam_sync_add() { + steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 + steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 + steam-rom-manager add >> "$srm_log" 2>&1 +} + +steam_sync_remove() { + steam-rom-manager disable --names "RetroDECK Launcher" >> "$srm_log" 2>&1 + steam-rom-manager enable --names "RetroDECK Steam Sync" >> "$srm_log" 2>&1 + steam-rom-manager remove >> "$srm_log" 2>&1 +}