-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathspotify-bin
executable file
·60 lines (51 loc) · 2.07 KB
/
spotify-bin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
SCALE_FACTOR=$(get-scale-factor.py)
WAYLAND_SOCKET=${WAYLAND_DISPLAY:-"wayland-0"}
function openuri {
# Spotify doesn't properly support single instance or even just opening URIs itself so lets hack around it:
# If a URI is passed we will try to activate an existing instance over MPRIS.
for arg in "$@"; do
if [ "${arg:0:8}" = "spotify:" ]; then
echo "Attempting to open $arg in existing instance..."
if gdbus call -e -d org.mpris.MediaPlayer2.spotify -o /org/mpris/MediaPlayer2 -m org.mpris.MediaPlayer2.Player.OpenUri "$arg" > /dev/null 2> /dev/null; then
return 0
else
return 1
fi
fi
done
return 2
}
function waitandopenuri {
if ! gdbus wait -e -t 5 org.mpris.MediaPlayer2.spotify; then
echo "Failed to open URI, MPRIS never appeared."
else
openuri "$@"
fi
}
# Create a "spotify" directory in $XDG_CONFIG_HOME.
# This works around an app bug where proxy settings don't persist when
# launching the app for the first time. See issue #280 for more context.
mkdir -p "${XDG_CONFIG_HOME}/spotify"
openuri "$@"
URI_HANDLED=$?
# If URI_HANDLED = 0, We raised an existing instance.
# If URI_HANDLED = 1, We found a URI but no existing instance.
# In this case we make an instance and then open the URI again...
# If URI_HANDLED = 2, No URI.
# (Forgive terrible shell usage)
if [ $URI_HANDLED -eq 0 ]; then
exit 0
fi
if [ -f "${XDG_CONFIG_HOME}/spotify-flags.conf" ]; then
mapfile -t EXTRA_FLAGS <<< "$(grep -v '^#' "${XDG_CONFIG_HOME}/spotify-flags.conf")"
fi
if [[ -e "${XDG_RUNTIME_DIR}/${WAYLAND_SOCKET}" || -e "${WAYLAND_DISPLAY}" ]]; then
EXTRA_FLAGS+=("--enable-wayland-ime" "--ozone-platform-hint=auto")
elif [ "${SCALE_FACTOR}" != "1.0" ]; then
EXTRA_FLAGS+=("--force-device-scale-factor=${SCALE_FACTOR}")
fi
env PULSE_PROP_application.icon_name="com.spotify.Client" LD_PRELOAD=/app/lib/spotify-preload.so${LD_PRELOAD:+:$LD_PRELOAD} /app/extra/bin/spotify "${EXTRA_FLAGS[@]}" "$@" &
if [ $URI_HANDLED -eq 1 ]; then
waitandopenuri "$@"
fi