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
68 lines
2.7 KiB
-- This file is part of Reno desktop.
|
|
--
|
|
-- 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.
|
|
--
|
|
-- 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.
|
|
--
|
|
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
|
|
-- Asynchronous XDG data aggregator
|
|
local menu_utils = require("menubar.utils")
|
|
local menu_gen = require("menubar.menu_gen")
|
|
local gears = require("gears")
|
|
local json = require("dkjson")
|
|
local lib = require("xdg_data")
|
|
menu_utils.wm_name = ""
|
|
|
|
-- Directories to scan for .desktop files
|
|
local desktop_dirs = {os.getenv("HOME").."/Desktop"}
|
|
local desktop_dirs_complete = 0
|
|
local _ = ((table.concat(gears.filesystem.get_xdg_data_dirs(),":") or
|
|
"/usr/share:/usr/local/share")..":"..os.getenv("HOME").."/.local/share"):gsub("[^:]*",function(path)
|
|
if gears.filesystem.dir_readable(path.."/applications") then
|
|
table.insert(desktop_dirs, path.."/applications")
|
|
end
|
|
end)
|
|
|
|
|
|
-- Global xdg data struct
|
|
_G.xdg = lib.init_xdg_struct()
|
|
-- Load cached applications
|
|
local cache = lib.load_xdg_cache()
|
|
-- Add missing category entries as defined by awesome
|
|
lib.add_categories(xdg,menu_gen.all_categories)
|
|
-- Asynchronous scanning process
|
|
lib.async_process_dirs(xdg,desktop_dirs,cache,function(v)
|
|
-- Count completed directory
|
|
desktop_dirs_complete = desktop_dirs_complete + 1
|
|
-- Call a global signal
|
|
awesome.emit_signal("xdg::dir_finished",v)
|
|
end)
|
|
|
|
local count = function(t)
|
|
local n = 0
|
|
for _,_ in pairs(t) do
|
|
n = n + 1
|
|
end
|
|
return n
|
|
end
|
|
|
|
awesome.connect_signal("xdg::dir_finished",function(dir)
|
|
-- We only send the all_finished signal when all directories finished processing
|
|
if desktop_dirs_complete == #desktop_dirs then
|
|
-- Clean up empty categories
|
|
for k,v in pairs(xdg.categories) do
|
|
if count(v.apps) == 0 then
|
|
xdg.categories[k] = nil
|
|
end
|
|
end
|
|
-- Save the cache if it doesn't exist yet
|
|
io.open(gears.filesystem.get_xdg_cache_home()..".reno_xdg_cache.json","w"):write(json.encode(xdg)):close()
|
|
-- Finally, call the all_finished signal
|
|
awesome.emit_signal("xdg::all_finished")
|
|
end
|
|
end)
|
|
|
|
-- Before exiting, save all xdg cache
|
|
awesome.connect_signal("exit",function()
|
|
io.open(gears.filesystem.get_xdg_cache_home()..".reno_xdg_cache.json","w"):write(json.encode(xdg)):close()
|
|
end)
|