Skip to content

Commit 90ed44e

Browse files
committed
chore: dry and optimize caching
1 parent c6c13e4 commit 90ed44e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scripts/spr.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,14 @@ main() {
9999
sprRemoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON"
100100
fi
101101

102-
if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then
103-
trackStatus "$PAUSE_ICON" "$PLAY_ICON" > "$cache_file"
104-
sliceTrack "$(cat $cache_file)" "$MAX_LENGTH" > "$cache_file"
102+
103+
if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -c%Y "$cache_file" 2>/dev/null || stat -f%m "$cache_file"))) -ge "$RATE" ]; then
104+
local full_track
105+
full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON")
106+
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
105107
fi
106108

107-
cat "$cache_file"
109+
echo "$BACK_BUTTON"
108110
}
109111

110112
main

0 commit comments

Comments
 (0)