Give each web app its own MPRIS player name
Browse files at this commit30989a88e6199e22de79b9d3713cc40af0a59057Parent: 459b67d- fix
- give each web app its own MPRIS player name
1 changed file +9 -7
.config/scripts/shared/webapp.shmodified+9 -7
| @@ -31,14 +31,16 @@ HOST="${URL#*://}" | |||
| 31 | HOST="${HOST%%/*}" | 31 | HOST="${HOST%%/*}" |
| 32 | CLASS="chrome-${HOST}__-Default" | 32 | CLASS="chrome-${HOST}__-Default" |
| 33 | 33 | ||
| 34 | -# Chromium names its MPRIS player chromium.instance<pid>, and inside a flatpak | 34 | +# Chromium names its MPRIS player chromium.instance<pid>, and every flatpak |
| 35 | -# sandbox the browser is always pid 2 — so this app, the Chromium flatpak and | 35 | +# sandbox has its own pid namespace, so each web app's browser would get the |
| 36 | -# FreeTube all fight over chromium.instance2 and only one shows in playerctl. | 36 | +# same pid and only the first app to start shows in playerctl. The sandbox |
| 37 | -# Running chromium as a child of a sandbox shell moves it to pid 3, giving the | 37 | +# shell forks and reaps PID_SKIP throwaway processes first (pids are handed out |
| 38 | -# web apps their own player name. The trailing `exit` stops bash from exec'ing | 38 | +# sequentially), which moves chromium to a per-profile pid. Offsets start at 10 |
| 39 | -# a lone command (which would keep chromium at pid 2). | 39 | +# to stay clear of the Chromium flatpak and FreeTube at pid 2. The trailing |
| 40 | +# `exit` stops bash from exec'ing chromium in place. | ||
| 41 | +PID_SKIP=$(( $(printf '%s' "$PROFILE" | cksum | cut -d' ' -f1) % 1000 + 10 )) | ||
| 40 | cmd=(flatpak run --command=bash "$BROWSER_ID" | 42 | cmd=(flatpak run --command=bash "$BROWSER_ID" |
| 41 | - -c 'chromium "$@"; exit $?' bash | 43 | + -c 'for ((i = 0; i < $0; i++)); do : & done; wait; chromium "$@"; exit $?' "$PID_SKIP" |
| 42 | --no-first-run | 44 | --no-first-run |
| 43 | --app="$URL" | 45 | --app="$URL" |
| 44 | --class="$CLASS" | 46 | --class="$CLASS" |