Reno is the second iteration of the AWMTK-powered AwesomeWM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.7 KiB

2 years ago
1 year ago
  1. -- This file is part of Reno desktop.
  2. --
  3. -- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  4. --
  5. -- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. --
  7. -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
  8. -- Asynchronous XDG data aggregator
  9. local menu_utils = require("menubar.utils")
  10. local menu_gen = require("menubar.menu_gen")
  11. local gears = require("gears")
  12. local json = require("dkjson")
  13. local lib = require("xdg_data")
  14. menu_utils.wm_name = ""
  15. -- Directories to scan for .desktop files
  16. local desktop_dirs = {os.getenv("HOME").."/Desktop"}
  17. local desktop_dirs_complete = 0
  18. local _ = ((table.concat(gears.filesystem.get_xdg_data_dirs(),":") or
  19. "/usr/share:/usr/local/share")..":"..os.getenv("HOME").."/.local/share"):gsub("[^:]*",function(path)
  20. if gears.filesystem.dir_readable(path.."/applications") then
  21. table.insert(desktop_dirs, path.."/applications")
  22. end
  23. end)
  24. -- Global xdg data struct
  25. _G.xdg = lib.init_xdg_struct()
  26. -- Load cached applications
  27. local cache = lib.load_xdg_cache()
  28. -- Add missing category entries as defined by awesome
  29. lib.add_categories(xdg,menu_gen.all_categories)
  30. -- Asynchronous scanning process
  31. lib.async_process_dirs(xdg,desktop_dirs,cache,function(v)
  32. -- Count completed directory
  33. desktop_dirs_complete = desktop_dirs_complete + 1
  34. -- Call a global signal
  35. awesome.emit_signal("xdg::dir_finished",v)
  36. end)
  37. local count = function(t)
  38. local n = 0
  39. for _,_ in pairs(t) do
  40. n = n + 1
  41. end
  42. return n
  43. end
  44. awesome.connect_signal("xdg::dir_finished",function(dir)
  45. -- We only send the all_finished signal when all directories finished processing
  46. if desktop_dirs_complete == #desktop_dirs then
  47. -- Clean up empty categories
  48. for k,v in pairs(xdg.categories) do
  49. if count(v.apps) == 0 then
  50. xdg.categories[k] = nil
  51. end
  52. end
  53. -- Save the cache if it doesn't exist yet
  54. io.open(gears.filesystem.get_xdg_cache_home()..".reno_xdg_cache.json","w"):write(json.encode(xdg)):close()
  55. -- Finally, call the all_finished signal
  56. awesome.emit_signal("xdg::all_finished")
  57. end
  58. end)
  59. -- Before exiting, save all xdg cache
  60. awesome.connect_signal("exit",function()
  61. io.open(gears.filesystem.get_xdg_cache_home()..".reno_xdg_cache.json","w"):write(json.encode(xdg)):close()
  62. end)