Skip to content

Commit b1b2720

Browse files
committed
Refactor audio option handling in start_mpv function for macOS
1 parent 100abec commit b1b2720

File tree

1 file changed

+14
-38
lines changed

1 file changed

+14
-38
lines changed

shelldio.sh

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -88,47 +88,23 @@ fade_in() {
8888
}
8989

9090
start_mpv() {
91-
if [[ -n "$mpv_pid" ]] && kill -0 "$mpv_pid" 2>/dev/null; then
92-
fade_out
93-
kill "$mpv_pid" 2>/dev/null
94-
# Wait up to 3 seconds for process to terminate
95-
for i in {1..30}; do
96-
if ! kill -0 "$mpv_pid" 2>/dev/null; then
97-
break
98-
fi
99-
sleep 0.1
100-
done
101-
# Force kill if still running
102-
if kill -0 "$mpv_pid" 2>/dev/null; then
103-
kill -9 "$mpv_pid" 2>/dev/null
104-
fi
105-
rm -f /tmp/mpv_socket
106-
fi
91+
if [[ -n "$mpv_pid" ]] && kill -0 "$mpv_pid" 2>/dev/null; then
92+
fade_out
93+
kill "$mpv_pid" 2>/dev/null
94+
rm -f /tmp/mpv_socket
95+
fi
10796

108-
mpv --no-video --input-ipc-server=/tmp/mpv_socket --volume=0 "$stathmos_url" &>/dev/null &
109-
mpv_pid=$!
97+
mpv --no-video --input-ipc-server=/tmp/mpv_socket --volume=0 "$stathmos_url" &>/dev/null &
98+
mpv_pid=$!
11099

111-
# Wait for the IPC socket to be ready with loading indicator
112-
for i in {1..40}; do
113-
if [ -S /tmp/mpv_socket ]; then
114-
# Clear the connection message line
115-
printf "\r%*s\r" 50 ""
116-
fade_in
117-
return 0
118-
fi
119-
# Progressive dots animation (1-5 dots cycling)
120-
dots=$((((i - 1) % 5) + 1))
121-
printf "\r%s%*s" "Συνδέεται στον σταθμό$(printf "%*s" $dots "" | tr ' ' '.')" $((5 - dots)) ""
122-
sleep 0.05
123-
done
124-
125-
# Connection failed
126-
echo "Αποτυχία σύνδεσης στον σταθμό"
127-
if kill -0 "$mpv_pid" 2>/dev/null; then
128-
kill -9 "$mpv_pid" 2>/dev/null
100+
# Wait for the IPC socket to be ready (max 2 seconds)
101+
for _ in {1..40}; do
102+
if [ -S /tmp/mpv_socket ]; then
103+
break
129104
fi
130-
mpv_pid=""
131-
return 1
105+
sleep 0.05
106+
done
107+
fade_in
132108
}
133109

134110
get_current_title() {

0 commit comments

Comments
 (0)