From 30989a88e6199e22de79b9d3713cc40af0a59057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 25 Oct 2026 17:25:31 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(webapp):=20give=20each=20web?= =?UTF-8?q?=20app=20its=20own=20MPRIS=20player=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.config/scripts/shared/webapp.sh b/.config/scripts/shared/webapp.sh index ee8df17..f2a7c12 100755 --- a/.config/scripts/shared/webapp.sh +++ b/.config/scripts/shared/webapp.sh @@ -31,14 +31,16 @@ HOST="${URL#*://}" HOST="${HOST%%/*}" CLASS="chrome-${HOST}__-Default" -# Chromium names its MPRIS player chromium.instance, and inside a flatpak -# sandbox the browser is always pid 2 — so this app, the Chromium flatpak and -# FreeTube all fight over chromium.instance2 and only one shows in playerctl. -# Running chromium as a child of a sandbox shell moves it to pid 3, giving the -# web apps their own player name. The trailing `exit` stops bash from exec'ing -# a lone command (which would keep chromium at pid 2). +# Chromium names its MPRIS player chromium.instance, and every flatpak +# sandbox has its own pid namespace, so each web app's browser would get the +# same pid and only the first app to start shows in playerctl. The sandbox +# shell forks and reaps PID_SKIP throwaway processes first (pids are handed out +# sequentially), which moves chromium to a per-profile pid. Offsets start at 10 +# to stay clear of the Chromium flatpak and FreeTube at pid 2. The trailing +# `exit` stops bash from exec'ing chromium in place. +PID_SKIP=$(( $(printf '%s' "$PROFILE" | cksum | cut -d' ' -f1) % 1000 + 10 )) cmd=(flatpak run --command=bash "$BROWSER_ID" - -c 'chromium "$@"; exit $?' bash + -c 'for ((i = 0; i < $0; i++)); do : & done; wait; chromium "$@"; exit $?' "$PID_SKIP" --no-first-run --app="$URL" --class="$CLASS"