Avoid loading duplicate .desktop files in menubar#3822
Avoid loading duplicate .desktop files in menubar#3822dyfrgi wants to merge 5 commits intoawesomeWM:masterfrom
Conversation
psychon
left a comment
There was a problem hiding this comment.
Looks fine to me. I looked at this locally with git diff -w and that makes the diff a lot smaller. :-)
lib/menubar/utils.lua
Outdated
| for i, entry in ipairs(result) do | ||
| local target = gio.File.new_for_path(entry.file) | ||
| entry.desktop_file_id = f:get_relative_path(target) | ||
| result[i] = entry |
There was a problem hiding this comment.
Isn't this line redundant? entry came from result, so is already referenced there.
There was a problem hiding this comment.
Good point. My poor Lua knowledge is showing here, about what variables are references and which are not. The Lua reference manual set me straight. I'll remove this.
Codecov Report
@@ Coverage Diff @@
## master #3822 +/- ##
==========================================
- Coverage 90.99% 90.97% -0.03%
==========================================
Files 900 901 +1
Lines 57506 57535 +29
==========================================
+ Hits 52329 52340 +11
- Misses 5177 5195 +18
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
I started working on some unit tests for this, but I gave up due to the lack of support for async() in busted 2.x. https://github.com/dyfrgi/awesome/compare/desktop-file-id...dyfrgi:awesome:menu_gen-unit-test?expand=1 shows the starting point, though. With busted 2.0, we'd need a custom test runner. I don't quite have it in me to dig into lgi + gio async work and busted custom test runners for this PR, so I hope that manual testing is sufficient. It would probably be possible to refactor things so as to make this easier to test without handling async in the test runner, but it's not obvious to me. |
|
there are several tests which have accommodation for that (via re-running test function few times), and using |
|
@dyfrgi Do you still plan to work on the test? As @actionless said, this is better done using an integration test suite since it has a full event loop and retry function if they return |
|
Whoops, I never actually sent the reply I drafted. Yes, I plan to work on it. Have done some work on it a couple weeks back but only got it to 95%. I'll post something for review soon. |
Currently, if a user copies a .desktop file into some other directory, they will get duplicate entries in menubar. This PR changes that so that only one entry is kept.
The Desktop Entry Specification says that entries have an id derived from their path.
Only the first file found with a given id, following the order of directories in
$XDG_DATA_DIRS, should be used. This PR changes the logic used by menubar to do exactly this. This allows users to e.g. override a system defined .desktop file by putting a changed one in~/.local/share/applications/. Changing '/' into '-' allows overriding a file stored inside a directory hierarchy of the system without creating directories in .local.To do this, the GIO Async context was hoisted above the iteration through directories as otherwise following directory precedence would be more complex.
There is one divergence from the spec in this implementation. The spec says:
In this implementation, we scan through
menu_bar.all_menu_dirs, and all these directories are treated the same, regardless of whether they are "an applications subdirectory of one of the $XDG_DATA_DIRS components". Some users set this, though it's pretty uncommon. I think this is unlikely to cause the few people who use this to add more directories any problems with accidentally-ignored .desktop files.Fixes #1816.