forge
Explore
Log in

Don't you dare go Hollow

Give each web app its own MPRIS player name

Browse files at this commit

30989a88e6199e22de79b9d3713cc40af0a59057Ahmet Kaan GümüşParent: 459b67d
  • fix
    • give each web app its own MPRIS player name
Show full message
🐛 fix(webapp): give each web app its own MPRIS player name

Every flatpak sandbox starts chromium at the same pid, so all web apps asked
for org.mpris.MediaPlayer2.chromium.instance3 and only the first one (e.g.
WhatsApp) showed up in playerctl and waybar. Burn a per-profile number of pids
in the sandbox shell before starting chromium.
.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 flatpak34+# 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 and35+# 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 the37+# 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'ing38+# 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 $?' bash43+ -c 'for ((i = 0; i < $0; i++)); do : & done; wait; chromium "$@"; exit $?' "$PID_SKIP"
42 --no-first-run44 --no-first-run
43 --app="$URL"45 --app="$URL"
44 --class="$CLASS"46 --class="$CLASS"