fix: shortcut syncs on/off with shared sidetone state and gates on capability

This commit is contained in:
loki committed 2026-08-31 14:26:51 +02:00
1 parent 3e950a848b
commit 03b72d8a78
1 file changed
+35 -1
+35 -1
View File
@@ -2,6 +2,8 @@ local hsc = require("./lib/hsc.luau")
local on = false
local battery = nil
local capsSidetone = false
local errorState = ""
local function render()
local label = on and noctalia.tr("shortcut.on") or noctalia.tr("shortcut.off")
@@ -31,7 +33,34 @@ local function apply(value)
end)
end
local function syncState()
local v = noctalia.state.get("caps")
if v then capsSidetone = v.sidetone == true end
v = noctalia.state.get("error")
if v ~= nil then errorState = v end
v = noctalia.state.get("sidetone")
if v ~= nil then
on = v > 0
end
end
function onCapsChanged(v)
capsSidetone = v ~= nil and v.sidetone == true or false
end
function onErrorChanged(v)
errorState = v or ""
end
function onSidetoneChanged(v)
if v ~= nil then
on = v > 0
render()
end
end
function onClick()
if not capsSidetone or errorState ~= "" then return end
if on then
apply(0)
else
@@ -39,7 +68,12 @@ function onClick()
end
end
noctalia.state.watch("battery", function(v) battery = v; render() end)
noctalia.state.watch("battery", function(v) battery = v or battery; render() end)
noctalia.state.watch("caps", onCapsChanged)
noctalia.state.watch("error", onErrorChanged)
noctalia.state.watch("sidetone", onSidetoneChanged)
local b = noctalia.state.get("battery")
if b then battery = b end
syncState()
render()