{ lib
, fetchzip
, appimageTools
, makeDesktopItem
}:

let
  pname = "fantasia-archive";
  version = "0.1.10";

  archive = fetchzip {
    url = "https://github.com/Elvanos/fantasia-archive/releases/download/v${version}/Fantasia.Archive-${version}-linux-appImage.zip";
    hash = "sha256-Ls+7wmj2qFoppiHJwt9Uan+9irFvzHxEWjIWrA9Nw2w=";
  };
  src = "${archive}/Fantasia.Archive-${version}-linux-appImage.AppImage"; 
  appimageContents = appimageTools.extractType2 {
    inherit pname src version;
  };

  description = "100% free, powerful & feature-rich offline worldbuilding tool that runs on your computer!";

  desktopItem = makeDesktopItem {
    name = pname;
    exec = "sh -c \"${pname} || ${pname} --disable-gpu-sandbox\"";
    icon = "${appimageContents}/fantasiaarchive.png";
    comment = description;
    desktopName = "Fantasia Archive";
    genericName = "A database manager for world building";
    categories = [ "Office" ];
  };
in
appimageTools.wrapType2 {
  inherit pname version src;

  extraInstallCommands = ''
    mkdir -p $out/share/applications
    ln -s ${desktopItem}/share/applications/${pname}.desktop $out/share/applications/${pname}.desktop
    cd $out/bin
    mv fantasia-archive-${version} ${pname}
  '';

  meta = with lib; {
    inherit description;
    homepage = "https://fantasiaarchive.com/";
    license = licenses.gpl3;
    maintainers = with maintainers; [ elnudev ];
    platforms = [ "x86_64-linux" ];
    sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
  };
}
