refactor: improve robustness and consistency across all scripts

- kb-blackout: optimize trim(), fix log units, add jit fallback
- ac-power: extract error handling helper, add capture_stderr,
  validate timeout, add security note, rename CONFIG to config
- touch-gestures: add min_brightness config, optimize brightnessctl
  to single call, improve wpctl regex, add shutdown handler
This commit is contained in:
2025-12-06 19:58:30 +01:00
parent 4e90c445f7
commit 749bed7dfb
3 changed files with 216 additions and 107 deletions

View File

@@ -30,7 +30,7 @@ local config = {
local mp = require("mp")
local msg = require("mp.msg")
local utils = require("mp.utils")
local jit = rawget(_G, "jit")
local jit = rawget(_G, "jit") or {}
local function coerce_boolean(value, default)
if type(value) == "boolean" then
@@ -137,7 +137,7 @@ if unsupported_platform() then
end
local function trim(str)
return (str and str:gsub("^%s+", ""):gsub("%s+$", "")) or ""
return str and str:match("^%s*(.-)%s*$") or ""
end
local function build_brightnessctl_args(extra)
@@ -315,8 +315,9 @@ end
local function schedule_timer()
cancel_timer()
state.timer = mp.add_timeout(seconds(config.timeout_ms), arm_disable_callback)
msg.verbose(("Inactivity timer armed for %.0f ms"):format(config.timeout_ms))
local delay = seconds(config.timeout_ms)
state.timer = mp.add_timeout(delay, arm_disable_callback)
msg.verbose(("Inactivity timer armed for %.1f s"):format(delay))
end
local function restore_backlight(reason)