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
+30 -31
View File
@@ -1,53 +1,52 @@
function tr(key) function tr(key)
return noctalia.tr(key) return noctalia.tr(key)
end end
function cfg(key) function cfg(key)
return noctalia.getConfig(key) return noctalia.getConfig(key)
end end
function getState(key) function getState(key)
return noctalia.state.get(key) return noctalia.state.get(key)
end end
function displayWidget(glyph: string, text: string, color: string?) function displayWidget(glyph: string, text: string, color: string?)
local _color = color or "on_surface" local _color = color or "on_surface"
if cfg("colorize_text") then if cfg("colorize_text") then
barWidget.setColor(_color) barWidget.setColor(_color)
end end
if cfg("colorize_glyph") then if cfg("colorize_glyph") then
barWidget.setGlyphColor(_color) barWidget.setGlyphColor(_color)
end end
if cfg("show_glyph") then if cfg("show_glyph") then
barWidget.setGlyph(glyph) barWidget.setGlyph(glyph)
end end
if cfg("show_text") then if cfg("show_text") then
barWidget.setText(text) barWidget.setText(text)
end end
end end
-- Hooks -- Hooks
function update() function update()
if getState("isRemoteCheckRunning") then if getState("isRemoteCheckRunning") then
displayWidget(cfg("checking_glyph"), tr("bar.checking"), cfg("checking_color")) displayWidget(cfg("checking_glyph"), tr("bar.checking"), cfg("checking_color"))
else else
if getState("isUpdateAvailable") then if getState("isUpdateAvailable") then
displayWidget(cfg("update_available_glyph"), tr("bar.update_available"), cfg("update_available_color")) displayWidget(cfg("update_available_glyph"), tr("bar.update_available"), cfg("update_available_color"))
else else
if getState("localHash") == "n/a" or getState("remoteHash") == "n/a" then if getState("localHash") == "n/a" or getState("remoteHash") == "n/a" then
displayWidget(cfg("unknown_glyph"), tr("bar.unknown"), cfg("unknown_color")) displayWidget(cfg("unknown_glyph"), tr("bar.unknown"), cfg("unknown_color"))
else else
displayWidget(cfg("up_to_date_glyph"), tr("bar.up_to_date"), cfg("up_to_date_color")) displayWidget(cfg("up_to_date_glyph"), tr("bar.up_to_date"), cfg("up_to_date_color"))
end end
end end
end end
end end
function onClick() function onClick()
noctalia.togglePanel("avivbintangaringga/nix-monitor:panel") noctalia.togglePanel("avivbintangaringga/nix-monitor:panel")
end end
+148 -144
View File
@@ -2,34 +2,34 @@ noctalia.setUpdateInterval(1000)
-- Helper functions -- Helper functions
function tr(key) function tr(key)
return noctalia.tr(key) return noctalia.tr(key)
end end
function cfg(key) function cfg(key)
return noctalia.getConfig(key) return noctalia.getConfig(key)
end end
function getState(key) function getState(key)
return noctalia.state.get(key) return noctalia.state.get(key)
end end
function setState(key, val) function setState(key, val)
noctalia.state.set(key, val) noctalia.state.set(key, val)
end end
function watchState(key, cb) function watchState(key, cb)
noctalia.state.watch(key, cb) noctalia.state.watch(key, cb)
end end
function killWithPidFile(file) function killWithPidFile(file)
if noctalia.fileExists(file) then if noctalia.fileExists(file) then
local pid = noctalia.string.trim(noctalia.readFile(file)) local pid = noctalia.string.trim(noctalia.readFile(file))
if type(pid) == "string" and pid ~= "" then if type(pid) == "string" and pid ~= "" then
noctalia.runAsync(`pkill -9 -P {pid} && kill -9 {pid}`) noctalia.runAsync(`pkill -9 -P {pid} && kill -9 {pid}`)
end end
noctalia.removeFile(file) noctalia.removeFile(file)
end end
end end
-- Vars -- Vars
@@ -47,14 +47,14 @@ local storePidFile = stateDir .. "/storeSize.pid"
local closurePidFile = stateDir .. "/closureSize.pid" local closurePidFile = stateDir .. "/closureSize.pid"
local showUpdateAvailableNotification = true local showUpdateAvailableNotification = true
local localHashCmd = "nixos-version --hash 2> /dev/null | cut -c -7" local localHashCmd = "nixos-version --hash 2> /dev/null | cut -c -7"
local remoteHashCmd = "git ls-remote https://github.com/NixOS/nixpkgs " .. branch .. " 2>/dev/null | cut -c 1-7" local remoteHashCmd = "git ls-remote https://github.com/NixOS/nixpkgs " .. branch .. " 2>/dev/null | cut -c 1-7"
local nixosGenerationsCmd = "nixos-rebuild list-generations | tail -n +2 | wc -l" 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())
@@ -82,12 +82,12 @@ noctalia.writeFile(remoteHashFile, "")
-- Local check -- Local check
function checkLocalHash() function checkLocalHash()
setState("lastLocalCheckTime", os.time()) setState("lastLocalCheckTime", os.time())
noctalia.runAsync(localHashCmd, function(res) noctalia.runAsync(localHashCmd, function(res)
if res.exitCode == 0 then if res.exitCode == 0 then
setState("localHash", noctalia.string.trim(res.stdout)) setState("localHash", noctalia.string.trim(res.stdout))
end end
end) end)
end end
-- Remote check -- Remote check
@@ -95,116 +95,118 @@ end
-- Currently it is writing to a file because when I use the runAsync with -- Currently it is writing to a file because when I use the runAsync with
-- the callback, it is timed out -- the callback, it is timed out
function checkRemoteHash(delay: number?) function checkRemoteHash(delay: number?)
local delay = delay or 0 local delay = delay or 0
if getState("isRemoteCheckRunning") then if getState("isRemoteCheckRunning") then
return return
end end
setState("isRemoteCheckRunning", true) setState("isRemoteCheckRunning", true)
setState("lastRemoteCheckRunTime", os.time()) setState("lastRemoteCheckRunTime", os.time())
if cfg("show_update_check_notification") then if cfg("show_update_check_notification") then
noctalia.notify(tr("notification.checking_update")) noctalia.notify(tr("notification.checking_update"))
end end
noctalia.writeFile(remoteHashFile, "") noctalia.writeFile(remoteHashFile, "")
noctalia.runAsync(`sleep {delay} && {remoteHashCmd} > {remoteHashFile} & echo $! > {remotePidFile}`) noctalia.runAsync(`sleep {delay} && {remoteHashCmd} > {remoteHashFile} & echo $! > {remotePidFile}`)
end end
-- Check if the remoteHash check command is finished by reading the file -- Check if the remoteHash check command is finished by reading the file
function checkRemoteStatus() function checkRemoteStatus()
local remoteHash = noctalia.string.trim(noctalia.readFile(remoteHashFile)) local remoteHash = noctalia.string.trim(noctalia.readFile(remoteHashFile))
if type(remoteHash) == "string" and remoteHash ~= "" then if type(remoteHash) == "string" and remoteHash ~= "" then
setState("isRemoteCheckRunning", false) setState("isRemoteCheckRunning", false)
setState("remoteHash", remoteHash) setState("remoteHash", remoteHash)
onRemoteHashCheckCompleted() onRemoteHashCheckCompleted()
end end
end end
function onRemoteHashCheckCompleted() function onRemoteHashCheckCompleted()
if cfg("show_update_check_notification") then if cfg("show_update_check_notification") then
noctalia.notify(tr("notification.update_check_completed")) noctalia.notify(tr("notification.update_check_completed"))
end end
setState("lastRemoteCheckTime", os.time()) setState("lastRemoteCheckTime", os.time())
local date = noctalia.formatTime("%Y-%m-%d %H:%M:%S") local date = noctalia.formatTime("%Y-%m-%d %H:%M:%S")
setState("lastRemoteCheckTimeStr", date) setState("lastRemoteCheckTimeStr", date)
noctalia.removeFile(remotePidFile) noctalia.removeFile(remotePidFile)
end end
function cancelRemoteCheck() function cancelRemoteCheck()
setState("isRemoteCheckRunning", false) setState("isRemoteCheckRunning", false)
killWithPidFile(remotePidFile) killWithPidFile(remotePidFile)
end end
-- Generation check -- Generation check
function checkGenerations() function checkGenerations()
setState("lastGenerationsCheckTime", os.time()) setState("lastGenerationsCheckTime", os.time())
noctalia.runAsync(nixosGenerationsCmd, function(result) noctalia.runAsync(nixosGenerationsCmd, function(result)
setState("nixosGenerations", noctalia.string.trim(result.stdout)) setState("nixosGenerations", noctalia.string.trim(result.stdout))
end) end)
noctalia.runAsync(nixosCurrentGenCmd, function(result) noctalia.runAsync(nixosCurrentGenCmd, function(result)
setState("nixosCurrentGen", noctalia.string.trim(result.stdout)) setState("nixosCurrentGen", noctalia.string.trim(result.stdout))
end) end)
if getState("hasHomeManager") then if getState("hasHomeManager") then
noctalia.runAsync(hmGenerationsCmd, function(result) noctalia.runAsync(hmGenerationsCmd, function(result)
setState("hmGenerations", noctalia.string.trim(result.stdout)) setState("hmGenerations", noctalia.string.trim(result.stdout))
end) end)
noctalia.runAsync(hmCurrentGenCmd, function(result) noctalia.runAsync(hmCurrentGenCmd, function(result)
setState("hmCurrentGen", noctalia.string.trim(result.stdout)) setState("hmCurrentGen", noctalia.string.trim(result.stdout))
end) end)
end end
end end
-- System stats check -- System stats check
function checkSystemStats() function checkSystemStats()
if getState("isSystemStatsCheckRunning") then if getState("isSystemStatsCheckRunning") then
return return
end end
setState("isSystemStatsCheckRunning", true) setState("isSystemStatsCheckRunning", true)
setState("lastSystemStatsCheckRunTime", os.time()) setState("lastSystemStatsCheckRunTime", os.time())
-- Sleep 0 to trigger noctalia calling /bin/sh -- Sleep 0 to trigger noctalia calling /bin/sh
noctalia.runAsync(`sleep 0 && {storeSizeCmd} > {storeSizeFile} & echo $! > {storePidFile}`) noctalia.runAsync(`sleep 0 && {storeSizeCmd} > {storeSizeFile} & echo $! > {storePidFile}`)
noctalia.runAsync(`sleep 0 && {closureSizeCmd} > {closureSizeFile} & echo $! > {closurePidFile}`) noctalia.runAsync(`sleep 0 && {closureSizeCmd} > {closureSizeFile} & echo $! > {closurePidFile}`)
end end
function checkSystemStatsFile() function checkSystemStatsFile()
local storeSize = noctalia.string.trim(noctalia.readFile(storeSizeFile)) local storeSize = noctalia.string.trim(noctalia.readFile(storeSizeFile))
local closureSize = noctalia.string.trim(noctalia.readFile(closureSizeFile)) local closureSize = noctalia.string.trim(noctalia.readFile(closureSizeFile))
if typeof(storeSize) == "string" and storeSize ~= "" then if typeof(storeSize) == "string" and storeSize ~= "" then
setState("storeSize", storeSize) setState("storeSize", storeSize)
end end
if typeof(closureSize) == "string" and closureSize ~= "" then if typeof(closureSize) == "string" and closureSize ~= "" then
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)
setState("lastSystemStatsCheckTime", os.time()) setState("lastSystemStatsCheckTime", os.time())
noctalia.removeFile(storePidFile) noctalia.removeFile(storePidFile)
noctalia.removeFile(closurePidFile) noctalia.removeFile(closurePidFile)
end end
end end
function cancelSystemCheck() function cancelSystemCheck()
setState("isSystemStatsCheckRunning", false) setState("isSystemStatsCheckRunning", false)
killWithPidFile(storePidFile) killWithPidFile(storePidFile)
killWithPidFile(closurePidFile) killWithPidFile(closurePidFile)
end end
-- Init -- Init
@@ -214,18 +216,18 @@ checkSystemStats()
-- Command watcher -- Command watcher
watchState("command", function(command) watchState("command", function(command)
if command == "check" then if command == "check" then
checkLocalHash() checkLocalHash()
cancelRemoteCheck() cancelRemoteCheck()
checkRemoteHash() checkRemoteHash()
checkGenerations() checkGenerations()
checkSystemStats() checkSystemStats()
end end
if command == "cancel" then if command == "cancel" then
cancelRemoteCheck() cancelRemoteCheck()
cancelSystemCheck() cancelSystemCheck()
end end
end) end)
-- --
@@ -233,60 +235,62 @@ 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
-- Remote check -- Remote check
if (os.time() - getState("lastRemoteCheckTime")) >= 60 * updateCheckInterval then if (os.time() - getState("lastRemoteCheckTime")) >= 60 * updateCheckInterval then
checkRemoteHash() checkRemoteHash()
end end
if getState("isRemoteCheckRunning") then if getState("isRemoteCheckRunning") then
checkRemoteStatus() checkRemoteStatus()
-- Remote check timeout -- Remote check timeout
if (os.time() - getState("lastRemoteCheckRunTime")) >= 60 * updateCheckDurationThreshold then if (os.time() - getState("lastRemoteCheckRunTime")) >= 60 * updateCheckDurationThreshold then
cancelRemoteCheck() cancelRemoteCheck()
end end
end end
if getState("localHash") ~= getState("remoteHash") and if
getState("localHash") ~= "n/a" and getState("remoteHash") ~= "n/a" getState("localHash") ~= getState("remoteHash")
then and getState("localHash") ~= "n/a"
setState("isUpdateAvailable", true) and getState("remoteHash") ~= "n/a"
then
setState("isUpdateAvailable", true)
if cfg("show_update_available_notification") and showUpdateAvailableNotification then if cfg("show_update_available_notification") and showUpdateAvailableNotification then
noctalia.notify(tr("notification.update_is_available")) noctalia.notify(tr("notification.update_is_available"))
showUpdateAvailableNotification = false showUpdateAvailableNotification = false
end end
else else
setState("isUpdateAvailable", false) setState("isUpdateAvailable", false)
showUpdateAvailableNotification = true showUpdateAvailableNotification = true
end end
-- Generations check -- Generations check
if (os.time() - getState("lastGenerationsCheckTime")) >= 10 then if (os.time() - getState("lastGenerationsCheckTime")) >= 10 then
checkGenerations() checkGenerations()
end end
-- System stats check -- System stats check
if (os.time() - getState("lastSystemStatsCheckTime")) >= 60 * systemStatsCheckInterval then if (os.time() - getState("lastSystemStatsCheckTime")) >= 60 * systemStatsCheckInterval then
checkSystemStats() checkSystemStats()
end end
if getState("isSystemStatsCheckRunning") then if getState("isSystemStatsCheckRunning") then
checkSystemStatsFile() checkSystemStatsFile()
-- System stats check timeout -- System stats check timeout
if (os.time() - getState("lastSystemStatsCheckRunTime")) >= 60 * systemStatsCheckDurationThreshold then if (os.time() - getState("lastSystemStatsCheckRunTime")) >= 60 * systemStatsCheckDurationThreshold then
cancelSystemCheck() cancelSystemCheck()
end end
end end
end end
function onExit(signal) function onExit(signal)
cancelRemoteCheck() cancelRemoteCheck()
cancelSystemCheck() cancelSystemCheck()
end end
+206 -195
View File
@@ -1,210 +1,221 @@
-- Helper functions -- Helper functions
function tr(key) function tr(key)
return noctalia.tr(key) return noctalia.tr(key)
end end
function cfg(key) function cfg(key)
return noctalia.getConfig(key) return noctalia.getConfig(key)
end end
function getState(key) function getState(key)
return noctalia.state.get(key) return noctalia.state.get(key)
end end
function setState(key, val) function setState(key, val)
noctalia.state.set(key, val) noctalia.state.set(key, val)
end end
function watchState(key, cb) function watchState(key, cb)
noctalia.state.watch(key, cb) noctalia.state.watch(key, cb)
end end
local function getBackgroundColor() local function getBackgroundColor()
local color = cfg("panel_card_color") local color = cfg("panel_card_color")
local opacity = cfg("panel_card_opacity") / 100 local opacity = cfg("panel_card_opacity") / 100
return `{color}/{opacity}` return `{color}/{opacity}`
end end
local function labelBox(subtext, text, glyph) local function labelBox(subtext, text, glyph)
return ui.column({ return ui.column({
fill = getBackgroundColor(), fill = getBackgroundColor(),
flexGrow = 1, flexGrow = 1,
height = 100, height = 100,
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
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(
name = glyph, items,
size = 16 ui.glyph({
})) name = glyph,
end size = 16,
})
)
end
table.insert(items, ui.label({ table.insert(
text = text, items,
fontSize = 12, ui.label({
fontWeight = "semibold" text = text,
})) fontSize = 12,
fontWeight = "semibold",
})
)
return ui.row({ return ui.row({
gap = 8, gap = 8,
align = "center" align = "center",
}, items) }, items)
end end
local function render() local function render()
local buttons = {} local buttons = {}
if getState("isRemoteCheckRunning") then if getState("isRemoteCheckRunning") then
table.insert(buttons, ui.button({ table.insert(
text = tr("panel.cancel"), buttons,
glyph = "cancel", ui.button({
flexGrow = 1, text = tr("panel.cancel"),
variant = "destructive", glyph = "cancel",
onClick = "onCancelClicked", flexGrow = 1,
})) variant = "destructive",
else onClick = "onCancelClicked",
if getState("isUpdateAvailable") and not cfg("hide_update_button") then })
table.insert(buttons, ui.button({ )
text = tr("panel.update"), else
glyph = "progress-down", if getState("isUpdateAvailable") and not cfg("hide_update_button") then
flexGrow = 1, table.insert(
variant = "primary", buttons,
onClick = "onUpdateClicked", ui.button({
})) text = tr("panel.update"),
else glyph = "progress-down",
table.insert(buttons, ui.button({ flexGrow = 1,
text = tr("panel.check"), variant = "primary",
glyph = "search", onClick = "onUpdateClicked",
flexGrow = 1, })
variant = "outline", )
onClick = "onCheckClicked", else
})) table.insert(
end buttons,
end ui.button({
text = tr("panel.check"),
glyph = "search",
flexGrow = 1,
variant = "outline",
onClick = "onCheckClicked",
})
)
end
end
if not cfg("hide_clean_button") then if not cfg("hide_clean_button") then
table.insert(buttons, ui.button({ table.insert(
text = tr("panel.clean"), buttons,
glyph = "trash", ui.button({
flexGrow = 1, text = tr("panel.clean"),
variant = "destructive", glyph = "trash",
onClick = "onCleanClicked", flexGrow = 1,
})) variant = "destructive",
end onClick = "onCleanClicked",
})
)
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"), fontSize = 16,
fontSize = 16, }),
}),
ui.label({ ui.label({
text = cfg("branch"), text = cfg("branch"),
fontSize = 12, fontSize = 12,
}), }),
}), }),
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"),
}), }),
ui.separator({ ui.separator({
thickness = 2, thickness = 2,
orientation = "horizontal", orientation = "horizontal",
spacing = 4 spacing = 4,
}), }),
ui.row({ ui.row({
fill = getBackgroundColor(), fill = getBackgroundColor(),
align = "center", align = "center",
justify = "space_between", justify = "space_between",
flexGrow = 1, flexGrow = 1,
paddingV = 4, paddingV = 4,
paddingH = 8, paddingH = 8,
radius = 8, radius = 8,
}, generationItems), }, generationItems),
ui.row({ ui.row({
fill = getBackgroundColor(), fill = getBackgroundColor(),
align = "center", align = "center",
justify = "center", justify = "center",
flexGrow = 1, flexGrow = 1,
paddingV = 4, paddingV = 4,
paddingH = 8, paddingH = 8,
radius = 8, radius = 8,
}, { }, {
statLabel(`{tr("panel.store_size")}: {getState("storeSize")}`, "database"), statLabel(`{tr("panel.store_size")}: {getState("storeSize")}`, "database"),
ui.spacer({width = 16}), ui.spacer({ width = 16 }),
statLabel(`{tr("panel.closure_size")}: {getState("closureSize")}`, "server"), statLabel(`{tr("panel.closure_size")}: {getState("closureSize")}`, "server"),
}), }),
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
@@ -217,48 +228,48 @@ watchState("closureSize", render)
-- Hooks -- Hooks
function onOpen(_ctx) function onOpen(_ctx)
render() render()
end end
function update() function update()
render() render()
end end
-- Click handler -- Click handler
function onCheckClicked() function onCheckClicked()
setState("command", "check") setState("command", "check")
end end
function onCancelClicked() function onCancelClicked()
setState("command", "cancel") setState("command", "cancel")
end end
function onUpdateClicked() function onUpdateClicked()
local command = cfg("update_command") local command = cfg("update_command")
if command == "" then if command == "" then
noctalia.notifyError(tr("notification.update_command_is_empty")) noctalia.notifyError(tr("notification.update_command_is_empty"))
return return
end end
if cfg("close_on_enter") then if cfg("close_on_enter") then
command = `{command} && echo && read -p "{tr("terminal.press_enter_to_exit")}"` command = `{command} && echo && read -p "{tr("terminal.press_enter_to_exit")}"`
end end
panel.close() panel.close()
noctalia.runInTerminal(command) noctalia.runInTerminal(command)
end end
function onCleanClicked() function onCleanClicked()
local command = cfg("clean_command") local command = cfg("clean_command")
if command == "" then if command == "" then
noctalia.notifyError(tr("notification.clean_command_is_empty")) noctalia.notifyError(tr("notification.clean_command_is_empty"))
return return
end end
if cfg("close_on_enter") then if cfg("close_on_enter") then
command = `{command} && echo && read -p "{tr("terminal.press_enter_to_exit")}"` command = `{command} && echo && read -p "{tr("terminal.press_enter_to_exit")}"`
end end
panel.close() panel.close()
noctalia.runInTerminal(command) noctalia.runInTerminal(command)
end end