docs: sync service.luau in plan with review fixes
This commit is contained in:
1 parent
213dfa30a6
commit
d77dc7eff4
1 file changed
+18
-16
@@ -464,7 +464,7 @@ local function publishCaps(info)
|
||||
if info == nil then
|
||||
noctalia.state.set("caps", {})
|
||||
noctalia.state.set("equalizerPresets", 0)
|
||||
noctalia.state.set("device", nil)
|
||||
noctalia.state.set("error", "no_caps")
|
||||
return
|
||||
end
|
||||
noctalia.state.set("caps", info.caps or {})
|
||||
@@ -474,28 +474,34 @@ local function publishCaps(info)
|
||||
product = info.product,
|
||||
vendor = info.vendor,
|
||||
})
|
||||
noctalia.state.set("error", "")
|
||||
end
|
||||
|
||||
local function handleStatus(status)
|
||||
if status == nil then
|
||||
local err = noctalia.state.get("error")
|
||||
if err == "no_binary" then
|
||||
return
|
||||
end
|
||||
noctalia.state.set("error", "unavailable")
|
||||
noctalia.state.set("battery", { status = "BATTERY_UNAVAILABLE", level = -1 })
|
||||
noctalia.state.set("chatmix", 0)
|
||||
return
|
||||
end
|
||||
noctalia.state.set("error", "")
|
||||
local battery = status.battery
|
||||
local battery = status.battery or { status = "BATTERY_UNAVAILABLE", level = -1 }
|
||||
noctalia.state.set("battery", battery)
|
||||
noctalia.state.set("chatmix", status.chatmix)
|
||||
noctalia.state.set("chatmix", status.chatmix or 0)
|
||||
noctalia.state.set("lastUpdate", noctalia.nowMs())
|
||||
if battery.level and battery.level > 0 and battery.status ~= "BATTERY_UNAVAILABLE" then
|
||||
local low = config().battery_low
|
||||
if battery.level ~= nil and battery.level >= 0 and battery.status ~= "BATTERY_UNAVAILABLE" then
|
||||
local low = config().battery_low or 20
|
||||
if battery.level <= low and not warned then
|
||||
warned = true
|
||||
noctalia.notifyError(
|
||||
noctalia.tr("notify.battery_low.title"),
|
||||
string.format(noctalia.tr("notify.battery_low.body"), battery.level)
|
||||
)
|
||||
elseif battery.level > low + 5 then
|
||||
elseif battery.level > low + 5 or battery.status == "BATTERY_CHARGING" or battery.status == "BATTERY_FULL" then
|
||||
warned = false
|
||||
end
|
||||
end
|
||||
@@ -508,14 +514,18 @@ end
|
||||
local function init()
|
||||
local cfg = config()
|
||||
hsc.init(cfg)
|
||||
warned = false
|
||||
if not hsc.isMock() and not noctalia.commandExists("headsetcontrol") then
|
||||
noctalia.state.set("error", "no_binary")
|
||||
noctalia.state.set("caps", {})
|
||||
noctalia.state.set("equalizerPresets", 0)
|
||||
noctalia.state.set("battery", { status = "BATTERY_UNAVAILABLE", level = -1 })
|
||||
noctalia.state.set("chatmix", 0)
|
||||
noctalia.log("headsetcontrol binary not found; polling disabled")
|
||||
return
|
||||
end
|
||||
hsc.fetchCapabilities(publishCaps)
|
||||
noctalia.setUpdateInterval(cfg.poll_interval * 1000)
|
||||
noctalia.setUpdateInterval((cfg.poll_interval or 60) * 1000)
|
||||
poll()
|
||||
end
|
||||
|
||||
@@ -533,18 +543,10 @@ function onIpc(event, _payload)
|
||||
end
|
||||
end
|
||||
|
||||
function onExit(_signal, reason)
|
||||
if reason == "uninstall" or reason == "disable" then
|
||||
noctalia.state.set("error", "")
|
||||
noctalia.state.set("battery", nil)
|
||||
noctalia.state.set("caps", {})
|
||||
end
|
||||
end
|
||||
|
||||
init()
|
||||
```
|
||||
|
||||
> Note: clearing `error` with `""` (not `nil`) because state values should stay within the documented plain-value types; `battery`/`device` are cleared with `nil` on the documented teardown paths only. Widgets/Panels treat `""` as "no error".
|
||||
> Review-approved deviations from the original plan: no `onExit` block (the state channel is process-lifetime and cleared on stop, so teardown clearing is unnecessary); no `state.set(key, nil)` (undocumented for state); low-battery re-arm also triggers on `BATTERY_CHARGING`/`BATTERY_FULL`; `no_binary` is preserved in `handleStatus(nil)`; `publishCaps` success clears `error` to `""`; battery warning fires at 0% (guard `level ~= nil and level >= 0`); config reads use `or` defaults; `warned` resets in `init()`.
|
||||
|
||||
- [ ] **Step 2: Enable the plugin and verify the service boots**
|
||||
|
||||
|
||||
Reference in new issue
Block a user