First pass on using directory id as unique id

This commit is contained in:
Michael Leuchtenburg 2023-06-13 17:40:53 -04:00
parent 392976060f
commit 0f8c00b758
2 changed files with 7 additions and 2 deletions

View File

@ -13,6 +13,7 @@ local utils = require("menubar.utils")
local pairs = pairs local pairs = pairs
local ipairs = ipairs local ipairs = ipairs
local table = table local table = table
local gdebug = require("gears.debug")
local menu_gen = {} local menu_gen = {}
@ -21,6 +22,7 @@ local menu_gen = {}
--- Get the path to the directories where XDG menu applications are installed. --- Get the path to the directories where XDG menu applications are installed.
local function get_xdg_menu_dirs() local function get_xdg_menu_dirs()
local dirs = gfilesystem.get_xdg_data_dirs() local dirs = gfilesystem.get_xdg_data_dirs()
gdebug.dump(gfilesystem.get_xdg_data_home(), "xdg_data_home")
table.insert(dirs, 1, gfilesystem.get_xdg_data_home()) table.insert(dirs, 1, gfilesystem.get_xdg_data_home())
return gtable.map(function(dir) return dir .. 'applications/' end, dirs) return gtable.map(function(dir) return dir .. 'applications/' end, dirs)
end end
@ -95,7 +97,7 @@ function menu_gen.generate(callback)
for _, entry in ipairs(entries) do for _, entry in ipairs(entries) do
-- Check whether to include program in the menu -- Check whether to include program in the menu
if entry.show and entry.Name and entry.cmdline then if entry.show and entry.Name and entry.cmdline then
local unique_key = entry.Name .. '\0' .. entry.cmdline local unique_key = entry.desktop_file_id
if not unique_entries[unique_key] then if not unique_entries[unique_key] then
local target_category = nil local target_category = nil
-- Check if the program falls into at least one of the -- Check if the program falls into at least one of the
@ -120,6 +122,8 @@ function menu_gen.generate(callback)
icon = icon, icon = icon,
category = target_category }) category = target_category })
unique_entries[unique_key] = true unique_entries[unique_key] = true
else
gdebug.dump(entry, "entry not included")
end end
end end
end end

View File

@ -410,7 +410,8 @@ function utils.parse_dir(dir_path, callback)
parser(f, result) parser(f, result)
for i, entry in ipairs(result) do for i, entry in ipairs(result) do
local target = gio.File.new_for_path(entry.file) local target = gio.File.new_for_path(entry.file)
entry.desktop_file_id = f:get_relative_path(target) local relative_path = f:get_relative_path(target)
entry.desktop_file_id = string.gsub(relative_path, "/", "-")
result[i] = entry result[i] = entry
end end
call_callback(callback, result) call_callback(callback, result)