A big problem with the .desktop files handled by Whisker menu + MenuLibre
XFCE uses the Whisker menu and MenuLibre as default as far as I understand. This is how you find you "apps", edit them or sort into categories.
Here's the huge issue:
User A can easily right click an app from the Whisker menu and edit it. Say it adds a new name. Behind the curtain Whisker has created a .desktop file for that app in .local/share/applications
to add to it the new name the user A has chosen. All good.
However, if user A later on deletes this app that he/she renamed, then the .desktop file is still present in .local/share/applications and therefore present in the Whisker menu. User A is confused. Clicks it and nothing happens. The options user A has is to "hide" this zombie app icon. So it does. Job done?
No.
If user A will reinstall this same app in the future, it will not see it at all, anywhere. Because when he/she chose to hide it, Whisker menu added a hide option to the same .desktop file it first created when user A chose to rename that app.
So user A needs to somehow be aware of all of these and un-hide that app manually via .local/share/applications
.
Menulibre is doing things in the same manner.
You see, you provide a very easy way for users to edit such apps and add them to categories and such, but not an easy way for them to undo these or deal with the consequences. I personally have hundreds of apps and end up adding them to different categories for ease of use, and some I rename or add keywords to them. In time I uninstall many of these apps, and then I end up with many zombie files in the menu. Now I have to go delete all of these .desktop files (that are named in all kinds of ways) from .local/share/applications
? This seems a bit insane.
Lets fix it!
We made a script that we tested with apps from repos, appimages, and flatpaks. Not tested with snaps so far.
This:
#!/bin/bash
for file in "$HOME"/.local/share/applications/*.desktop; do
name=$(basename "$file") || continue
[[ "$name" = appimagekit_* ]] || [[ "$name" = menulibre-* ]] && continue
[ -f /usr/share/applications/"$name" ] ||
ls /var/lib/flatpak/app/*/current/active/files/share/applications/"$name" &>/dev/null ||
mv "$file" "$file.bak"
done
for bakfile in "$HOME"/.local/share/applications/*.desktop.bak; do
origfile="${bakfile/%.bak}"
[ -f "$origfile" ] && continue
name=$(basename "$origfile") || continue
[ -f /usr/share/applications/"$name" ] ||
ls /var/lib/flatpak/app/*/current/active/files/share/applications/"$name" &>/dev/null &&
mv "$bakfile" "$origfile"
done
notify-send 'The icons have been refreshed!'
What it does is to check the /usr/share/applications/
and /var/lib/flatpak/app/*/current/active/files/share/applications/
for .desktop files. If it does not find them there but they are in .local/share/applications
, it means that these apps are gone (uninstalled) and so it renames the .desktop files from .local/share/applications
with a .bak at the end, making them invisible for the desktop. This way if user A installs an app, then edits it via MenuLibre or Whisker menu, and then uninstalls this app, the script will be able to automatically remove the apps' icon from the system basically. So user A is now happy that he/she uninstalled an app and that app is gone!
More to that, if user A reinstalls the app, the script will bring back the original (and edited) app icon. User A is very happy. Uninstall or Install removes or brings back the app's icon, as it should.
But it is not as great as we want to, because any .desktop file added manually to .local/share/applications
will be renamed too. Since users can also create new launchers via MenuLibre, these do not have a .desktop file in /usr/share/applications/
or /var/lib/flatpak/app/*/current/active/files/share/applications/
so our script would think that these need to be renamed. We then added a rule to ignore the files that start with "menulibre" (since MenuLibre renames all new launchers made via it, as such). Same was the thinking for appimages, ignore .desktop files that start with "appimagekit_" since appimages have no .dekstop file anywhere else.
So now, with our script, if users deal with repo packages, flatpaks, or appimages, and then they edit them via Whisker menu or MenuLibre, things will be fine and no zombie apps in the menus. And it even ignores the entries created by the MenuLibre.
Help us.
But to make our job a lot easier it would be best if all edited .desktop files via Whisker menu and MenuLibre be put into a separate folder in .local/share/applications
. This way we could only temper with that folder and not the main
.local/share/applications
.
We ask for your feedback and help.