mirror of
https://github.com/lhns/steam-frame-nix.git
synced 2026-10-06 03:00:13 +02:00
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).
54 lines
2.6 KiB
Nix
54 lines
2.6 KiB
Nix
# The Firefox Flatpak launcher (firefox.nix). In the nested desktop (KDE) it
|
|
# uses the desktop profile; with the fullscreen fix it links that profile's
|
|
# user.js to the sandbox path desktopJs (undoing the fix there) right before
|
|
# Firefox starts, and once Firefox has exited and the profile is no longer in
|
|
# use (a second launch that only hands its URL to the running Firefox returns
|
|
# at once) removes the link and the value Firefox stored from it in
|
|
# prefs.js. A user.js of the user's own is never touched. After a crash the
|
|
# next launch or steam-frame-nix-cleanup finishes the removal.
|
|
{ lib, writeShellScript, coreutils, findutils, gnugrep
|
|
, flatpakBin ? "/usr/bin/flatpak" # (not `flatpak`: callPackage would pass pkgs.flatpak)
|
|
, profileDir ? null # shell word, e.g. "$HOME/.var/app/…/desktop"; null: no desktop profile
|
|
, desktopFix ? false
|
|
, desktopJs ? "/app/etc/firefox/steam-frame-nix-desktop-user.js"
|
|
, desktopKeys ? [ "full-screen-api.ignore-widgets" ]
|
|
}:
|
|
writeShellScript "firefox-launcher" (''
|
|
PATH=${lib.makeBinPath [ coreutils findutils gnugrep ]}:$PATH
|
|
run=(${flatpakBin} run --branch=stable --arch=aarch64 --command=firefox --file-forwarding org.mozilla.firefox)
|
|
'' + (if profileDir == null then ''
|
|
exec "''${run[@]}" "$@"
|
|
'' else ''
|
|
if [ "$XDG_CURRENT_DESKTOP" != KDE ]; then exec "''${run[@]}" "$@"; fi
|
|
prof="${profileDir}"
|
|
# Firefox exits (status 1) if the --profile dir doesn't exist yet.
|
|
mkdir -p "$prof"
|
|
'' + lib.optionalString desktopFix ''
|
|
js=${lib.escapeShellArg desktopJs}
|
|
u=$prof/user.js
|
|
# Firefox holds .parentlock open while it uses a profile (the sandbox sees
|
|
# the profile at the same path).
|
|
inUse() { find /proc/[0-9]*/fd -lname "$prof/.parentlock" -print -quit 2>/dev/null | grep -q .; }
|
|
ours() { [ -L "$u" ] && [ "$(readlink "$u")" = "$js" ]; }
|
|
sfn_unlink() {
|
|
ours && ! inUse || return 0
|
|
if [ -f "$prof/prefs.js" ] && grep -qF -f <(printf '%s\n' ${lib.escapeShellArgs (map (k: "user_pref(${builtins.toJSON k},") desktopKeys)}) "$prof/prefs.js"; then
|
|
grep -vF -f <(printf '%s\n' ${lib.escapeShellArgs (map (k: "user_pref(${builtins.toJSON k},") desktopKeys)}) "$prof/prefs.js" > "$prof/prefs.js.sfn" || true
|
|
cat "$prof/prefs.js.sfn" > "$prof/prefs.js"
|
|
rm -f "$prof/prefs.js.sfn"
|
|
fi
|
|
rm -f "$u"
|
|
}
|
|
if [ -e "$u" ] || [ -L "$u" ]; then
|
|
ours || echo "firefox: $u is not steam-frame-nix's; fullscreen stays inside the window in this profile" >&2
|
|
else
|
|
ln -s "$js" "$u"
|
|
fi
|
|
"''${run[@]}" --profile "$prof" "$@"
|
|
status=$?
|
|
sfn_unlink
|
|
exit $status
|
|
'' + lib.optionalString (!desktopFix) ''
|
|
exec "''${run[@]}" --profile "$prof" "$@"
|
|
''))
|