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:
elwrcl committed 2026-10-04 06:27:57 +03:00
1 parent 9fa71fd399
commit 619eab9dc9
11 files changed
+234 -81

No files matched your search

+31 -17
View File
@@ -12,13 +12,13 @@ assert(#calls.notify == 1, "notified once")
assert(#calls.run == 0, "nothing run")
ok("valw missing")
-- --state failing: the same.
-- --state failing: the same, with valw's error message (not its log line).
reset()
fake.exists = true
fake.answers["valw toolbar --state"] = { exitCode = 1, stdout = "", stderr = "warn\nerror: broken\n" }
fake.answers["valw toolbar --state"] = { exitCode = 1, stdout = "", stderr = valwError("broken config") }
onOpen(nil)
assert(findAll(rendered, function(n) return n.kind == "label" and n.props.text == "panel.unavailable" end)[1], "label")
assert(calls.notify[1][2] == "error: broken", "the stderr's last line: " .. tostring(calls.notify[1][2]))
assert(calls.notify[1][2] == "broken config", "valw's message: " .. tostring(calls.notify[1][2]))
ok("--state failing")
-- A working valw: the remembered mode is primary, the timer selected.
@@ -46,42 +46,56 @@ end)
assert(#hex == 0, "no hex colours")
ok("renders the state")
-- A mode click closes the panel first, then captures after the wait.
-- A mode click closes the panel first, then captures after the wait, as a
-- stream (no timeout: a region or a timer can take longer than 5 s).
reset()
button("mode.region").props.onClick()
assert(calls.order[1] == "close" and calls.order[2] == "run", "close, then run")
assert(calls.run[1] == "sleep 0.3 && valw toolbar --run region", calls.run[1])
assert(calls.order[1] == "close" and calls.order[2] == "stream", "close, then capture")
assert(calls.stream[1] == "(sleep 0.3 && valw toolbar --run region) 2>&1; echo valw-exit:$?", calls.stream[1])
assert(#calls.run == 0, "never through runAsync's timeout")
assert(#calls.notify == 0, "success is silent")
ok("mode click")
-- A failed capture notifies; a cancelled one doesn't.
-- A failed capture notifies with valw's message; a cancel doesn't; a
-- failure without a message gets a generic one.
reset()
fake.answers["sleep 0.3 && valw toolbar --run"] = { exitCode = 1, stdout = "", stderr = "error: no outputs\n" }
fake.streams["(sleep 0.3 && valw toolbar --run"] = valwFailure("no outputs", 1)
button("mode.screen").props.onClick()
assert(calls.notify[1][2] == "error: no outputs", "failure notified")
assert(calls.notify[1][2] == "no outputs", "failure notified: " .. tostring(calls.notify[1][2]))
reset()
fake.answers["sleep 0.3 && valw toolbar --run"] = { exitCode = 3, stdout = "", stderr = "" }
fake.streams["(sleep 0.3 && valw toolbar --run"] = { "valw-exit:3" }
button("mode.window").props.onClick()
assert(#calls.notify == 0, "cancel is silent")
reset()
fake.streams["(sleep 0.3 && valw toolbar --run"] = { "valw-exit:143" }
button("mode.window").props.onClick()
assert(calls.notify[1][2] == "error.failed", "a generic message")
fake.streams["(sleep 0.3 && valw toolbar --run"] = nil
ok("capture results")
-- The timer and the toggles write through --set and re-render at once.
-- The timer and the toggles re-render at once and send every choice, so
-- two quick changes can't undo each other.
reset()
fake.answers["sleep 0.3 && valw toolbar --run"] = nil
select = findAll(rendered, function(n) return n.kind == "select" end)[1]
select.props.onChange("2")
assert(calls.run[1] == "valw toolbar --set timer=10", calls.run[1])
assert(
calls.run[1] == "valw toolbar --set mode=zoom --set timer=10 --set cursor=false --set preview=true --set sound=true",
calls.run[1]
)
select = findAll(rendered, function(n) return n.kind == "select" end)[1]
assert(select.props.selectedIndex == 2, "re-rendered with 10 s")
reset()
toggles = findAll(rendered, function(n) return n.kind == "toggle" end)
toggles[3].props.onChange("false")
assert(calls.run[1] == "valw toolbar --set sound=false", calls.run[1])
assert(
calls.run[1] == "valw toolbar --set mode=zoom --set timer=10 --set cursor=false --set preview=true --set sound=false",
calls.run[1]
)
toggles = findAll(rendered, function(n) return n.kind == "toggle" end)
assert(toggles[3].props.checked == false, "re-rendered with sound off")
reset()
fake.answers["valw toolbar --set"] = { exitCode = 1, stdout = "", stderr = "error: read-only\n" }
fake.answers["valw toolbar --set"] = { exitCode = 1, stdout = "", stderr = valwError("read-only file system") }
toggles[1].props.onChange("true")
assert(calls.run[1] == "valw toolbar --set cursor=true", calls.run[1])
assert(calls.notify[1][2] == "error: read-only", "a failed --set notifies")
assert(string.find(calls.run[1], "--set cursor=true", 1, true), calls.run[1])
assert(calls.notify[1][2] == "read-only file system", "a failed --set notifies")
ok("timer and toggles")