# Signal Desktop with config/signal/theme.css applied. Signal has no user
# stylesheet, so this repacks the app.asar of nixpkgs' signal-desktop so that it
# 1. loads theme.css as stylesheets/custom.css after Signal's own stylesheets, and
# 2. creates the main window transparent, so Hyprland's blur shows through.
# Nothing else is changed; the electron, flags and profile (~/.config/Signal) are
# those of the stock package.
#
# This replaces signal/launch from the old dotfiles: the copy is built here, once,
# instead of at start-up. Edit theme.css, rebuild, and run config/signal/restart.
# If a Signal update moves one of the two places being patched, the build fails
# rather than shipping an unthemed or half-patched Signal.
{
lib,
runCommand,
signal-desktop,
asar,
theme ? ../../config/signal/theme.css,
}:
runCommand "signal-desktop-themed-${signal-desktop.version}"
{
nativeBuildInputs = [ asar ];
inherit (signal-desktop) meta;
passthru.unthemed = signal-desktop;
}
''
src=${signal-desktop}
mkdir -p $out/bin $out/share
for d in $src/share/*; do
[ "$(basename "$d")" = signal-desktop ] || [ "$(basename "$d")" = applications ] || ln -s "$d" $out/share/
done
mkdir -p $out/share/signal-desktop
for f in $src/share/signal-desktop/*; do
case "$(basename "$f")" in app.asar|app.asar.unpacked) ;; *) ln -s "$f" $out/share/signal-desktop/ ;; esac
done
asar extract $src/share/signal-desktop/app.asar app
cp ${theme} app/stylesheets/custom.css
# 1. Load the theme last, so it wins over Signal's own stylesheets.
anchor=''
grep -qF "$anchor" app/background.html
sed -i "s|$anchor|&\n |" app/background.html
grep -qF 'href="stylesheets/custom.css"' app/background.html
# 2. Transparent main window. It is the only BrowserWindow created with
# sandbox:false, which is what the pattern keys on; exactly one match or stop.
sed -i 's/backgroundColor:[A-Za-z0-9_$]*,\(webPreferences:{[^}]*sandbox:!1\)/transparent:!0,backgroundColor:`#00000000`,\1/' app/bundles/main.js
[ "$(grep -o 'transparent:!0,backgroundColor:`#00000000`' app/bundles/main.js | wc -l)" = 1 ]
asar pack --unpack '*.node' app $out/share/signal-desktop/app.asar
# Same launcher as the stock package, pointed at the themed app.asar.
substitute $src/bin/signal-desktop $out/bin/signal-desktop \
--replace-fail "$src/share/signal-desktop/app.asar" "$out/share/signal-desktop/app.asar"
chmod +x $out/bin/signal-desktop
mkdir -p $out/share/applications
substitute $src/share/applications/signal.desktop $out/share/applications/signal.desktop \
--replace-quiet "$src/bin/signal-desktop" "$out/bin/signal-desktop"
''