Skip to content
Merged
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
73 changes: 73 additions & 0 deletions spruce/scripts/helperFunctions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1011,3 +1011,76 @@ enable_or_disable_wifi() {
log_message "WiFi turned on"
fi
}

get_current_app() {
if [ -f /tmp/cmd_to_run.sh ]; then
sed 's/[[:space:]]*$//' /tmp/cmd_to_run.sh
else
printf 'PyUI\n'
fi
}

extract_entry_name() {
cmd="$1"

case "$cmd" in
*emu/standard_launch.sh*)
# Get last quoted argument
last_arg=$(printf '%s\n' "$cmd" \
| sed -n 's/.*"\([^"]*\)"/\1/p' \
| tail -n 1)
# Extract everything after the last "Roms/"
if echo "$last_arg" | grep -q "Roms/"; then
rom_path=$(printf '%s\n' "$last_arg" | sed 's/.*\(Roms\/.*\)/\1/')
# Remove any trailing quote
rom_path="${rom_path%\"}"
printf '%s\n' "$rom_path"
else
printf '%s\n' "${last_arg##*/}"
fi
;;
*App/*)
# Extract everything after the LAST "App/" including subfolders and file
app_path=$(printf '%s\n' "$cmd" \
| sed -n 's/.*\(App\/.*\)/\1/p' \
| tail -n 1)
# Remove any trailing quote
app_path="${app_path%\"}"
printf '%s\n' "$app_path"
;;
*)
printf '%s\n' "$cmd"
;;
esac
}


log_activity_event() {
app="$1"
event="$2"

[ -z "$app" ] && return 1
[ -z "$event" ] && return 1

ts="$(date +%s)"
pid="$$"

LOG_DIR="/mnt/SDCARD/Saves/spruce"
LOG_FILE="$LOG_DIR/activity.jsonl"

mkdir -p "$LOG_DIR" || return 1

name=$(extract_entry_name "$app")

safe_app=$(printf '%s' "$name" | sed '
s/\\/\\\\/g
s/"/\\"/g
s/\t/\\t/g
s/\r/\\r/g
s/\n/\\n/g
')

printf '{"ts":%s,"event":"%s","app":"%s","pid":%s}\n' \
"$ts" "$event" "$safe_app" "$pid" >> "$LOG_FILE"
}

2 changes: 1 addition & 1 deletion spruce/scripts/platform/device_functions/SmartProS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ device_exit_sleep(){
sleep 10
restore_cores_online
) &
echo 0 > $WAKE_ALARM_PATH
clear_wake_alarm $WAKE_ALARM_PATH
}


Expand Down
5 changes: 5 additions & 0 deletions spruce/scripts/platform/device_functions/trimui_a133p.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ device_enter_sleep() {
trigger_device_sleep
}


device_exit_sleep(){
clear_wake_alarm $WAKE_ALARM_PATH
}

get_current_volume() {
amixer get 'Soft Volume Master' | sed -n 's/.*Front Left: *\([0-9]*\).*/\1/p' | tr -d '[]%'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ set_wake_alarm() {
return 0
}

clear_wake_alarm() {
WAKE_ALARM_PATH="$1"

if [ -e "$WAKE_ALARM_PATH" ]; then
echo 0 > "$WAKE_ALARM_PATH"
log_message "clear_wake_alarm: Wakealarm cleared"
fi
}

device_woke_via_timer() {
[ ! -f "$SLEEP_TIMER_FILE" ] && {
echo "false"
Expand Down
7 changes: 6 additions & 1 deletion spruce/scripts/principal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ while [ 1 ]; do

prepare_for_pyui_launch

log_activity_event "PyUI" "START"
/mnt/SDCARD/App/PyUI/launch.sh
log_activity_event "PyUI" "STOP"

post_pyui_exit

Expand All @@ -58,6 +60,8 @@ while [ 1 ]; do
# This section handles what becomes of that temp file.
if [ -f /tmp/cmd_to_run.sh ]; then

cmd="$(sed 's/[[:space:]]*$//' /tmp/cmd_to_run.sh)"
log_activity_event "$cmd" "START"
set_performance # lead with this to speed up launching

udpbcast -f /tmp/host_msg 2>/dev/null &
Expand All @@ -73,6 +77,7 @@ while [ 1 ]; do
killall -9 udpbcast 2>/dev/null

set_smart
log_activity_event "$cmd" "STOP"
fi

if flag_check "tmp_update_repair_attempted"; then
Expand All @@ -85,4 +90,4 @@ while [ 1 ]; do
/mnt/SDCARD/spruce/scripts/networkservices.sh &
fi

done
done
2 changes: 2 additions & 0 deletions spruce/scripts/save_poweroff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
. /mnt/SDCARD/spruce/scripts/helperFunctions.sh
. /mnt/SDCARD/spruce/scripts/network/syncthingFunctions.sh

current_app="$(get_current_app)"
log_activity_event "$current_app" "STOP"

# kill principal and runtime first so no new app / MainUI will be loaded anymore
killall -q -15 runtime.sh
Expand Down
6 changes: 6 additions & 0 deletions spruce/scripts/sleep_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ if [ -e /tmp/sleep_helper_started ]; then
exit 0
fi

current_app="$(get_current_app)"
log_activity_event "$current_app" "STOP"


log_message "Sleep helper starting up..."
rm -f /tmp/power_pressed_flag

Expand Down Expand Up @@ -162,6 +166,8 @@ trigger_sleep

device_exit_sleep

log_activity_event "$current_app" "START"

# Restore volume
VOLUME_LV=$(jq -r '.vol' "$SYSTEM_JSON")
set_volume "$VOLUME_LV"
Expand Down