Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions skeleton/SYSTEM/desktop/bin/run_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
# run_hooks.sh - shared hook runner for NextUI
# Usage: run_hooks.sh <dir-name> [--sync-only]
#
# dir-name: directory name under $USERDATA_PATH/.hooks/ (e.g. pre-launch.d, boot.d)
# --sync-only: force all scripts to run synchronously
#
# By default, scripts run in the background. Scripts ending in .sync.sh
# always run synchronously. All background scripts are waited on before exit.

DIR_NAME="$1"
SYNC_ONLY="${2:-}"

: "${SDCARD_PATH:=/var/tmp/nextui/sdcard}"
: "${PLATFORM:=desktop}"
: "${USERDATA_PATH:=$SDCARD_PATH/.userdata/$PLATFORM}"

HOOK_DIR="$USERDATA_PATH/.hooks/$DIR_NAME"
[ -d "$HOOK_DIR" ] || exit 0

case "$DIR_NAME" in
pre-*) export HOOK_PHASE="pre" ;;
post-*) export HOOK_PHASE="post" ;;
boot*) export HOOK_PHASE="boot" ;;
esac
export HOOK_CATEGORY="$DIR_NAME"

for script in "$HOOK_DIR"/*.sh; do
[ -f "$script" ] || continue
if [ "$SYNC_ONLY" = "--sync-only" ] || echo "$script" | grep -q '\.sync\.sh$'; then
( "$script" ) > /dev/null 2>&1 || true
else
( "$script" ) > /dev/null 2>&1 &
fi
done
wait
24 changes: 24 additions & 0 deletions skeleton/SYSTEM/desktop/paks/MinUI.pak/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,29 @@ if [ -f "$AUTO_PATH" ]; then
"$AUTO_PATH"
fi

# Composable boot hooks (run after auto.sh for backward compatibility)
"$SYSTEM_PATH/bin/run_hooks.sh" boot.d

cd $(dirname "$0")

#######################################
# Hook system

parse_hook_cmd() {
HOOK_CMD="$1"
HOOK_EMU_PATH=$(echo "$HOOK_CMD" | sed "s/^'\\([^']*\\)'.*/\\1/")
_remainder=$(echo "$HOOK_CMD" | sed "s/^'[^']*'//")
if echo "$_remainder" | grep -q "'"; then
HOOK_TYPE="rom"
HOOK_ROM_PATH=$(echo "$_remainder" | sed "s/.*'\\([^']*\\)'.*/\\1/")
else
HOOK_TYPE="pak"
HOOK_ROM_PATH=""
fi
[ -f /tmp/last.txt ] && HOOK_LAST=$(cat /tmp/last.txt) || HOOK_LAST=""
export HOOK_CMD HOOK_EMU_PATH HOOK_TYPE HOOK_ROM_PATH HOOK_LAST
}

#######################################

EXEC_PATH="/tmp/nextui_exec"
Expand All @@ -57,7 +78,10 @@ touch "$EXEC_PATH" && sync

if [ -f $NEXT_PATH ]; then
CMD=`cat $NEXT_PATH`
parse_hook_cmd "$CMD"
"$SYSTEM_PATH/bin/run_hooks.sh" pre-launch.d
eval $CMD
"$SYSTEM_PATH/bin/run_hooks.sh" post-launch.d
rm -f $NEXT_PATH
fi
#done
36 changes: 36 additions & 0 deletions skeleton/SYSTEM/tg5040/bin/run_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
# run_hooks.sh - shared hook runner for NextUI
# Usage: run_hooks.sh <dir-name> [--sync-only]
#
# dir-name: directory name under $USERDATA_PATH/.hooks/ (e.g. pre-launch.d, boot.d)
# --sync-only: force all scripts to run synchronously
#
# By default, scripts run in the background. Scripts ending in .sync.sh
# always run synchronously. All background scripts are waited on before exit.

DIR_NAME="$1"
SYNC_ONLY="${2:-}"

: "${SDCARD_PATH:=/mnt/SDCARD}"
: "${PLATFORM:=tg5040}"
: "${USERDATA_PATH:=$SDCARD_PATH/.userdata/$PLATFORM}"

