Change wmclass for appimages launched with AppRun with Gnome

Hi,

I use appimagetools to wrap appimages, for example

{ appimageTools, lib, fetchurl }:

let
  name = "navicat";
  version = "16.2.2";
  # Minor versions are released using the same file name
  versionItems = builtins.splitVersion version;
  majorVersion = (builtins.elemAt versionItems 0);

  appimageContents = appimageTools.extract {
    inherit name src;
  };

  src = fetchurl {
    url = "https://download3.navicat.com/download/navicat${majorVersion}-premium-en.AppImage";
    hash = "sha256-noh1b9qegZJlxSicmOXTjDyjoxGMPDfCS7G2OeWPM8A=";
  };
in

appimageTools.wrapType1 {
  inherit name src;

  extraInstallCommands = ''
    mkdir -p $out/share/applications
    ln -s ${appimageContents}/navicat.desktop $out/share/applications/navicat.desktop
    cp -r ${appimageContents}/usr/share/icons/ $out/share/
  '';

  extraPkgs = pkgs: [ ];

  meta = with lib; {
    description = "Navicat Premium 16";
    homepage = "https://www.navicat.com/";
    license = with licenses; [ unfree ];
    platforms = [ "x86_64-linux" ];
  };
}

When I launch the app, the desktop icon is duplicated in the Dash of Gnome because the wmclass is AppRun and not navicat

Capture d’écran du 2023-07-21 13-36-39

Is there a way to change the wmclass of an appimage that is launched with AppRun ?

WM_CLASS is a X11 concept, on Wayland each window has an application id Projects/GnomeShell/ApplicationBased - GNOME Wiki!

I finally found out how to solve my issue, by adding the --name option to the exec command

  extraInstallCommands = ''
    mv $out/bin/${name} $out/bin/${pname}
    install -m 444 -D ${appimageContents}/${pname}.desktop -t $out/share/applications
    substituteInPlace $out/share/applications/${pname}.desktop --replace 'Exec=navicat' 'Exec=${pname} --name ${pname}'
    cp -r ${appimageContents}/usr/share/icons $out/share
  '';