Files
MicroPythonOS/scripts/run_desktop.sh
T

61 lines
2.0 KiB
Bash
Raw Normal View History

2026-03-11 21:26:56 +01:00
#!/bin/bash
2026-03-11 21:40:06 +01:00
scriptdir=$(cd "$(dirname "$0")" && pwd -P)
2025-10-09 19:14:44 +02:00
script="$1"
if [ -f "$script" ]; then
2026-03-11 21:40:06 +01:00
script="$(cd "$(dirname "$script")" && pwd -P)/$(basename "$script")"
2025-10-09 19:14:44 +02:00
fi
echo "Usage:"
echo "$0 # with no arguments just starts it up normally"
echo "$0 scriptfile.py # doesn't initialize anything, just runs scriptfile.py directly"
echo "$0 appname # starts the app by appname, for example: com.example.helloworld"
#export SDL_WINDOW_FULLSCREEN=true
2025-11-07 10:51:00 +01:00
export HEAPSIZE=8M # default, same a PSRAM on many ESP32-S3 boards
2026-01-26 20:11:19 +01:00
#export HEAPSIZE=64M # fine for fullscreen 1280x720 slides
2025-10-09 19:14:44 +02:00
2025-10-20 23:23:51 +02:00
os_name=$(uname -s)
2025-10-24 17:02:20 +02:00
if [ "$os_name" = "Darwin" ]; then
2025-10-20 23:23:51 +02:00
echo "Running on macOS"
2025-10-24 17:02:20 +02:00
binary="$scriptdir"/../lvgl_micropython/build/lvgl_micropy_macOS
2025-10-20 23:23:51 +02:00
else
echo "Running on $os_name"
2025-10-24 17:02:20 +02:00
binary="$scriptdir"/../lvgl_micropython/build/lvgl_micropy_unix
2025-10-20 23:23:51 +02:00
fi
2026-03-11 21:40:06 +01:00
binary="$(cd "$(dirname "$binary")" && pwd -P)/$(basename "$binary")"
2025-10-10 12:46:53 +02:00
chmod +x "$binary"
2025-12-23 22:27:28 +01:00
pushd "$scriptdir"/../internal_filesystem/
2025-12-11 21:27:38 +01:00
if [ -f "$script" ]; then
echo "Running script $script"
2026-03-11 21:40:06 +01:00
"$binary" -v -i "$script"
2025-12-11 21:27:38 +01:00
else
2026-03-11 21:26:56 +01:00
CONFIG_FILE="data/com.micropythonos.settings/config.json"
2026-03-11 21:40:06 +01:00
if [ -n "$script" ]; then
2026-03-11 21:26:56 +01:00
echo "run_desktop.sh: running app $script"
if [ -f "$CONFIG_FILE" ]; then
2026-03-11 21:26:56 +01:00
if grep -q '"auto_start_app"' "$CONFIG_FILE"; then
echo "Updating auto_start_app field using sed"
sed -i.backup -e 's/"auto_start_app": ".*"/"auto_start_app": "'$script'"/' "$CONFIG_FILE"
else
echo "Adding auto_start_app to config file"
sed -i.backup -E 's/[[:space:]]*}[[:space:]]*$/,"auto_start_app": "'$script'"}/' "$CONFIG_FILE"
fi
else
2026-03-11 21:40:06 +01:00
mkdir -p "$(dirname "$CONFIG_FILE")"
echo '{"auto_start_app": "'$script'"}' > "$CONFIG_FILE"
fi
2026-03-11 21:26:56 +01:00
else
if [ -f "$CONFIG_FILE" ]; then
echo "Removing auto_start_app from config file"
sed -i.backup -E 's/[[:space:]]*,?[[:space:]]*"auto_start_app"[[:space:]]*:[[:space:]]*"[^"]*"[[:space:]]*//g; s/\{[[:space:]]*,/\{/g; s/,[[:space:]]*\}/\}/g' "$CONFIG_FILE"
fi
fi
2026-03-11 21:40:06 +01:00
"$binary" -X heapsize=$HEAPSIZE -v -i -c "$(cat main.py)"
2025-12-11 21:27:38 +01:00
fi
2025-10-09 19:14:44 +02:00
popd