-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdesktop_files.lua
More file actions
122 lines (88 loc) · 2.16 KB
/
desktop_files.lua
File metadata and controls
122 lines (88 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
--[[
-- DESKTOP FILES ***************************************
]]--
function AppChooseGroup(name, groups)
local str, group, first, config
local toks
config=AppConfigFind(name)
if config ~= nil
then
if strutil.strlen(config.group) > 0 then return config.group end
end
if groups==nil then return nil end
toks=strutil.TOKENIZER(groups, ";")
str=toks:next()
while str ~= nil
do
group=FindGroup(str)
if group ~= nil
then
if group.ignore == false then return str end
else
if first ~= nil then first = str end
end
str=toks:next()
end
if first ~= nil
then
group=NewGroup(first)
return group.name
end
return nil
end
function LoadDesktopFile(path)
local S, str, toks, invoke, exec, run_dir, config, app, categories
S=stream.STREAM(path, "r")
if S ~= nil
then
app=NewApp("desktop", "", "", "")
str=S:readln()
while str ~= nil
do
toks=strutil.TOKENIZER(strutil.stripTrailingWhitespace(str), "=")
key=toks:next()
value=strutil.stripQuotes(toks:remaining())
strutil.trim(key)
strutil.trim(value)
if key=="Name"
then
app.name=value
app.title=value
elseif key=="Icon" then app.icons=value
elseif key=="Path" then run_dir=value
elseif key=="Exec" then exec=value
elseif key=="Categories" then categories=value
end
str=S:readln()
end
S:close()
if strutil.strlen(exec) < 1 then return end
--desktop files can specify a 'filename' argument using %f. As we are building menus for window managers
--that don't understand this, we pass an empty string for this value to get rid of it
app.exec=string.gsub(exec, "%%f","")
app.group=AppChooseGroup(app.name, categories)
--once both app.name, app.group and app.exec are sorted, we can check overrides
ProcessAppOverrides(app)
--if app has ignore set, then do nothing
app=AppConfigAdd(app)
if app.ignore == true then return end
if strutil.strlen(run_dir) > 0
then
app.invoke="cd '" .. run_dir .. "'; " .. app.exec
else
app.invoke=app.exec
end
MenuAddItem(app.group, app)
end
end
function LoadDesktopFiles(path)
local files, item, str
str=path.."/share/applications/*.desktop"
files=filesys.GLOB(str)
item=files:next()
while item ~= nil
do
LoadDesktopFile(item)
item=files:next()
end
end