From 8ffed3a16463e023f07864f5c3518ab7a17416dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 24 Nov 2025 01:13:56 +0300 Subject: [PATCH] feat: :spark: song_detail automatically switches to latest --- .config/hypr/hyprland.conf | 2 +- .config/mimeapps.list | 8 ++-- .config/qt6ct/qt6ct.conf | 2 +- .config/scripts/shared/song_detail.sh | 65 ++++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/.config/hypr/hyprland.conf b/.config/hypr/hyprland.conf index 18237e5..9b72bc1 100644 --- a/.config/hypr/hyprland.conf +++ b/.config/hypr/hyprland.conf @@ -47,7 +47,7 @@ $power_menu = bash ~/.config/scripts/system/power_menu.sh $browser = flatpak run io.github.ungoogled_software.ungoogled_chromium --enable-features=MiddleClickAutoscroll $browser_unsafe = mullvad-exclude flatpak run com.brave.Browser --incognito --enable-features=MiddleClickAutoscroll $signal = flatpak run org.signal.Signal -$deezer = flatpak run app.zen_browser.zen +$deezer = mullvad-exclude flatpak run app.zen_browser.zen $mainMod = SUPER $my_trigger = Alt diff --git a/.config/mimeapps.list b/.config/mimeapps.list index a42f76c..6804d5a 100644 --- a/.config/mimeapps.list +++ b/.config/mimeapps.list @@ -1,5 +1,5 @@ - [Default Applications] -image=org.gnome.Loupe.desktop -image/jpeg=org.gnome.Loupe.desktop -image/png=org.gnome.Loupe.desktop +video/mp4=org.gnome.Showtime.desktop + +[Added Associations] +video/mp4=org.gnome.Showtime.desktop; diff --git a/.config/qt6ct/qt6ct.conf b/.config/qt6ct/qt6ct.conf index 8ab5ca2..da14c2f 100644 --- a/.config/qt6ct/qt6ct.conf +++ b/.config/qt6ct/qt6ct.conf @@ -24,7 +24,7 @@ underline_shortcut=1 wheel_scroll_lines=3 [SettingsWindow] -geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x3\0\0\0\0\0\0\0\0\0\0\0\0\x3\xae\0\0\x3\xfd\0\0\0\0\0\0\0\0\0\0\x3\xae\0\0\x3\xfd\0\0\0\0\x2\0\0\0\a\x80\0\0\0\0\0\0\0\0\0\0\x3\xae\0\0\x3\xfd) +geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x3\0\0\0\0\0\0\0\0\0\0\0\0\ag\0\0\x3\xfd\0\0\0\0\0\0\0\0\0\0\ag\0\0\x3\xfd\0\0\0\0\x2\0\0\0\a\x80\0\0\0\0\0\0\0\0\0\0\ag\0\0\x3\xfd) [Troubleshooting] force_raster_widgets=1 diff --git a/.config/scripts/shared/song_detail.sh b/.config/scripts/shared/song_detail.sh index 4880ff8..e5b0a0f 100755 --- a/.config/scripts/shared/song_detail.sh +++ b/.config/scripts/shared/song_detail.sh @@ -1,15 +1,66 @@ #!/bin/bash -# Get current playing song from playerctl +# Get current playing song from playerctl, prioritizing the most recently active player + if command -v playerctl &> /dev/null; then # Check if any player is running if playerctl status &> /dev/null; then - status=$(playerctl status 2>/dev/null) - artist=$(playerctl metadata artist 2>/dev/null) - title=$(playerctl metadata title 2>/dev/null) - duration_us=$(playerctl metadata mpris:length 2>/dev/null) + # Get list of all players and find the one with most recent activity + player_list=$(playerctl -l 2>/dev/null) + + if [[ -z "$player_list" ]]; then + echo "" + exit 0 + fi + + # Track which player has the most recent activity + most_recent_player="" + most_recent_time=0 + + while IFS= read -r player; do + player_status=$(playerctl -p "$player" status 2>/dev/null) + + # Only consider players that are Playing or Paused + if [[ "$player_status" == "Playing" ]] || [[ "$player_status" == "Paused" ]]; then + # Get the last activity time for this player + activity_cache="/tmp/playerctl_activity_${player}" + + if [[ "$player_status" == "Playing" ]]; then + # Update timestamp for playing player + current_time=$(date +%s) + echo "$current_time" > "$activity_cache" + most_recent_time=$current_time + most_recent_player="$player" + elif [[ -f "$activity_cache" ]]; then + # Check if paused player has a recent activity timestamp + activity_time=$(cat "$activity_cache") + if [[ $activity_time -gt $most_recent_time ]]; then + most_recent_time=$activity_time + most_recent_player="$player" + fi + fi + fi + done <<< "$player_list" + + # If no active player found, exit + if [[ -z "$most_recent_player" ]]; then + echo "" + exit 0 + fi + + status=$(playerctl -p "$most_recent_player" status 2>/dev/null) + + # Exit if media is stopped + if [[ "$status" == "Stopped" ]]; then + echo "" + exit 0 + fi + + artist=$(playerctl -p "$most_recent_player" metadata artist 2>/dev/null) + title=$(playerctl -p "$most_recent_player" metadata title 2>/dev/null) + duration_us=$(playerctl -p "$most_recent_player" metadata mpris:length 2>/dev/null) # Define cache file for paused position - POSITION_CACHE="/tmp/playerctl_position_cache" + POSITION_CACHE="/tmp/playerctl_position_cache_${most_recent_player}" # Set icon based on playback status if [[ "$status" == "Playing" ]]; then @@ -30,7 +81,7 @@ if command -v playerctl &> /dev/null; then # Get current position with caching logic position="" - position_us=$(playerctl position 2>/dev/null) + position_us=$(playerctl -p "$most_recent_player" position 2>/dev/null) if [[ "$status" == "Playing" ]]; then # When playing, get live position and cache it