noctalia-plugin: captures as streams (no 5 s timeout), valw's error message in notifications, full state on every --set
This commit is contained in:
1 parent
9fa71fd399
commit
619eab9dc9
11 files changed
+234
-81
No files matched your search
+25
-10
@@ -5,18 +5,33 @@
|
||||
|
||||
local PANEL = "elars/valw:toolbar"
|
||||
|
||||
local function lastLine(text)
|
||||
local last = ""
|
||||
for line in string.gmatch(text or "", "[^\n]+") do
|
||||
last = line
|
||||
-- valw's stderr on an error starts with "error: <message>", then cause,
|
||||
-- hint and log lines.
|
||||
local function errorMessage(lines)
|
||||
for _, line in ipairs(lines) do
|
||||
local message = string.match(line, "^error: (.+)$")
|
||||
if message then
|
||||
return message
|
||||
end
|
||||
end
|
||||
return last
|
||||
return noctalia.tr("error.failed")
|
||||
end
|
||||
|
||||
-- Exit 3 is a cancel (Esc): not an error.
|
||||
local function report(result)
|
||||
if result.exitCode ~= 0 and result.exitCode ~= 3 then
|
||||
noctalia.notifyError("valw", lastLine(result.stderr))
|
||||
-- A capture lasts as long as the user takes (a region, a zoom, the timer),
|
||||
-- so it runs as a stream: runAsync with a callback kills its command after
|
||||
-- 5 s. stderr joins the stream and the exit status comes last.
|
||||
local function capture(command)
|
||||
local lines = {}
|
||||
local started = noctalia.runStream("(" .. command .. ") 2>&1; echo valw-exit:$?", function(line)
|
||||
local code = string.match(line, "^valw%-exit:(%d+)$")
|
||||
if code == nil then
|
||||
table.insert(lines, line)
|
||||
elseif code ~= "0" and code ~= "3" then
|
||||
noctalia.notifyError("valw", errorMessage(lines))
|
||||
end
|
||||
end)
|
||||
if not started then
|
||||
noctalia.notifyError("valw", noctalia.tr("error.failed"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,5 +47,5 @@ function onClick()
|
||||
end
|
||||
|
||||
function onRightClick()
|
||||
noctalia.runAsync("valw region", report)
|
||||
capture("valw region")
|
||||
end
|
||||
Reference in new issue
Block a user