HOOK_DIR="$USERDATA_PATH/.hooks/$DIR_NAME"
[ -d "$HOOK_DIR" ] || exit 0

case "$DIR_NAME" in
pre-*) export HOOK_PHASE="pre" ;;
post-*) export HOOK_PHASE="post" ;;
boot*) export HOOK_PHASE="boot" ;;
esac
export HOOK_CATEGORY="$DIR_NAME"

for script in "$HOOK_DIR"/*.sh; do
[ -f "$script" ] || continue
if [ "$SYNC_ONLY" = "--sync-only" ] || echo "$script" | grep -q '\.sync\.sh$'; then
( "$script" ) > /dev/null 2>&1 || true
else
( "$script" ) > /dev/null 2>&1 &
fi
done
wait
7 changes: 7 additions & 0 deletions skeleton/SYSTEM/tg5040/bin/suspend
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ asound_state_dir=/tmp/asound-suspend
before() {
>&2 echo "Preparing for suspend..."

# Run pre-sleep hooks synchronously before services are stopped.
# Subshell ensures a crashing hook cannot block suspend.
( "$SYSTEM_PATH/bin/run_hooks.sh" pre-sleep.d --sync-only ) >/dev/null 2>&1 || true

>&2 echo "Saving mixer state..."
mkdir -p "$asound_state_dir"
alsactl --file "$asound_state_dir/asound.state.pre" store || true
Expand All @@ -36,6 +40,9 @@ before() {
after() {
>&2 echo "Resumed from suspend."

# Run post-resume hooks in background immediately after wake.
( "$SYSTEM_PATH/bin/run_hooks.sh" post-resume.d ) >/dev/null 2>&1 &

if [ -n "$wifid_running" ]; then
>&2 echo "Starting wpa_supplicant..."
/etc/wifi/wifi_init.sh start || true
Expand Down
24 changes: 24 additions & 0 deletions skeleton/SYSTEM/tg5040/paks/MinUI.pak/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,29 @@ if [ -f "$AUTO_PATH" ]; then
"$AUTO_PATH"
fi

# Composable boot hooks (run after auto.sh for backward compatibility)
"$SYSTEM_PATH/bin/run_hooks.sh" boot.d

cd $(dirname "$0")

#######################################
# Hook system

parse_hook_cmd() {
HOOK_CMD="$1"
HOOK_EMU_PATH=$(echo "$HOOK_CMD" | sed "s/^'\\([^']*\\)'.*/\\1/")
_remainder=$(echo "$HOOK_CMD" | sed "s/^'[^']*'//")
if echo "$_remainder" | grep -q "'"; then
HOOK_TYPE="rom"
HOOK_ROM_PATH=$(echo "$_remainder" | sed "s/.*'\\([^']*\\)'.*/\\1/")
else
HOOK_TYPE="pak"
HOOK_ROM_PATH=""
fi
[ -f /tmp/last.txt ] && HOOK_LAST=$(cat /tmp/last.txt) || HOOK_LAST=""
export HOOK_CMD HOOK_EMU_PATH HOOK_TYPE HOOK_ROM_PATH HOOK_LAST
}

#######################################

# kill show2.elf if running
Expand All @@ -167,7 +188,10 @@ while [ -f $EXEC_PATH ]; do

if [ -f $NEXT_PATH ]; then
CMD=`cat $NEXT_PATH`
parse_hook_cmd "$CMD"
"$SYSTEM_PATH/bin/run_hooks.sh" pre-launch.d
eval $CMD
"$SYSTEM_PATH/bin/run_hooks.sh" post-launch.d
rm -f $NEXT_PATH
echo $CPU_SPEED_PERF > $CPU_PATH
fi
Expand Down
36 changes: 36 additions & 0 deletions skeleton/SYSTEM/tg5050/bin/run_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
# run_hooks.sh - shared hook runner for NextUI
# Usage: run_hooks.sh <dir-name> [--sync-only]
#
# dir-name: directory name under $USERDATA_PATH/.hooks/ (e.g. pre-launch.d, boot.d)
# --sync-only: force all scripts to run synchronously
#
# By default, scripts run in the background. Scripts ending in .sync.sh
# always run synchronously. All background scripts are waited on before exit.

