non-blocking logic

This commit is contained in:
2026-02-27 20:21:44 -06:00
parent 6a3fae09d0
commit 36a3299976

View File

@@ -43,6 +43,8 @@ do
this_state="$value" this_state="$value"
if [ "$this_state" = "playing" ] && [ "$this_action" = "rungame" ]; then if [ "$this_state" = "playing" ] && [ "$this_action" = "rungame" ]; then
# We wrap the whole operation in ( ) & to background the entire sequence
(
log "INFO" "Game Started: $(basename "$this_game_path")" log "INFO" "Game Started: $(basename "$this_game_path")"
filename=$(basename "$this_save_path") filename=$(basename "$this_save_path")
@@ -55,25 +57,29 @@ do
if [ "$local_size" -lt "$remote_size" ]; then if [ "$local_size" -lt "$remote_size" ]; then
log "WARN" "Cloud save LARGER. Restoring..." log "WARN" "Cloud save LARGER. Restoring..."
mkdir -p "$(dirname "$this_backup_path")" mkdir -p "$(dirname "$this_backup_path")"
# Fixed: backup-dir needs to be a directory
rclone copyto "$remote_full" "$this_save_path" --backup-dir "$(dirname "$this_backup_path")" rclone copyto "$remote_full" "$this_save_path" --backup-dir "$(dirname "$this_backup_path")"
else else
log "INFO" "Local save safe. Updating..." log "INFO" "Local save safe. Updating..."
rclone update "$remote_full" "$this_save_path" rclone update "$remote_full" "$this_save_path"
fi fi
# FIX: Added -m flag # Signal that sync is done
mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" -m "SaveContinue=0" mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" -m "SaveContinue=0"
) &
log "DEBUG" "Sync process backgrounded for Start Game."
elif [ "$this_state" = "endgame" ]; then elif [ "$this_state" = "endgame" ]; then
(
log "INFO" "Game Ended. Syncing..." log "INFO" "Game Ended. Syncing..."
rclone update "$this_save_path" "$REMOTE_BASE/$this_system_id/" rclone update "$this_save_path" "$REMOTE_BASE/$this_system_id/"
log "INFO" "Sync Complete." log "INFO" "Sync Complete."
mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" -m "SaveContinue=0" mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" -m "SaveContinue=0"
) &
log "DEBUG" "Sync process backgrounded for End Game."
fi fi
# Reset variables # Reset variables immediately so the loop is ready for the next line
this_system_id=""; this_game_path=""; this_save_path=""; this_action=""; this_backup_path="" this_system_id=""; this_game_path=""; this_save_path=""; this_action=""; this_backup_path=""
;; ;;
esac esac