hyprland: discover lua modules dynamically
This commit is contained in:
@@ -19,16 +19,61 @@ package.path = table.concat({
|
|||||||
package.path,
|
package.path,
|
||||||
}, ";")
|
}, ";")
|
||||||
|
|
||||||
local modules = {
|
local function shell_quote(value)
|
||||||
"hyprland.state",
|
return "'" .. tostring(value):gsub("'", "'\\''") .. "'"
|
||||||
"hyprland.scratchpads",
|
end
|
||||||
"hyprland.core",
|
|
||||||
"hyprland.layouts",
|
local function module_load_phase(name)
|
||||||
"hyprland.windows",
|
if name == "state" then
|
||||||
"hyprland.settings",
|
return 0
|
||||||
"hyprland.binds",
|
elseif name == "binds" then
|
||||||
"hyprland.events",
|
return 20
|
||||||
|
elseif name == "events" then
|
||||||
|
return 30
|
||||||
|
end
|
||||||
|
|
||||||
|
return 10
|
||||||
|
end
|
||||||
|
|
||||||
|
local function discover_modules()
|
||||||
|
local modules_dir = base_dir .. "/hyprland"
|
||||||
|
local handle = assert(io.popen("find " .. shell_quote(modules_dir) .. " -maxdepth 1 -type f -name '*.lua' -print"))
|
||||||
|
local discovered = {}
|
||||||
|
|
||||||
|
for path in handle:lines() do
|
||||||
|
local name = path:match("/([^/]+)%.lua$")
|
||||||
|
if name then
|
||||||
|
discovered[#discovered + 1] = {
|
||||||
|
name = name,
|
||||||
|
module = "hyprland." .. name,
|
||||||
|
phase = module_load_phase(name),
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
handle:close()
|
||||||
|
|
||||||
|
table.sort(discovered, function(left, right)
|
||||||
|
if left.phase ~= right.phase then
|
||||||
|
return left.phase < right.phase
|
||||||
|
end
|
||||||
|
|
||||||
|
return left.name < right.name
|
||||||
|
end)
|
||||||
|
|
||||||
|
local modules = {}
|
||||||
|
for _, item in ipairs(discovered) do
|
||||||
|
modules[#modules + 1] = item.module
|
||||||
|
end
|
||||||
|
|
||||||
|
if modules[1] ~= "hyprland.state" then
|
||||||
|
error("hyprland/state.lua is required")
|
||||||
|
end
|
||||||
|
|
||||||
|
return modules
|
||||||
|
end
|
||||||
|
|
||||||
|
local modules = discover_modules()
|
||||||
|
|
||||||
for _, module in ipairs(modules) do
|
for _, module in ipairs(modules) do
|
||||||
package.loaded[module] = nil
|
package.loaded[module] = nil
|
||||||
|
|||||||
Reference in New Issue
Block a user