revised image asset structure

This commit is contained in:
Mikkeli Matlock
2026-01-25 23:13:30 +09:00
parent d7a1f2fabd
commit b1e23fdd10
16 changed files with 92 additions and 169 deletions

View File

@@ -71,14 +71,6 @@ def build(clean: bool = False) -> bool:
os.chdir(UI_DIR)
# Prepare assets (fonts, images)
prepare_script = SCRIPT_DIR / "prepare_assets.sh"
if prepare_script.exists():
print("Preparing assets...")
run(["bash", str(prepare_script)])
else:
print(f"WARNING: {prepare_script} not found")
# Initialize elinux project if needed
elinux_dir = UI_DIR / "elinux"
if not elinux_dir.exists():

View File

@@ -36,15 +36,6 @@ echo "Cross-compiler: $CXX"
cd "$UI_DIR"
# Prepare assets (fonts, images)
PREPARE_SCRIPT="$SCRIPT_DIR/prepare_assets.sh"
if [ -x "$PREPARE_SCRIPT" ]; then
echo "Preparing assets..."
"$PREPARE_SCRIPT"
else
echo "WARNING: $PREPARE_SCRIPT not found or not executable"
fi
# Initialize elinux project if not already configured
if [ ! -d "elinux" ]; then
echo "Initializing elinux project structure..."

View File

@@ -17,6 +17,7 @@ PROJECT_ROOT = SCRIPT_DIR.parent
CONFIG_FILE = SCRIPT_DIR / "deploy_target.json"
BUILD_DIR = PROJECT_ROOT / "pi" / "ui" / "build" / "elinux" / "arm64" / "release" / "bundle"
CONFIG_SRC = PROJECT_ROOT / "pi" / "ui" / "config.json"
IMAGES_SRC = PROJECT_ROOT / "extra" / "images"
def run(cmd: list[str], check: bool = True, **kwargs) -> subprocess.CompletedProcess:
@@ -77,6 +78,20 @@ def deploy(restart: bool = False) -> bool:
print()
print("Note: No config.json found, using defaults")
# Sync images to assets path
if IMAGES_SRC.exists():
assets_path = config.get("assets_path", f"{remote_path}/assets")
print()
print(f"Syncing images to {assets_path}...")
run([
"rsync", "-avz",
f"{IMAGES_SRC}/",
f"{ssh_target}:{assets_path}/",
])
else:
print()
print("Note: No extra/images folder found, skipping image sync")
# Restart service if requested
if restart:
print()

View File

@@ -28,6 +28,7 @@ SERVICE_NAME=$(read_json service_name)
SSH_TARGET="$PI_USER@$PI_HOST"
BUILD_DIR="$PROJECT_ROOT/pi/ui/build/elinux/arm64/release/bundle"
CONFIG_SRC="$PROJECT_ROOT/pi/ui/config.json"
IMAGES_SRC="$PROJECT_ROOT/extra/images"
echo "=== Smart Serow Deploy ==="
echo "Target: $SSH_TARGET:$REMOTE_PATH"
@@ -55,6 +56,18 @@ else
echo "Note: No config.json found, using defaults"
fi
# Sync images to assets path
if [ -d "$IMAGES_SRC" ]; then
# Read assets_path from config, fall back to default
ASSETS_PATH=$(python3 -c "import json; print(json.load(open('$CONFIG_FILE')).get('assets_path', '$REMOTE_PATH/assets'))" 2>/dev/null || echo "$REMOTE_PATH/assets")
echo ""
echo "Syncing images to $ASSETS_PATH..."
rsync -avz "$IMAGES_SRC/" "$SSH_TARGET:$ASSETS_PATH/"
else
echo ""
echo "Note: No extra/images folder found, skipping image sync"
fi
# Restart service if requested
RESTART="${1:-}"
if [ "$RESTART" = "--restart" ] || [ "$RESTART" = "-r" ]; then

View File

@@ -2,5 +2,6 @@
"user": "pi",
"host": "raspberrypi.local",
"remote_path": "/opt/smartserow",
"service_name": "smartserow-ui"
"service_name": "smartserow-ui",
"assets_path": "~/smartserow-ui/assets"
}

View File

