style(nix-monitor): reformat with stylua

This commit is contained in:
avivbintangaringga
2026-07-16 16:38:52 +07:00
parent 132575905e
commit 486b106d2e
3 changed files with 384 additions and 370 deletions
-1
View File
@@ -45,7 +45,6 @@ function update()
end end
end end
end end
end end
function onClick() function onClick()
+11 -7
View File
@@ -53,8 +53,8 @@ local nixosGenerationsCmd = "nixos-rebuild list-generations | tail -n +2 | wc -l
local nixosCurrentGenCmd = "nixos-rebuild list-generations | grep True | awk '{print $1}'" local nixosCurrentGenCmd = "nixos-rebuild list-generations | grep True | awk '{print $1}'"
local hmGenerationsCmd = "home-manager generations | wc -l" local hmGenerationsCmd = "home-manager generations | wc -l"
local hmCurrentGenCmd = "home-manager generations | grep '(current)' | awk '{print $5}'" local hmCurrentGenCmd = "home-manager generations | grep '(current)' | awk '{print $5}'"
local storeSizeCmd = "du -s --block-size=1GiB /nix/store | awk '\{print $1 \" GiB\"\}'" local storeSizeCmd = "du -s --block-size=1GiB /nix/store | awk '{print $1 \" GiB\"}'"
local closureSizeCmd = "nix path-info --closure-size --human-readable /run/current-system | awk '\{print $2, $3\}'" local closureSizeCmd = "nix path-info --closure-size --human-readable /run/current-system | awk '{print $2, $3}'"
-- State inits -- State inits
setState("lastLocalCheckTime", os.time()) setState("lastLocalCheckTime", os.time())
@@ -190,8 +190,10 @@ function checkSystemStatsFile()
setState("closureSize", closureSize) setState("closureSize", closureSize)
end end
local success = typeof(storeSize) == "string" and storeSize ~= "" and local success = typeof(storeSize) == "string"
typeof(closureSize) == "string" and closureSize ~= "" and storeSize ~= ""
and typeof(closureSize) == "string"
and closureSize ~= ""
if success then if success then
setState("isSystemStatsCheckRunning", false) setState("isSystemStatsCheckRunning", false)
@@ -234,7 +236,7 @@ end)
function update() function update()
-- Check local hash every 10 seconds -- Check local hash every 10 seconds
if (os.time() - getState("lastLocalCheckTime") >= 10) then if os.time() - getState("lastLocalCheckTime") >= 10 then
checkLocalHash() checkLocalHash()
end end
@@ -252,8 +254,10 @@ function update()
end end
end end
if getState("localHash") ~= getState("remoteHash") and if
getState("localHash") ~= "n/a" and getState("remoteHash") ~= "n/a" getState("localHash") ~= getState("remoteHash")
and getState("localHash") ~= "n/a"
and getState("remoteHash") ~= "n/a"
then then
setState("isUpdateAvailable", true) setState("isUpdateAvailable", true)
+51 -40
View File
@@ -34,20 +34,20 @@ local function labelBox(subtext, text, glyph)
radius = 8, radius = 8,
align = "center", align = "center",
padding = 12, padding = 12,
justify = "space_between" justify = "space_between",
}, { }, {
ui.glyph({ ui.glyph({
name = glyph, name = glyph,
size = 30 size = 30,
}), }),
ui.label({ ui.label({
text = text, text = text,
fontWeight = "bold" fontWeight = "bold",
}), }),
ui.label({ ui.label({
text = subtext, text = subtext,
fontSize = 12, fontSize = 12,
fontWeight = "medium" fontWeight = "medium",
}), }),
}) })
end end
@@ -55,21 +55,27 @@ end
local function statLabel(text, glyph: string?) local function statLabel(text, glyph: string?)
local items = {} local items = {}
if glyph ~= nil then if glyph ~= nil then
table.insert(items, ui.glyph({ table.insert(
items,
ui.glyph({
name = glyph, name = glyph,
size = 16 size = 16,
})) })
)
end end
table.insert(items, ui.label({ table.insert(
items,
ui.label({
text = text, text = text,
fontSize = 12, fontSize = 12,
fontWeight = "semibold" fontWeight = "semibold",
})) })
)
return ui.row({ return ui.row({
gap = 8, gap = 8,
align = "center" align = "center",
}, items) }, items)
end end
@@ -77,67 +83,73 @@ local function render()
local buttons = {} local buttons = {}
if getState("isRemoteCheckRunning") then if getState("isRemoteCheckRunning") then
table.insert(buttons, ui.button({ table.insert(
buttons,
ui.button({
text = tr("panel.cancel"), text = tr("panel.cancel"),
glyph = "cancel", glyph = "cancel",
flexGrow = 1, flexGrow = 1,
variant = "destructive", variant = "destructive",
onClick = "onCancelClicked", onClick = "onCancelClicked",
})) })
)
else else
if getState("isUpdateAvailable") and not cfg("hide_update_button") then if getState("isUpdateAvailable") and not cfg("hide_update_button") then
table.insert(buttons, ui.button({ table.insert(
buttons,
ui.button({
text = tr("panel.update"), text = tr("panel.update"),
glyph = "progress-down", glyph = "progress-down",
flexGrow = 1, flexGrow = 1,
variant = "primary", variant = "primary",
onClick = "onUpdateClicked", onClick = "onUpdateClicked",
})) })
)
else else
table.insert(buttons, ui.button({ table.insert(
buttons,
ui.button({
text = tr("panel.check"), text = tr("panel.check"),
glyph = "search", glyph = "search",
flexGrow = 1, flexGrow = 1,
variant = "outline", variant = "outline",
onClick = "onCheckClicked", onClick = "onCheckClicked",
})) })
)
end end
end end
if not cfg("hide_clean_button") then if not cfg("hide_clean_button") then
table.insert(buttons, ui.button({ table.insert(
buttons,
ui.button({
text = tr("panel.clean"), text = tr("panel.clean"),
glyph = "trash", glyph = "trash",
flexGrow = 1, flexGrow = 1,
variant = "destructive", variant = "destructive",
onClick = "onCleanClicked", onClick = "onCleanClicked",
})) })
)
end end
local lastCheckTimeStr = getState("lastRemoteCheckTimeStr") local lastCheckTimeStr = getState("lastRemoteCheckTimeStr")
local generationItems = { local generationItems = {
statLabel(`SYS: {getState("nixosGenerations")}`, "device-desktop"), statLabel(`SYS: {getState("nixosGenerations")}`, "device-desktop"),
statLabel(`{tr("panel.current")}: {getState("nixosCurrentGen")}`, "device-desktop-check") statLabel(`{tr("panel.current")}: {getState("nixosCurrentGen")}`, "device-desktop-check"),
} }
if getState("hasHomeManager") and getState("hmGenerations") ~= "" if getState("hasHomeManager") and getState("hmGenerations") ~= "" and getState("hmCurrentGen") ~= "" then
and getState("hmCurrentGen") ~= "" then table.insert(generationItems, statLabel(`HM: {getState("hmGenerations")}`, "home"))
table.insert(generationItems,
statLabel(`HM: {getState("hmGenerations")}`, "home")
)
table.insert(generationItems, table.insert(generationItems, statLabel(`{tr("panel.current")}: {getState("hmCurrentGen")}`, "home-check"))
statLabel(`{tr("panel.current")}: {getState("hmCurrentGen")}`, "home-check")
)
end end
panel.render( panel.render(ui.column({
ui.column({
gap = 8, gap = 8,
}, { }, {
ui.row({ ui.row({
justify = "space_between", justify = "space_between",
align = "center" align = "center",
}, { }, {
ui.label({ ui.label({
text = tr("panel.title"), text = tr("panel.title"),
@@ -152,12 +164,12 @@ local function render()
ui.separator({ ui.separator({
thickness = 2, thickness = 2,
orientation = "horizontal", orientation = "horizontal",
spacing = 4 spacing = 4,
}), }),
ui.row({ ui.row({
gap = 8, gap = 8,
align = "center", align = "center",
justify = "space_between" justify = "space_between",
}, { }, {
labelBox(tr("panel.local"), getState("localHash"), "devices-pc"), labelBox(tr("panel.local"), getState("localHash"), "devices-pc"),
labelBox(tr("panel.remote"), getState("remoteHash"), "world"), labelBox(tr("panel.remote"), getState("remoteHash"), "world"),
@@ -165,7 +177,7 @@ local function render()
ui.separator({ ui.separator({
thickness = 2, thickness = 2,
orientation = "horizontal", orientation = "horizontal",
spacing = 4 spacing = 4,
}), }),
ui.row({ ui.row({
fill = getBackgroundColor(), fill = getBackgroundColor(),
@@ -192,19 +204,18 @@ local function render()
ui.separator({ ui.separator({
thickness = 2, thickness = 2,
orientation = "horizontal", orientation = "horizontal",
spacing = 4 spacing = 4,
}), }),
ui.label({ ui.label({
text = `{tr("panel.last_checked")}: {lastCheckTimeStr}`, text = `{tr("panel.last_checked")}: {lastCheckTimeStr}`,
fontSize = 12 fontSize = 12,
}), }),
ui.row({ ui.row({
gap = 8, gap = 8,
align = "center", align = "center",
justify = "space_between" justify = "space_between",
}, buttons) }, buttons),
}) }))
)
end end
-- State watcher -- State watcher