saturn: Provide data-dirs as List

And use the right priority
This commit is contained in:
Samuel Dionne-Riel 2022-01-25 00:45:31 -05:00 committed by Daniel Barlow
parent 4f82010ab0
commit 3574f3930f

View File

@ -89,6 +89,8 @@
(local lfs (require :lfs)) (local lfs (require :lfs))
(local inifile (require :inifile)) (local inifile (require :inifile))
(local List (require "pl.List"))
(local stringx (require "pl.stringx"))
(local inspect (require :inspect)) (local inspect (require :inspect))
(local posix (require :posix)) (local posix (require :posix))
@ -174,16 +176,20 @@
(path.concat (current-user-home) ".local/share/"))) (path.concat (current-user-home) ".local/share/")))
(fn xdg-data-dirs [] (fn xdg-data-dirs []
"Provides all data-dirs as a colon-separated string." "Provides all data-dirs as a List. Most important first."
;; Expected to be used with gmatch as a generator. ;; Expected to be used with gmatch as a generator.
(search-path.concat (let [dirs (List)]
(xdg-data-home) (dirs:append (xdg-data-home))
(os.getenv "XDG_DATA_DIRS") (dirs:extend (stringx.split (os.getenv "XDG_DATA_DIRS") ":"))
)) dirs
))
(fn all-apps [] (fn all-apps []
(var apps-table {}) (var apps-table {})
(each [path (string.gmatch (xdg-data-dirs) "[^:]*")] ;; Reversing the data dirs gives priority to the first elements.
;; This means conflicting `.desktop` files (or: desktop file ID) are given
;; priority to the first elements by "simply" reading it last.
(each [path (List.iter (List.reverse (xdg-data-dirs)))]
(let [apps (.. path "/applications/")] (let [apps (.. path "/applications/")]
(when (lfs.attributes apps) (when (lfs.attributes apps)
(each [f (lfs.dir apps)] (each [f (lfs.dir apps)]