docs: sync shortcut.luau in plan with review fixes
This commit is contained in:
1 parent
03b72d8a78
commit
919118be55
1 file changed
+38
-2
@@ -1025,6 +1025,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")
|
||||
@@ -1039,7 +1041,7 @@ end
|
||||
local function currentSidetone()
|
||||
local v = noctalia.state.get("sidetone")
|
||||
if v ~= nil then return v end
|
||||
return noctalia.getConfig("sidetone_default")
|
||||
return noctalia.getConfig("sidetone_default") or 64
|
||||
end
|
||||
|
||||
local function apply(value)
|
||||
@@ -1055,6 +1057,7 @@ local function apply(value)
|
||||
end
|
||||
|
||||
function onClick()
|
||||
if not capsSidetone or errorState ~= "" then return end
|
||||
if on then
|
||||
apply(0)
|
||||
else
|
||||
@@ -1062,12 +1065,45 @@ function onClick()
|
||||
end
|
||||
end
|
||||
|
||||
noctalia.state.watch("battery", function(v) battery = v; render() 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
|
||||
|
||||
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()
|
||||
```
|
||||
|
||||
> Review notes: `on` syncs with the shared `sidetone` state on load and via a watcher, so entry hot-reloads no longer invert the toggle and panel changes propagate. `onClick` is gated on `caps.sidetone` and a clean `error` state. `capsSidetone`/`errorState` must be declared BEFORE `onClick` (a forward reference to a `local` inside a function body resolves to a global nil in Lua/Luau and would disable the gate).
|
||||
|
||||
- [ ] **Step 2: Verify the shortcut renders (hot-reload)**
|
||||
|
||||
Open the control center. The tile labeled "Sidetone off" (or "Sidetone on" after enabling) with a music icon should be present. Clicking toggles sidetone (mock mode: toggles state without touching hardware).
|
||||
|
||||
Reference in new issue
Block a user