style(nix-monitor): reformat with stylua
This commit is contained in:
@@ -45,7 +45,6 @@ function update()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function onClick()
|
||||
|
||||
@@ -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 hmGenerationsCmd = "home-manager generations | wc -l"
|
||||
local hmCurrentGenCmd = "home-manager generations | grep '(current)' | awk '{print $5}'"
|
||||
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 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}'"
|
||||
|
||||
-- State inits
|
||||
setState("lastLocalCheckTime", os.time())
|
||||
@@ -190,8 +190,10 @@ function checkSystemStatsFile()
|
||||
setState("closureSize", closureSize)
|
||||
end
|
||||
|
||||
local success = typeof(storeSize) == "string" and storeSize ~= "" and
|
||||
typeof(closureSize) == "string" and closureSize ~= ""
|
||||
local success = typeof(storeSize) == "string"
|
||||
and storeSize ~= ""
|
||||
and typeof(closureSize) == "string"
|
||||
and closureSize ~= ""
|
||||
|
||||
if success then
|
||||
setState("isSystemStatsCheckRunning", false)
|
||||
@@ -234,7 +236,7 @@ end)
|
||||
|
||||
function update()
|
||||
-- Check local hash every 10 seconds
|
||||
if (os.time() - getState("lastLocalCheckTime") >= 10) then
|
||||
if os.time() - getState("lastLocalCheckTime") >= 10 then
|
||||
checkLocalHash()
|
||||
end
|
||||
|
||||
@@ -252,8 +254,10 @@ function update()
|
||||
end
|
||||
end
|
||||
|
||||
if getState("localHash") ~= getState("remoteHash") and
|
||||
getState("localHash") ~= "n/a" and getState("remoteHash") ~= "n/a"
|
||||
if
|
||||
getState("localHash") ~= getState("remoteHash")
|
||||
and getState("localHash") ~= "n/a"
|
||||
and getState("remoteHash") ~= "n/a"
|
||||
then
|
||||
setState("isUpdateAvailable", true)
|
||||
|
||||
|
||||
+51
-40
@@ -34,20 +34,20 @@ local function labelBox(subtext, text, glyph)
|
||||
radius = 8,
|
||||
align = "center",
|
||||
padding = 12,
|
||||
justify = "space_between"
|
||||
justify = "space_between",
|
||||
}, {
|
||||
ui.glyph({
|
||||
name = glyph,
|
||||
size = 30
|
||||
size = 30,
|
||||
}),
|
||||
ui.label({
|
||||
text = text,
|
||||
fontWeight = "bold"
|
||||
fontWeight = "bold",
|
||||
}),
|
||||
ui.label({
|
||||
text = subtext,
|
||||
fontSize = 12,
|
||||
fontWeight = "medium"
|
||||
fontWeight = "medium",
|
||||
}),
|
||||
})
|
||||
end
|
||||
@@ -55,21 +55,27 @@ end
|
||||
local function statLabel(text, glyph: string?)
|
||||
local items = {}
|
||||
if glyph ~= nil then
|
||||
table.insert(items, ui.glyph({
|
||||
table.insert(
|
||||
items,
|
||||
ui.glyph({
|
||||
name = glyph,
|
||||
size = 16
|
||||
}))
|
||||
size = 16,
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
table.insert(items, ui.label({
|
||||
table.insert(
|
||||
items,
|
||||
ui.label({
|
||||
text = text,
|
||||
fontSize = 12,
|
||||
fontWeight = "semibold"
|
||||
}))
|
||||
fontWeight = "semibold",
|
||||
})
|
||||
)
|
||||
|
||||
return ui.row({
|
||||
gap = 8,
|
||||
align = "center"
|
||||
align = "center",
|
||||
}, items)
|
||||
end
|
||||
|
||||
@@ -77,67 +83,73 @@ local function render()
|
||||
local buttons = {}
|
||||
|
||||
if getState("isRemoteCheckRunning") then
|
||||
table.insert(buttons, ui.button({
|
||||
table.insert(
|
||||
buttons,
|
||||
ui.button({
|
||||
text = tr("panel.cancel"),
|
||||
glyph = "cancel",
|
||||
flexGrow = 1,
|
||||
variant = "destructive",
|
||||
onClick = "onCancelClicked",
|
||||
}))
|
||||
})
|
||||
)
|
||||
else
|
||||
if getState("isUpdateAvailable") and not cfg("hide_update_button") then
|
||||
table.insert(buttons, ui.button({
|
||||
table.insert(
|
||||
buttons,
|
||||
ui.button({
|
||||
text = tr("panel.update"),
|
||||
glyph = "progress-down",
|
||||
flexGrow = 1,
|
||||
variant = "primary",
|
||||
onClick = "onUpdateClicked",
|
||||
}))
|
||||
})
|
||||
)
|
||||
else
|
||||
table.insert(buttons, ui.button({
|
||||
table.insert(
|
||||
buttons,
|
||||
ui.button({
|
||||
text = tr("panel.check"),
|
||||
glyph = "search",
|
||||
flexGrow = 1,
|
||||
variant = "outline",
|
||||
onClick = "onCheckClicked",
|
||||
}))
|
||||
})
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
if not cfg("hide_clean_button") then
|
||||
table.insert(buttons, ui.button({
|
||||
table.insert(
|
||||
buttons,
|
||||
ui.button({
|
||||
text = tr("panel.clean"),
|
||||
glyph = "trash",
|
||||
flexGrow = 1,
|
||||
variant = "destructive",
|
||||
onClick = "onCleanClicked",
|
||||
}))
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
local lastCheckTimeStr = getState("lastRemoteCheckTimeStr")
|
||||
local generationItems = {
|
||||
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") ~= ""
|
||||
and getState("hmCurrentGen") ~= "" then
|
||||
table.insert(generationItems,
|
||||
statLabel(`HM: {getState("hmGenerations")}`, "home")
|
||||
)
|
||||
if getState("hasHomeManager") and getState("hmGenerations") ~= "" and getState("hmCurrentGen") ~= "" then
|
||||
table.insert(generationItems, statLabel(`HM: {getState("hmGenerations")}`, "home"))
|
||||
|
||||
table.insert(generationItems,
|
||||
statLabel(`{tr("panel.current")}: {getState("hmCurrentGen")}`, "home-check")
|
||||
)
|
||||
table.insert(generationItems, statLabel(`{tr("panel.current")}: {getState("hmCurrentGen")}`, "home-check"))
|
||||
end
|
||||
|
||||
panel.render(
|
||||
ui.column({
|
||||
panel.render(ui.column({
|
||||
gap = 8,
|
||||
}, {
|
||||
ui.row({
|
||||
justify = "space_between",
|
||||
align = "center"
|
||||
align = "center",
|
||||
}, {
|
||||
ui.label({
|
||||
text = tr("panel.title"),
|
||||
@@ -152,12 +164,12 @@ local function render()
|
||||
ui.separator({
|
||||
thickness = 2,
|
||||
orientation = "horizontal",
|
||||
spacing = 4
|
||||
spacing = 4,
|
||||
}),
|
||||
ui.row({
|
||||
gap = 8,
|
||||
align = "center",
|
||||
justify = "space_between"
|
||||
justify = "space_between",
|
||||
}, {
|
||||
labelBox(tr("panel.local"), getState("localHash"), "devices-pc"),
|
||||
labelBox(tr("panel.remote"), getState("remoteHash"), "world"),
|
||||
@@ -165,7 +177,7 @@ local function render()
|
||||
ui.separator({
|
||||
thickness = 2,
|
||||
orientation = "horizontal",
|
||||
spacing = 4
|
||||
spacing = 4,
|
||||
}),
|
||||
ui.row({
|
||||
fill = getBackgroundColor(),
|
||||
@@ -192,19 +204,18 @@ local function render()
|
||||
ui.separator({
|
||||
thickness = 2,
|
||||
orientation = "horizontal",
|
||||
spacing = 4
|
||||
spacing = 4,
|
||||
}),
|
||||
ui.label({
|
||||
text = `{tr("panel.last_checked")}: {lastCheckTimeStr}`,
|
||||
fontSize = 12
|
||||
fontSize = 12,
|
||||
}),
|
||||
ui.row({
|
||||
gap = 8,
|
||||
align = "center",
|
||||
justify = "space_between"
|
||||
}, buttons)
|
||||
})
|
||||
)
|
||||
justify = "space_between",
|
||||
}, buttons),
|
||||
}))
|
||||
end
|
||||
|
||||
-- State watcher
|
||||
|
||||
Reference in New Issue
Block a user