DIR_NAME="$1"
SYNC_ONLY="${2:-}"

: "${SDCARD_PATH:=/mnt/SDCARD}"
: "${PLATFORM:=tg5050}"
: "${USERDATA_PATH:=$SDCARD_PATH/.userdata/$PLATFORM}"

HOOK_DIR="$USERDATA_PATH/.hooks/$DIR_NAME"
[ -d "$HOOK_DIR" ] || exit 0

case "$DIR_NAME" in
pre-*) export HOOK_PHASE="pre" ;;
post-*) export HOOK_PHASE="post" ;;
boot*) export HOOK_PHASE="boot" ;;
esac
export HOOK_CATEGORY="$DIR_NAME"

for script in "$HOOK_DIR"/*.sh; do
[ -f "$script" ] || continue
if [ "$SYNC_ONLY" = "--sync-only" ] || echo "$script" | grep -q '\.sync\.sh$'; then
( "$script" ) > /dev/null 2>&1 || true
else
( "$script" ) > /dev/null 2>&1 &
fi
done
wait
7 changes: 7 additions & 0 deletions skeleton/SYSTEM/tg5050/bin/suspend
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ asound_state_dir=/tmp/asound-suspend
before() {
>&2 echo "Preparing for suspend..."

# Run pre-sleep hooks synchronously before services are stopped.
# Subshell ensures a crashing hook cannot block suspend.
( "$SYSTEM_PATH/bin/run_hooks.sh" pre-sleep.d --sync-only ) >/dev/null 2>&1 || true

>&2 echo "Saving mixer state..."
mkdir -p "$asound_state_dir"
alsactl --file "$asound_state_dir/asound.state.pre" store || true
Expand All @@ -36,6 +40,9 @@ before() {
after() {
>&2 echo "Resumed from suspend."

# Run post-resume hooks in background immediately after wake.
( "$SYSTEM_PATH/bin/run_hooks.sh" post-resume.d ) >/dev/null 2>&1 &

if [ -n "$wifid_running" ]; then
>&2 echo "Starting wpa_supplicant..."
$SYSTEM_PATH/etc/wifi/wifi_init.sh start || true
Expand Down
24 changes: 24 additions & 0 deletions skeleton/SYSTEM/tg5050/paks/MinUI.pak/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,29 @@ if [ -f "$AUTO_PATH" ]; then
echo after auto.sh `cat /proc/uptime` >> /tmp/nextui_boottime
fi

# Composable boot hooks (run after auto.sh for backward compatibility)
"$SYSTEM_PATH/bin/run_hooks.sh" boot.d

cd $(dirname "$0")

#######################################
# Hook system

parse_hook_cmd() {
HOOK_CMD="$1"
HOOK_EMU_PATH=$(echo "$HOOK_CMD" | sed "s/^'\\([^']*\\)'.*/\\1/")
_remainder=$(echo "$HOOK_CMD" | sed "s/^'[^']*'//")
if echo "$_remainder" | grep -q "'"; then
HOOK_TYPE="rom"
HOOK_ROM_PATH=$(echo "$_remainder" | sed "s/.*'\\([^']*\\)'.*/\\1/")
else
HOOK_TYPE="pak"
HOOK_ROM_PATH=""
fi
[ -f /tmp/last.txt ] && HOOK_LAST=$(cat /tmp/last.txt) || HOOK_LAST=""
export HOOK_CMD HOOK_EMU_PATH HOOK_TYPE HOOK_ROM_PATH HOOK_LAST
}

#######################################

# kill show2.elf if running
Expand All @@ -180,7 +201,10 @@ while [ -f $EXEC_PATH ]; do

if [ -f $NEXT_PATH ]; then
CMD=`cat $NEXT_PATH`
parse_hook_cmd "$CMD"
"$SYSTEM_PATH/bin/run_hooks.sh" pre-launch.d
eval $CMD
"$SYSTEM_PATH/bin/run_hooks.sh" post-launch.d
rm -f $NEXT_PATH
echo $CPU_SPEED_PERF > $BIG_PATH
fi
Expand Down
Loading