#
# Fix a bug that makes signal not start on wayland.
#
# vim: et:ts=2:sw=2:
#
{ ... }:
let
  overlay = final': prev': {
    signal-desktop-bin = prev'.signal-desktop-bin.overrideAttrs (
      final: prev: rec {

        # We'll need to patch the ASAR in order to apply our fix.
        nativeBuildInputs = prev.nativeBuildInputs ++ [
          prev'.asar
        ];

        # Do terrible, terrible things.
        preFixup =
          prev.preFixup
          + ''
						# Make this work with KDE wallet on non-kde.
						gappsWrapperArgs+=(
							--add-flags "--password-store=kwallet6"
						)

            # Fix up the main.js in the app to actually show the window.
            #pushd $out/lib/Signal/resources/

            #asar extract app.asar app-unpacked

            #pushd app-unpacked
            #patch -p1 < ${./01-show-window.patch}
            #popd

            #asar pack app-unpacked app.asar
            #popd
          '';

      }
    );
  };
in
{
  nixpkgs.overlays = [ overlay ];
}
