#!/bin/bash # Run File Browser Demo Script # This script starts both the mock server and the WASM demo set -e echo "๐ŸŽฏ File Browser Demo Launcher" echo "==============================" echo "" # Function to cleanup background processes cleanup() { echo "" echo "๐Ÿงน Cleaning up..." if [ ! -z "$MOCK_SERVER_PID" ]; then kill $MOCK_SERVER_PID 2>/dev/null || true echo "โœ… Mock server stopped" fi if [ ! -z "$TRUNK_PID" ]; then kill $TRUNK_PID 2>/dev/null || true echo "โœ… Trunk dev server stopped" fi exit 0 } # Set up signal handlers trap cleanup SIGINT SIGTERM # Check dependencies echo "๐Ÿ” Checking dependencies..." if ! command -v cargo &> /dev/null; then echo "โŒ Error: Rust/Cargo is not installed" echo "Please install Rust from https://rustup.rs/" exit 1 fi if ! command -v trunk &> /dev/null; then echo "โŒ Error: Trunk is not installed" echo "Please install Trunk: cargo install trunk" exit 1 fi echo "โœ… Dependencies OK" echo "" # Start mock server in background echo "๐Ÿš€ Starting mock server..." cd "$(dirname "$0")/mock-server" cargo build --release cargo run --release & MOCK_SERVER_PID=$! cd .. # Wait a moment for server to start sleep 2 # Check if mock server is running if ! curl -s http://localhost:3001/health > /dev/null; then echo "โŒ Error: Mock server failed to start" cleanup exit 1 fi echo "โœ… Mock server running on http://localhost:3001" echo "" # Start trunk dev server echo "๐ŸŒ Starting WASM demo..." echo "Building and serving on http://localhost:8080" echo "" echo "๐Ÿ“‹ Demo Features:" echo " โ€ข File/directory listing with navigation" echo " โ€ข Create new directories" echo " โ€ข Upload files with progress tracking" echo " โ€ข Download files" echo " โ€ข Delete files and directories" echo " โ€ข Responsive Bootstrap UI" echo "" echo "๐Ÿ’ก Use Ctrl+C to stop both servers" echo "" trunk serve --port 8080 & TRUNK_PID=$! # Wait for trunk to start sleep 3 # Open browser (optional) if command -v open &> /dev/null; then echo "๐ŸŒ Opening browser..." open http://localhost:8080 elif command -v xdg-open &> /dev/null; then echo "๐ŸŒ Opening browser..." xdg-open http://localhost:8080 fi echo "" echo "๐ŸŽ‰ Demo is ready!" echo " ๐Ÿ“ฑ Frontend: http://localhost:8080" echo " ๐Ÿ”ง Backend: http://localhost:3001" echo "" echo "Press Ctrl+C to stop all servers" # Wait for user to stop wait