Files
lhns--steam-frame-nix/modules/firefox/check.nix
T
Pierre Kisters 1672210ead firefox: desktop profile user.js only while its Firefox runs
The desktop profile's user.js link (undoing the fullscreen fix there) was
kept in place on every switch and before every launch. Now the launcher
(nested desktop only) makes it right before Firefox starts, waits for
Firefox instead of exec'ing it, and once it has exited and the profile is
no longer in use removes the link and the value Firefox stored from it in
prefs.js. A second launch that hands its URL to the running Firefox returns
at once and leaves both alone; a user.js of the user's own is never
touched. The desktop profile itself is a normal Firefox profile (browser
data) and is never removed.

No activation step touches profiles anymore: leftovers of a crash and what
older versions wrote (user.js copies and links, their prefs.js values) are
steam-frame-nix-cleanup's (orphans on switch), which leaves the desktop
link alone while the profile is in use; the firefox-desktop-userjs --keep
is gone. The launcher lives in firefox/launcher.nix; checks.firefox runs it
against a fake flatpak (link only while running, forwarded second launch,
prefs.js cleaned only once unlocked, own user.js untouched, Steam session).
2026-09-29 00:07:26 +02:00

70 lines
3.2 KiB
Nix

# Checks of the Firefox launcher's desktop profile user.js (launcher.nix)
# against a fake flatpak: the link exists only while Firefox runs, a second
# launch that hands over to the running Firefox doesn't remove it, the value
# Firefox stored from it leaves prefs.js once the profile is unlocked, and a
# user.js of the user's own is never touched.
{ pkgs }:
let
# Fake `flatpak run … org.mozilla.firefox --profile DIR …`: with the
# profile locked by another process it "forwards" and returns; otherwise it
# holds .parentlock, records user.js and stores the pref like Firefox does,
# and runs until $FAKE/release exists.
fakeFlatpak = pkgs.writeShellScript "flatpak" ''
while [ $# -gt 0 ] && [ "$1" != --profile ]; do shift; done
[ $# -gt 0 ] || { echo "default profile" >> $FAKE/log; exit 0; }
prof=$2
if find /proc/[0-9]*/fd -lname "$prof/.parentlock" -print -quit 2>/dev/null | grep -q .; then
echo forwarded >> $FAKE/log; exit 0
fi
touch "$prof/.parentlock"; exec 9< "$prof/.parentlock"
echo "started $(readlink "$prof/user.js" || echo none)" >> $FAKE/log
[ -L "$prof/user.js" ] && echo 'user_pref("full-screen-api.ignore-widgets", false);' >> "$prof/prefs.js"
while [ ! -e $FAKE/release ]; do sleep 0.1; done
exit 3
'';
launcher = pkgs.callPackage ./launcher.nix {
flatpakBin = fakeFlatpak;
profileDir = "$HOME/ff/desktop";
desktopFix = true;
};
in
pkgs.runCommand "firefox-check" { nativeBuildInputs = [ pkgs.findutils pkgs.gnugrep ]; } ''
set -euo pipefail
fail() { echo "FAIL: $*" >&2; cat $FAKE/log >&2 || true; exit 1; }
export HOME=$PWD/home FAKE=$PWD/fake XDG_CURRENT_DESKTOP=KDE
mkdir -p $HOME $FAKE; : > $FAKE/log
p=$HOME/ff/desktop
# first launch: link made, Firefox runs
${launcher} https://example.org & first=$!
for i in $(seq 100); do grep -q started $FAKE/log && break; sleep 0.1; done
grep -qx 'started /app/etc/firefox/steam-frame-nix-desktop-user.js' $FAKE/log || fail "not linked at start"
echo 'user_pref("other", 1);' >> $p/prefs.js
# second launch: hands over, returns, cleans nothing
${launcher} https://example.com
grep -qx forwarded $FAKE/log || fail "no forward"
[ -L $p/user.js ] || fail "second launch removed the link"
# Firefox exits: link and value gone, exit status passed on
touch $FAKE/release
status=0; wait $first || status=$?
[ $status = 3 ] || fail "status $status"
[ ! -e $p/user.js ] && [ ! -L $p/user.js ] || fail "link left"
[ "$(cat $p/prefs.js)" = 'user_pref("other", 1);' ] || fail "prefs.js: $(cat $p/prefs.js)"
# a user.js of the user's own: untouched
echo 'user_pref("mine", 1);' > $p/user.js
echo 'user_pref("full-screen-api.ignore-widgets", false);' >> $p/prefs.js
${launcher} || true
[ "$(cat $p/user.js)" = 'user_pref("mine", 1);' ] || fail "own user.js changed"
grep -q ignore-widgets $p/prefs.js || fail "prefs.js changed with an own user.js"
rm $p/user.js
# Steam session: default profile, no link
: > $FAKE/log
XDG_CURRENT_DESKTOP=gamescope ${launcher} || true
grep -qx 'default profile' $FAKE/log || fail "used --profile in the Steam session"
[ ! -e $p/user.js ] || fail "linked in the Steam session"
echo ok
touch $out
''