@@ -1,109 +0,0 @@
#!/bin/bash
# prepare_assets.sh - Prepares fonts and images for Flutter build
# Run this before 'flutter build' to ensure assets are in place
#
# This script handles:
# - DIN1451 font: symlinks from extra/ if present, otherwise downloads Noto Sans as fallback
# - Dashboard image: symlinks from extra/ if present, otherwise skipped (handled at runtime)
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
UI_DIR="$PROJECT_ROOT/pi/ui"
FONTS_DIR="$UI_DIR/fonts"
IMAGES_DIR="$UI_DIR/assets/images"
EXTRA_FONTS="$PROJECT_ROOT/extra/fonts"
EXTRA_IMAGES="$PROJECT_ROOT/extra/images"
# Noto Sans download URLs (Google Fonts)
NOTO_SANS_BASE="https://github.com/googlefonts/noto-fonts/raw/main/hinted/ttf/NotoSans"
NOTO_REGULAR="$NOTO_SANS_BASE/NotoSans-Regular.ttf"
NOTO_BOLD="$NOTO_SANS_BASE/NotoSans-Bold.ttf"
NOTO_LIGHT="$NOTO_SANS_BASE/NotoSans-Light.ttf"
echo "=== Smart Serow Asset Preparation ==="
# --- FONTS ---
echo ""
echo "--- Fonts ---"
# Ensure Noto Sans fallbacks exist
download_noto() {
local weight=$1
local url=$2
local dest="$FONTS_DIR/NotoSans-${weight}.ttf"
if [ ! -f "$dest" ]; then
echo "Downloading Noto Sans $weight..."
curl -sL "$url" -o "$dest" || {
echo "Warning: Failed to download Noto Sans $weight"
return 1
}
echo " -> Downloaded $dest"
else
echo " Noto Sans $weight already present"
fi
}
download_noto "Regular" "$NOTO_REGULAR"
download_noto "Bold" "$NOTO_BOLD"
download_noto "Light" "$NOTO_LIGHT"
# DIN1451 - symlink if available, otherwise use Noto Sans
DIN_TARGET="$FONTS_DIR/din1451alt.ttf"
DIN_SOURCE="$EXTRA_FONTS/din1451alt.ttf"
# Remove old symlink/file to ensure fresh state
rm -f "$DIN_TARGET"
if [ -f "$DIN_SOURCE" ]; then
echo "DIN1451 found - linking/copying"
# Try symlink first, fall back to copy (Windows compatibility)
if ln -s "$DIN_SOURCE" "$DIN_TARGET" 2>/dev/null; then
echo " -> Linked $DIN_TARGET -> $DIN_SOURCE"
else
cp "$DIN_SOURCE" "$DIN_TARGET"
echo " -> Copied $DIN_TARGET (symlinks not supported)"
fi
else
echo "DIN1451 not found - using Noto Sans as fallback"
if [ -f "$FONTS_DIR/NotoSans-Regular.ttf" ]; then
cp "$FONTS_DIR/NotoSans-Regular.ttf" "$DIN_TARGET"
echo " -> Copied Noto Sans Regular as $DIN_TARGET"
else
echo " ERROR: No fallback font available!"
exit 1
fi
fi
# --- IMAGES ---
echo ""
echo "--- Images ---"
REI_TARGET="$IMAGES_DIR/rei_default.png"
REI_SOURCE="$EXTRA_IMAGES/rei_default.png"
# Remove old symlink/file
rm -f "$REI_TARGET"
if [ -f "$REI_SOURCE" ]; then
echo "Dashboard image found - linking/copying"
# Try symlink first, fall back to copy (Windows compatibility)
if ln -s "$REI_SOURCE" "$REI_TARGET" 2>/dev/null; then
echo " -> Linked $REI_TARGET -> $REI_SOURCE"
else
cp "$REI_SOURCE" "$REI_TARGET"
echo " -> Copied $REI_TARGET (symlinks not supported)"
fi
else
echo "Dashboard image not found - will use empty fallback at runtime"
# Create a tiny transparent PNG placeholder (1x1 pixel)
# This avoids asset not found errors while keeping the build clean
printf '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\nIDATx\x9cc\x00\x01\x00\x00\x05\x00\x01\r\n-\xb4\x00\x00\x00\x00IEND\xaeB`\x82' > "$REI_TARGET"
echo " -> Created 1x1 transparent placeholder"
fi
echo ""
echo "=== Asset preparation complete ==="
echo "You can now run: flutter build linux"