mirror of
https://github.com/kuhyx/scripts.git
synced 2026-07-04 11:43:03 +02:00
Add instant mode for near-instantaneous music app termination
- New 'instant' mode polls every 0.5 seconds (vs 3s for regular mode) - Made instant mode the default for the systemd service - Added youtube-music-wrapper.sh to block launch when focus apps running - YouTube Music killed within 0.5 seconds of opening
This commit is contained in:
parent
16be741bda
commit
a60acd9e68
@ -209,6 +209,32 @@ notify_user() {
|
||||
log_message "$message"
|
||||
}
|
||||
|
||||
# Instant monitoring loop - uses polling at high frequency
|
||||
# This runs every 0.5 seconds for near-instant detection
|
||||
instant_monitor_loop() {
|
||||
log_message "=== Music Parallelism INSTANT Monitor Started ==="
|
||||
log_message "Focus apps monitored: ${FOCUS_APPS[*]}"
|
||||
log_message "Polling every 0.5 seconds for instant kill"
|
||||
|
||||
while true; do
|
||||
# Only check if focus app is running
|
||||
if is_focus_app_running &>/dev/null; then
|
||||
# Instant kill youtube-music if detected
|
||||
if pgrep -f "youtube-music" &>/dev/null; then
|
||||
pkill -9 -f "youtube-music" 2>/dev/null || true
|
||||
log_message "INSTANT KILL: YouTube Music terminated"
|
||||
notify-send -u normal -t 2000 "🎵 YouTube Music killed" "Focus mode active" 2>/dev/null || true
|
||||
fi
|
||||
# Also check other music services
|
||||
if pgrep -x "spotify" &>/dev/null; then
|
||||
pkill -9 -x "spotify" 2>/dev/null || true
|
||||
log_message "INSTANT KILL: Spotify terminated"
|
||||
fi
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
}
|
||||
|
||||
# Main monitoring loop
|
||||
monitor_loop() {
|
||||
log_message "=== Music Parallelism Monitor Started ==="
|
||||
@ -289,7 +315,8 @@ show_usage() {
|
||||
echo "Usage: $0 [command]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " monitor - Start monitoring (default, runs in foreground)"
|
||||
echo " monitor - Start monitoring (default, checks every ${CHECK_INTERVAL}s)"
|
||||
echo " instant - Instant monitoring (checks every 0.5s for immediate kill)"
|
||||
echo " status - Show current status of focus apps and music services"
|
||||
echo " kill - Immediately kill all music services"
|
||||
echo " help - Show this help message"
|
||||
@ -304,10 +331,13 @@ show_usage() {
|
||||
}
|
||||
|
||||
# Main
|
||||
case "${1:-monitor}" in
|
||||
case "${1:-instant}" in
|
||||
monitor | start | run)
|
||||
monitor_loop
|
||||
;;
|
||||
instant | fast)
|
||||
instant_monitor_loop
|
||||
;;
|
||||
status)
|
||||
show_status
|
||||
;;
|
||||
|
||||
@ -5,7 +5,7 @@ Wants=graphical-session.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/music-parallelism.sh monitor
|
||||
ExecStart=/usr/local/bin/music-parallelism.sh instant
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
|
||||
45
scripts/digital_wellbeing/youtube-music-wrapper.sh
Normal file
45
scripts/digital_wellbeing/youtube-music-wrapper.sh
Normal file
@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# YouTube Music Wrapper - Blocks launch when focus apps are running
|
||||
# This replaces the actual youtube-music binary
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REAL_BINARY="/opt/YouTube Music/youtube-music"
|
||||
LOG_FILE="${XDG_STATE_HOME:-$HOME/.local/state}/music-parallelism/music-parallelism.log"
|
||||
|
||||
log_message() {
|
||||
local msg
|
||||
msg="$(date '+%Y-%m-%d %H:%M:%S') - $1"
|
||||
echo "$msg" >&2
|
||||
echo "$msg" >>"$LOG_FILE" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Focus apps that block music
|
||||
FOCUS_APPS=(
|
||||
"code" "Code" "vscodium" "cursor"
|
||||
"jetbrains" "idea" "pycharm" "webstorm" "clion" "rider"
|
||||
"sublime_text" "atom" "neovide"
|
||||
"steam_app" "steamwebhelper" "gamescope"
|
||||
"blender" "godot" "unity" "UnrealEditor"
|
||||
)
|
||||
|
||||
# Check if any focus app is running
|
||||
is_focus_app_running() {
|
||||
for app in "${FOCUS_APPS[@]}"; do
|
||||
if pgrep -i -f "$app" &>/dev/null; then
|
||||
echo "$app"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Main
|
||||
if focus_app=$(is_focus_app_running); then
|
||||
log_message "BLOCKED: YouTube Music launch prevented (focus app: $focus_app)"
|
||||
notify-send -u normal -t 3000 "🚫 YouTube Music Blocked" "Focus mode active ($focus_app)" 2>/dev/null || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# No focus app running, launch normally
|
||||
exec "$REAL_BINARY" "$@"
|
||||
Loading…
Reference in New Issue
Block a user