From a0597ec3916295d3013c51acb7aaefcac102edc0 Mon Sep 17 00:00:00 2001 From: Yocraft-2000 <304616174+Yocraft-2000@users.noreply.github.com> Date: Sat, 15 Aug 2026 18:14:01 +0200 Subject: [PATCH 1/7] chore: dump version and api --- battery-widget/plugin.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/battery-widget/plugin.toml b/battery-widget/plugin.toml index 8f6b3360..12bf4fad 100644 --- a/battery-widget/plugin.toml +++ b/battery-widget/plugin.toml @@ -1,7 +1,7 @@ id = "yocraft/battery-widget" name = "Battery Widget" -version = "2.0.1" -plugin_api = 3 +version = "2.1.0" +plugin_api = 26 author = "yocraft" license = "MIT" deprecated = false From fef38ac955853d1bb5b62598b36534b660744ab4 Mon Sep 17 00:00:00 2001 From: Yocraft-2000 <304616174+Yocraft-2000@users.noreply.github.com> Date: Sat, 15 Aug 2026 18:14:58 +0200 Subject: [PATCH 2/7] refactor: use new getSetting from api 26 --- battery-widget/widget.luau | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/battery-widget/widget.luau b/battery-widget/widget.luau index 83445f02..78692666 100644 --- a/battery-widget/widget.luau +++ b/battery-widget/widget.luau @@ -3,7 +3,7 @@ local color local data = { percent = 0, status = "unknown" } local label_content = noctalia.getConfig("label_content") -local warning_threshold = 10 +local warning_threshold = noctalia.getSetting("battery.warning_threshold") or 10 local path = "/sys/class/power_supply/" local batName @@ -102,32 +102,6 @@ local function getGlyph() end end -local function getWarningThreshold() - noctalia.runAsync( - "grep warning_threshold ~/.local/state/noctalia/settings.toml | awk '{print $3}'", - function(result) - if result.exitCode ~= 0 then - noctalia.log("battery-widget: failed to get warning_threshold: " .. result.stderr) - return - end - - local res = result.stdout - - if not res then - noctalia.log("battery-widget: invalid warning_threshold, keeping default") - return - end - - local parsed = tonumber(noctalia.string.trim(res)) - if parsed then - warning_threshold = parsed - else - noctalia.log("battery-widget: invalid warning_threshold, keeping default") - end - end - ) -end - local function getColor() if data.status == "charging" or data.status == "fully-charged" or data.status == "pending-charge" then color = noctalia.getConfig("charging_color") @@ -271,7 +245,5 @@ if not batName then return end -getWarningThreshold() - initData() watchBattery() From 111852dcaccfb13ce1fe1f046ed54c24f1106d62 Mon Sep 17 00:00:00 2001 From: Yocraft-2000 <304616174+Yocraft-2000@users.noreply.github.com> Date: Sat, 15 Aug 2026 18:30:01 +0200 Subject: [PATCH 3/7] refactor: improve readability and call getConfig only at initialization instead of on each render --- battery-widget/widget.luau | 40 ++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/battery-widget/widget.luau b/battery-widget/widget.luau index 78692666..8667f0be 100644 --- a/battery-widget/widget.luau +++ b/battery-widget/widget.luau @@ -2,8 +2,18 @@ local glyph local color local data = { percent = 0, status = "unknown" } -local label_content = noctalia.getConfig("label_content") -local warning_threshold = noctalia.getSetting("battery.warning_threshold") or 10 +local config = { + warning_threshold = noctalia.getSetting("battery.warning_threshold") or 10, + layout = noctalia.getConfig("layout"), + show_glyph = noctalia.getConfig("show_glyph"), + show_label = noctalia.getConfig("show_label"), + label_content = noctalia.getConfig("label_content"), + hide_plugged = noctalia.getConfig("hide_plugged"), + hide_full = noctalia.getConfig("hide_full"), + color = noctalia.getConfig("color"), + warning_color = noctalia.getConfig("warning_color"), + charging_color = noctalia.getConfig("charging_color"), +} local path = "/sys/class/power_supply/" local batName @@ -45,7 +55,7 @@ local function parse(output) data.status = stateMap[tonumber(state)] or "unknown" end - if label_content == "time" then + if config.label_content == "time" then local timeToEmpty = output:match("'TimeToEmpty':%s*") if timeToEmpty then data.timeToEmpty = tonumber(timeToEmpty) @@ -55,7 +65,7 @@ local function parse(output) if timeToFull then data.timeToFull = tonumber(timeToFull) end - elseif label_content == "rate" then + elseif config.label_content == "rate" then local rate = output:match("'EnergyRate':%s*<([%-%d%.]+)>") if rate then data.rate = tonumber(rate) @@ -104,14 +114,14 @@ end local function getColor() if data.status == "charging" or data.status == "fully-charged" or data.status == "pending-charge" then - color = noctalia.getConfig("charging_color") + color = config.charging_color return end - if data.percent <= warning_threshold then - color = noctalia.getConfig("warning_color") + if data.percent <= config.warning_threshold then + color = config.warning_color return end - color = noctalia.getConfig("color") + color = config.color end local function formatTime(seconds) @@ -144,11 +154,11 @@ local function formatPercent() end local function getLabelText() - if label_content == "time" then + if config.label_content == "time" then local connected = data.status == "charging" or data.status == "fully-charged" or data.status == "pending-charge" local seconds = connected and data.timeToFull or data.timeToEmpty return formatTime(seconds) or formatPercent() - elseif label_content == "rate" then + elseif config.label_content == "rate" then return formatRate(data.rate) or formatPercent() end @@ -156,21 +166,21 @@ local function getLabelText() end local function render() - if (noctalia.getConfig("hide_plugged") and (data.status == "charging" or data.status == "pending-charge")) - or (noctalia.getConfig("hide_full") and data.status == "fully-charged") then + if (config.hide_plugged and (data.status == "charging" or data.status == "pending-charge")) + or (config.hide_full and data.status == "fully-charged") then desktopWidget.render(ui.row()) return end local content = {} - if noctalia.getConfig("show_glyph") then + if config.show_glyph then table.insert(content, ui.glyph({ name = glyph, color = color })) end - if noctalia.getConfig("show_label") then + if config.show_label then table.insert(content, ui.label({ text = getLabelText(), color = color })) end - local vertical = noctalia.getConfig("layout") == "vertical" + local vertical = config.layout == "vertical" local layout = vertical and ui.column or ui.row From de2260ea98fdac11cedfbfef357e0000983f3955 Mon Sep 17 00:00:00 2001 From: Yocraft-2000 <304616174+Yocraft-2000@users.noreply.github.com> Date: Sat, 15 Aug 2026 18:34:32 +0200 Subject: [PATCH 4/7] fix: fallback default on getConfig --- battery-widget/widget.luau | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/battery-widget/widget.luau b/battery-widget/widget.luau index 8667f0be..438e937c 100644 --- a/battery-widget/widget.luau +++ b/battery-widget/widget.luau @@ -4,15 +4,15 @@ local data = { percent = 0, status = "unknown" } local config = { warning_threshold = noctalia.getSetting("battery.warning_threshold") or 10, - layout = noctalia.getConfig("layout"), - show_glyph = noctalia.getConfig("show_glyph"), - show_label = noctalia.getConfig("show_label"), - label_content = noctalia.getConfig("label_content"), - hide_plugged = noctalia.getConfig("hide_plugged"), - hide_full = noctalia.getConfig("hide_full"), - color = noctalia.getConfig("color"), - warning_color = noctalia.getConfig("warning_color"), - charging_color = noctalia.getConfig("charging_color"), + layout = noctalia.getConfig("layout") or "horizontal", + show_glyph = noctalia.getConfig("show_glyph") or true, + show_label = noctalia.getConfig("show_label") or true, + label_content = noctalia.getConfig("label_content") or "percent", + hide_plugged = noctalia.getConfig("hide_plugged") or false, + hide_full = noctalia.getConfig("hide_full") or false, + color = noctalia.getConfig("color") or "on_surface", + warning_color = noctalia.getConfig("warning_color") or "error", + charging_color = noctalia.getConfig("charging_color") or "on_surface", } local path = "/sys/class/power_supply/" @@ -76,12 +76,12 @@ local function parse(output) end local function getBatName() - local config = noctalia.getConfig("battery") + local config = noctalia.getConfig("battery") or "auto" if config == "bat0" then return "BAT0" elseif config == "custom" then - return noctalia.getConfig("battery_name") + return noctalia.getConfig("battery_name") or "BAT0" end local folders = noctalia.listDir(path) From 8a45dcd44e01a794274f15e3a52358a439f9c9cb Mon Sep 17 00:00:00 2001 From: Yocraft-2000 <304616174+Yocraft-2000@users.noreply.github.com> Date: Sat, 15 Aug 2026 18:50:18 +0200 Subject: [PATCH 5/7] chore: update plugin description --- battery-widget/README.md | 2 +- battery-widget/plugin.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/battery-widget/README.md b/battery-widget/README.md index da2e6f60..5502fd70 100644 --- a/battery-widget/README.md +++ b/battery-widget/README.md @@ -1,6 +1,6 @@ # Battery Widget -Desktop/lockscreen widget that displays the current battery level and charging status. +Desktop/Lockscreen widget that displays battery level, status, charging rate, and time remaining. ## Plugin diff --git a/battery-widget/plugin.toml b/battery-widget/plugin.toml index 12bf4fad..3bb0853b 100644 --- a/battery-widget/plugin.toml +++ b/battery-widget/plugin.toml @@ -6,7 +6,7 @@ author = "yocraft" license = "MIT" deprecated = false icon = "battery" -description = "Desktop/Lockscreen widget to show battery." +description = "Desktop/Lockscreen widget that displays battery level, status, charging rate, and time remaining." tags = [ "desktop", "hardware", "system", "utility" ] dependencies = [ "upower", "gdbus" ] From 07321923c689f3849cd0a0867a8119ccb03d6961 Mon Sep 17 00:00:00 2001 From: Yocraft-2000 <304616174+Yocraft-2000@users.noreply.github.com> Date: Sat, 15 Aug 2026 21:10:57 +0200 Subject: [PATCH 6/7] fix: update watchBattery to new config syntax --- battery-widget/widget.luau | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/battery-widget/widget.luau b/battery-widget/widget.luau index 438e937c..00e943c4 100644 --- a/battery-widget/widget.luau +++ b/battery-widget/widget.luau @@ -225,10 +225,10 @@ end local function watchBattery() local patterns = { "Percentage", "State" } - if label_content == "time" then + if config.label_content == "time" then table.insert(patterns, "TimeToEmpty") table.insert(patterns, "TimeToFull") - elseif label_content == "rate" then + elseif config.label_content == "rate" then table.insert(patterns, "EnergyRate") end From a087be4560d544ab48d7e58e2ab47650b810d3b3 Mon Sep 17 00:00:00 2001 From: Yocraft-2000 <304616174+Yocraft-2000@users.noreply.github.com> Date: Sat, 15 Aug 2026 21:31:27 +0200 Subject: [PATCH 7/7] fix: fallback breaking boolean configs --- battery-widget/widget.luau | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/battery-widget/widget.luau b/battery-widget/widget.luau index 00e943c4..ca1b4689 100644 --- a/battery-widget/widget.luau +++ b/battery-widget/widget.luau @@ -2,17 +2,26 @@ local glyph local color local data = { percent = 0, status = "unknown" } +local function getConf(key, default) + local value = noctalia.getConfig(key) + if value == nil then + return default + else + return value + end +end + local config = { warning_threshold = noctalia.getSetting("battery.warning_threshold") or 10, - layout = noctalia.getConfig("layout") or "horizontal", - show_glyph = noctalia.getConfig("show_glyph") or true, - show_label = noctalia.getConfig("show_label") or true, - label_content = noctalia.getConfig("label_content") or "percent", - hide_plugged = noctalia.getConfig("hide_plugged") or false, - hide_full = noctalia.getConfig("hide_full") or false, - color = noctalia.getConfig("color") or "on_surface", - warning_color = noctalia.getConfig("warning_color") or "error", - charging_color = noctalia.getConfig("charging_color") or "on_surface", + layout = getConf("layout", "horizontal"), + show_glyph = getConf("show_glyph", true), + show_label = getConf("show_label", true), + label_content = getConf("label_content", "percent"), + hide_plugged = getConf("hide_plugged", false), + hide_full = getConf("hide_full", false), + color = getConf("color", "on_surface"), + warning_color = getConf("warning_color", "error"), + charging_color = getConf("charging_color", "on_surface"), } local path = "/sys/class/power_supply/" @@ -43,8 +52,6 @@ if not noctalia.commandExists("gdbus") then end local function parse(output) - data = data or {} - local percent = output:match("'Percentage':%s*<([%d%.]+)>") if percent then data.percent = tonumber(percent) or 0