From 0f8c00b75885cd4b719c7c518a417adc799d4b0c Mon Sep 17 00:00:00 2001 From: Michael Leuchtenburg Date: Tue, 13 Jun 2023 17:40:53 -0400 Subject: [PATCH] First pass on using directory id as unique id --- lib/menubar/menu_gen.lua | 6 +++++- lib/menubar/utils.lua | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/menubar/menu_gen.lua b/lib/menubar/menu_gen.lua index 193eef1c5..deea86484 100644 --- a/lib/menubar/menu_gen.lua +++ b/lib/menubar/menu_gen.lua @@ -13,6 +13,7 @@ local utils = require("menubar.utils") local pairs = pairs local ipairs = ipairs local table = table +local gdebug = require("gears.debug") local menu_gen = {} @@ -21,6 +22,7 @@ local menu_gen = {} --- Get the path to the directories where XDG menu applications are installed. local function get_xdg_menu_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()) return gtable.map(function(dir) return dir .. 'applications/' end, dirs) end @@ -95,7 +97,7 @@ function menu_gen.generate(callback) for _, entry in ipairs(entries) do -- Check whether to include program in the menu 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 local target_category = nil -- Check if the program falls into at least one of the @@ -120,6 +122,8 @@ function menu_gen.generate(callback) icon = icon, category = target_category }) unique_entries[unique_key] = true + else + gdebug.dump(entry, "entry not included") end end end diff --git a/lib/menubar/utils.lua b/lib/menubar/utils.lua index 7590b2ee9..0f06e647d 100644 --- a/lib/menubar/utils.lua +++ b/lib/menubar/utils.lua @@ -410,7 +410,8 @@ function utils.parse_dir(dir_path, callback) parser(f, result) 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) + local relative_path = f:get_relative_path(target) + entry.desktop_file_id = string.gsub(relative_path, "/", "-") result[i] = entry end call_callback(callback, result)