♻️ refactor(cache-stats)!: refactor the wakatime and music stats modules

Modules now spawn the scripts automatically at startup and kill them at exit. Both stats are handled by a single script and a lockfile is used to avoid multiple instances spawning.

BREAKING CHANGE: Please remove any user services previously used to spawn scripts.
This commit is contained in:
2024-08-08 22:40:00 -04:00
parent e28783da1f
commit 0c50bcd14b
6 changed files with 128 additions and 21 deletions
+37
View File
@@ -0,0 +1,37 @@
#!/bin/bash
# Separator variable
separator="␟"
# Lock file path
lock_file="/tmp/music_wakatime_update.lock"
# Create a lock file to ensure only one instance of the script runs
if [[ -e $lock_file ]]; then
echo "Another instance of this script is already running."
exit 1
else
# Create the lock file
touch "$lock_file"
fi
# Function to clean up lock file on exit
cleanup() {
rm -f "$lock_file"
}
trap cleanup EXIT
# Update the music cache file every second
while true; do
playerctl --ignore-player firefox,kdeconnect,haruna,plasma-browser-integration metadata --format "{{ artist }}${separator}{{ title }}${separator}{{ album }}${separator}{{ status }}${separator}{{ volume }}${separator}{{ loop }}${separator}{{ shuffle }}" >~/.cache/music_cache.txt
sleep 1
done & # Run this loop in the background
# Update the Wakatime cache file every 60 seconds
while true; do
~/.wakatime/wakatime-cli --today >~/.cache/wakatime_cache.txt 2>/dev/null
sleep 60
done & # Run this loop in the background
# Wait for all background processes to finish
wait
-9
View File
@@ -1,9 +0,0 @@
#!/bin/bash
# Separator variable
separator="␟"
# Update the cache file every second
while true; do
playerctl --ignore-player firefox,kdeconnect,haruna,plasma-browser-integration metadata --format "{{ artist }}${separator}{{ title }}${separator}{{ album }}${separator}{{ status }}${separator}{{ volume }}${separator}{{ loop }}${separator}{{ shuffle }}" >~/.cache/music_cache.txt
sleep 1
done
-7
View File
@@ -1,7 +0,0 @@
#!/bin/bash
# Update the cache file with the Wakatime CLI command
while true; do
~/.wakatime/wakatime-cli --today >~/.cache/wakatime_cache.txt 2>/dev/null
sleep 60
done