* feat(battery-threshold): add translations and rule file * feat(battery-threshold): add setup script * feat(battery-threshold): add plugin manifest * feat(battery-threshold): implement battery-threshold service * feat(battery-threshold): implement battery-threshold widget * feat(battery-threshold): implement battery-threshold panel * feat(battery-threshold): add readme * chore(battery-threshold): add dependencies field * chore(battery-threshold): add thumbnail * docs(battery-threshold): add thumbnail to readme * fix(battery-threshold): add thumbnail from generator * chore(battery-threshold): add license and icon fields to plugin.toml * style(battery-threshold): replace tabs with spaces * style(battery-threshold): unflatten translation files * refactor(battery-threshold): use translations for widget tooltip * chore(battery-threshold): replace raw strings with translations * chore(battery-threshold): remove panel ipc event * chore(battery-threshold): check error on file read * chore(battery-threshold): remove `setUpdateInterval` calls * style(battery-threshold): fix formatting * chore(battery-threshold): remove tags capital letters * Update plugin.toml * chore(battery-threshold): remove de fr and tr translations * chore(battery-threshold): update thumbnail * fix(battery-threshold): add shell quoting for runAsync * chore(battery-threshold): embed rule file content in setup script * chore(battery-threshold): update manifest * refactor(battery-threshold): use noctalia.pluginDataDir, log read/write errors * docs(battery-threshold): update README to match template * chore(battery-threshold): add missing dependencies to manifest --------- Co-authored-by: Lemmy <studio@quadbyte.net>
173 lines
4.9 KiB
Luau
173 lines
4.9 KiB
Luau
--!nonstrict
|
|
local is_open = false
|
|
|
|
local function render_panel()
|
|
if not is_open then
|
|
return
|
|
end
|
|
|
|
local is_available = noctalia.state.get("is_available") == true
|
|
local is_writable = noctalia.state.get("is_writable") == true
|
|
local threshold = noctalia.state.get("current_threshold") or 0
|
|
local model_name = noctalia.state.get("battery_model_name") or ""
|
|
|
|
local title_text = noctalia.tr("panel.title")
|
|
local sub_text = ""
|
|
if not is_available then
|
|
sub_text = noctalia.tr("panel.not-available")
|
|
else
|
|
sub_text = model_name
|
|
end
|
|
|
|
local hint_text = ""
|
|
local hint_color = "on_surface_variant"
|
|
if not is_writable then
|
|
hint_text = noctalia.tr("panel.read-only")
|
|
hint_color = "error"
|
|
else
|
|
hint_text = noctalia.tr("panel.adjust-limit")
|
|
end
|
|
|
|
local children = {
|
|
ui.row({ align = "center", justify = "space_between" }, {
|
|
ui.column({ gap = 2 }, {
|
|
ui.label({
|
|
text = title_text,
|
|
fontSize = 16,
|
|
fontWeight = "bold",
|
|
color = "primary",
|
|
}),
|
|
ui.label({
|
|
text = sub_text,
|
|
fontSize = 12,
|
|
color = "on_surface_variant",
|
|
}),
|
|
}),
|
|
ui.button({
|
|
glyph = "close",
|
|
variant = "ghost",
|
|
onClick = "onCloseClicked",
|
|
}),
|
|
}),
|
|
}
|
|
|
|
if is_available then
|
|
table.insert(
|
|
children,
|
|
ui.separator({ thickness = 1, color = "outline/0.3", spacing = 8 })
|
|
)
|
|
|
|
if is_writable then
|
|
table.insert(
|
|
children,
|
|
ui.column({ gap = 8 }, {
|
|
ui.row({ align = "center", justify = "space_between" }, {
|
|
ui.label({
|
|
text = title_text,
|
|
fontSize = 14,
|
|
color = "on_surface",
|
|
}),
|
|
ui.label({
|
|
text = tostring(threshold) .. "%",
|
|
fontSize = 16,
|
|
fontWeight = "bold",
|
|
color = "primary",
|
|
}),
|
|
}),
|
|
ui.row({ align = "center", gap = 8 }, {
|
|
ui.label({
|
|
text = "40%",
|
|
fontSize = 11,
|
|
color = "on_surface_variant",
|
|
}),
|
|
ui.slider({
|
|
min = 40,
|
|
max = 100,
|
|
step = 5,
|
|
value = threshold,
|
|
enabled = is_writable,
|
|
onChange = "onSliderChange",
|
|
}),
|
|
ui.label({
|
|
text = "100%",
|
|
fontSize = 11,
|
|
color = "on_surface_variant",
|
|
}),
|
|
}),
|
|
ui.label({
|
|
text = hint_text,
|
|
fontSize = 11,
|
|
color = hint_color,
|
|
textAlign = "center",
|
|
}),
|
|
})
|
|
)
|
|
else
|
|
table.insert(
|
|
children,
|
|
ui.column({ gap = 12, align = "center" }, {
|
|
ui.label({
|
|
text = hint_text,
|
|
fontSize = 12,
|
|
color = "error",
|
|
textAlign = "center",
|
|
maxLines = 2,
|
|
}),
|
|
ui.button({
|
|
text = noctalia.tr("panel.button"),
|
|
glyph = "shield-lock",
|
|
variant = "primary",
|
|
onClick = "onRunSetup",
|
|
}),
|
|
})
|
|
)
|
|
end
|
|
end
|
|
|
|
panel.render(ui.column({ gap = 12, padding = 12 }, children))
|
|
end
|
|
|
|
function onOpen(context: string?)
|
|
is_open = true
|
|
render_panel()
|
|
end
|
|
|
|
function onClose()
|
|
is_open = false
|
|
end
|
|
|
|
function onSliderChange(value: string)
|
|
local num = tonumber(value)
|
|
if num then
|
|
noctalia.state.set("set_threshold_request", num)
|
|
noctalia.state.set("current_threshold", num)
|
|
render_panel()
|
|
end
|
|
end
|
|
|
|
function onCloseClicked()
|
|
panel.close()
|
|
end
|
|
|
|
function onRunSetup()
|
|
noctalia.state.set("run_setup_request", true)
|
|
end
|
|
|
|
noctalia.state.watch("current_threshold", function()
|
|
if is_open then
|
|
render_panel()
|
|
end
|
|
end)
|
|
|
|
noctalia.state.watch("is_writable", function()
|
|
if is_open then
|
|
render_panel()
|
|
end
|
|
end)
|
|
|
|
noctalia.state.watch("is_available", function()
|
|
if is_open then
|
|
render_panel()
|
|
end
|
|
end)
|