fix: http(s) match, shell escape, cleaner code

This commit is contained in:
Yocraft-2000
2026-07-18 09:07:21 +02:00
parent d9eea91d2b
commit 7c5ed0be6a
+17 -4
View File
@@ -8,7 +8,7 @@ local function loadLinks()
for _, line in ipairs(raw) do for _, line in ipairs(raw) do
local name, url = line:match("^([^|]+)|(.+)$") local name, url = line:match("^([^|]+)|(.+)$")
if name and url then if name and url and url:match("^https?://") then
table.insert(links, { table.insert(links, {
name = noctalia.string.trim(name), name = noctalia.string.trim(name),
url = noctalia.string.trim(url), url = noctalia.string.trim(url),
@@ -83,11 +83,20 @@ function onQuery(query)
end end
if text == "" then if text == "" then
table.insert(results, { id = link.url, title = link.name, subtitle = link.url, glyph = glyphValue, icon = iconValue }) table.insert(results, {
id = link.url,
title = link.name, subtitle = link.url,
glyph = glyphValue, icon = iconValue
})
else else
local score = noctalia.fuzzyScore(text, link.name) local score = noctalia.fuzzyScore(text, link.name)
if score ~= nil then if score ~= nil then
table.insert(results, { id = link.url, title = link.name, subtitle = link.url, glyph = glyphValue, icon = iconValue, score = score }) table.insert(results, {
id = link.url,
title = link.name, subtitle = link.url,
glyph = glyphValue, icon = iconValue,
score = score
})
end end
end end
end end
@@ -95,8 +104,12 @@ function onQuery(query)
launcher.setResults(query, results) launcher.setResults(query, results)
end end
local function shellEscape(raw)
return "'" .. raw:gsub("'", "'\\''") .. "'"
end
function onActivate(id) function onActivate(id)
noctalia.runAsync("xdg-open '" .. id .. "'") noctalia.runAsync("xdg-open " .. shellEscape(id))
if noctalia.getConfig("notify") then if noctalia.getConfig("notify") then
noctalia.notify("Websites", "Opening " .. id) noctalia.notify("Websites", "Opening " .. id)
end end