#!/usr/bin/env bash
# Check app process + crash logs + events
source "$(cd "$(dirname "$0")/.." && pwd)/scripts/_config.sh"

log "Checking app process..."
pid=$(hdc -t "$DEVICE" shell "ps -ef 2>&1" | grep "$BUNDLE" | grep -v grep | grep -v shell | awk '{print $2}' | head -1)
if [ -n "$pid" ]; then
  echo -e "  ${GREEN}App running${NC}  pid=$pid  bundle=$BUNDLE"
else
  echo -e "  ${RED}App NOT running${NC}"
fi

log "Crash / e2e pipeline events..."
hdc -t "$DEVICE" shell "hilog -x -D 0x0001 2>/dev/null" 2>/dev/null | grep -iE 'crash|fatal|STACKTRACE|SIGSEGV|SIGABRT|onJsException|assert|firstView|FirstContentful|init|loadModule|STATUS|onInitialized|engine|TimeMonitor' | tail -30 || true