-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathcrd-mirror
executable file
·59 lines (49 loc) · 1.91 KB
/
crd-mirror
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
#!/usr/bin/env bash
### Chrome Remote Desktop Mirroring ###
# This script launches Chrome Remote Desktop in mirroring mode, #
# similar to how CRD works on other platforms. Audio is redirected #
# upon client connection. When client disconnects, the audio is #
# redirected back to the main sink. #
# #
# See crd-mirror.service for launching this script as a systemd user service. #
### ###
CRD=/opt/google/chrome-remote-desktop/chrome-remote-desktop
SUMMARY="Chrome Remote Desktop"
test -n ${DISPLAY} || { echo 'DISPLAY environment variable must be set.'; exit 1; }
start() {
${CRD} --check-running && { echo 'Chrome Remote Desktop is already running'; exit 1; }
${CRD} --start --mirror ${DISPLAY}
}
on_connect() {
PULSE_COMMAND=$(grep 'sink_name' ${HOME}/.config/chrome-remote-desktop/pulseaudio*/default.pa)
SINK_NAME=$(echo ${PULSE_COMMAND} | sed -E 's/^.*sink_name=(\w+).*$/\1/')
pacmd ${PULSE_COMMAND}
pacmd set-default-sink ${SINK_NAME}
# for some reason key repeat is disabled when remote session is connected
xset r on
}
on_disconnect() {
pacmd unload-module module-pipe-sink
xdg-screensaver lock
}
_kill() {
${CRD} --stop
}
main() {
trap _kill EXIT
while true; do
test -e ${LOGFILE} || break
LINE=$(grep -E -m1 "Client (dis)?connected" <(tail -f -n0 ${LOGFILE} --pid ${PID}))
MESSAGE=$(echo "${LINE}" | sed -E 's/\[.+\] (Client .+: .+)\/.+/\1/')
notify-send "${SUMMARY}" "${MESSAGE}"
if [[ ${MESSAGE} =~ " connected" ]] ; then
on_connect
elif [[ ${MESSAGE} =~ " disconnected" ]] ; then
on_disconnect
fi
done
}
start
PID=$(pgrep -f chrome-remote-desktop-host)
LOGFILE=/proc/${PID}/fd/1
main