Merge pull request #25 from avivbintangaringga/main

feat(nix-monitor): update version 1.1.0
This commit is contained in:
Lysec
2026-07-16 13:04:26 +02:00
committed by GitHub
5 changed files with 456 additions and 395 deletions
+3 -6
View File
@@ -11,16 +11,14 @@ function getState(key)
end end
function displayWidget(glyph: string, text: string, color: string?) function displayWidget(glyph: string, text: string, color: string?)
if color == nil then local _color = color or "on_surface"
color = "on_surface"
end
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
@@ -47,7 +45,6 @@ function update()
end end
end end
end end
end end
function onClick() function onClick()
+17 -13
View File
@@ -1,4 +1,4 @@
noctalia.setUpdateInterval(5000) noctalia.setUpdateInterval(1000)
-- Helper functions -- Helper functions
function tr(key) function tr(key)
@@ -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())
@@ -146,20 +146,20 @@ function checkGenerations()
setState("lastGenerationsCheckTime", os.time()) setState("lastGenerationsCheckTime", os.time())
noctalia.runAsync(nixosGenerationsCmd, function(result) noctalia.runAsync(nixosGenerationsCmd, function(result)
setState("nixosGenerations", result.stdout) setState("nixosGenerations", noctalia.string.trim(result.stdout))
end) end)
noctalia.runAsync(nixosCurrentGenCmd, function(result) noctalia.runAsync(nixosCurrentGenCmd, function(result)
setState("nixosCurrentGen", 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", result.stdout) setState("hmGenerations", noctalia.string.trim(result.stdout))
end) end)
noctalia.runAsync(hmCurrentGenCmd, function(result) noctalia.runAsync(hmCurrentGenCmd, function(result)
setState("hmCurrentGen", result.stdout) setState("hmCurrentGen", noctalia.string.trim(result.stdout))
end) end)
end end
end end
@@ -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)
@@ -267,7 +271,7 @@ function update()
end end
-- Generations check -- Generations check
if (os.time() - getState("lastGenerationsCheckTime")) >= 20 then if (os.time() - getState("lastGenerationsCheckTime")) >= 10 then
checkGenerations() checkGenerations()
end end
+74 -52
View File
@@ -20,28 +20,34 @@ function watchState(key, cb)
noctalia.state.watch(key, cb) noctalia.state.watch(key, cb)
end end
local function getBackgroundColor()
local color = cfg("panel_card_color")
local opacity = cfg("panel_card_opacity") / 100
return `{color}/{opacity}`
end
local function labelBox(subtext, text, glyph) local function labelBox(subtext, text, glyph)
return ui.column({ return ui.column({
fill = "surface/0.7", 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
@@ -49,98 +55,121 @@ 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 = 20 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
local function render() local function render()
local firstBtn local buttons = {}
if getState("isRemoteCheckRunning") then if getState("isRemoteCheckRunning") then
firstBtn = 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") then if getState("isUpdateAvailable") and not cfg("hide_update_button") then
firstBtn = 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
firstBtn = 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
table.insert(
buttons,
ui.button({
text = tr("panel.clean"),
glyph = "trash",
flexGrow = 1,
variant = "destructive",
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") then if getState("hasHomeManager") and getState("hmGenerations") ~= "" and getState("hmCurrentGen") ~= "" then
table.insert(generationItems, table.insert(generationItems, statLabel(`HM: {getState("hmGenerations")}`, "home"))
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 = 20, fontSize = 16,
}), }),
ui.label({ ui.label({
text = cfg("branch"), text = cfg("branch"),
fontSize = 14, 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"),
@@ -148,10 +177,10 @@ local function render()
ui.separator({ ui.separator({
thickness = 2, thickness = 2,
orientation = "horizontal", orientation = "horizontal",
spacing = 4 spacing = 4,
}), }),
ui.row({ ui.row({
fill = "surface/0.7", fill = getBackgroundColor(),
align = "center", align = "center",
justify = "space_between", justify = "space_between",
flexGrow = 1, flexGrow = 1,
@@ -160,7 +189,7 @@ local function render()
radius = 8, radius = 8,
}, generationItems), }, generationItems),
ui.row({ ui.row({
fill = "surface/0.7", fill = getBackgroundColor(),
align = "center", align = "center",
justify = "center", justify = "center",
flexGrow = 1, flexGrow = 1,
@@ -175,27 +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,
}), }),
ui.row({ ui.row({
gap = 8, gap = 8,
align = "center", align = "center",
justify = "space_between" justify = "space_between",
}, { }, buttons),
firstBtn, }))
ui.button({
text = tr("panel.clean"),
glyph = "trash",
flexGrow = 1,
variant = "destructive",
onClick = "onCleanClicked",
}),
})
})
)
end end
-- State watcher -- State watcher
@@ -203,6 +223,8 @@ watchState("isRemoteCheckRunning", render)
watchState("lastRemoteCheckTimeStr", render) watchState("lastRemoteCheckTimeStr", render)
watchState("localHash", render) watchState("localHash", render)
watchState("remoteHash", render) watchState("remoteHash", render)
watchState("storeSize", render)
watchState("closureSize", render)
-- Hooks -- Hooks
function onOpen(_ctx) function onOpen(_ctx)
@@ -223,7 +245,7 @@ function onCancelClicked()
end end
function onUpdateClicked() function onUpdateClicked()
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
@@ -238,7 +260,7 @@ function onUpdateClicked()
end end
function onCleanClicked() function onCleanClicked()
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
+57 -27
View File
@@ -1,6 +1,6 @@
id = "avivbintangaringga/nix-monitor" id = "avivbintangaringga/nix-monitor"
name = "Nix Monitor" name = "Nix Monitor"
version = "1.0.0" version = "1.1.0"
min_noctalia = "5.0.0" min_noctalia = "5.0.0"
icon = "package" icon = "package"
author = "avivbintangaringga" author = "avivbintangaringga"
@@ -85,6 +85,32 @@ type = "color"
label_key = "setting.widget.unknown_color.label" label_key = "setting.widget.unknown_color.label"
default = "on_surface" default = "on_surface"
[[setting]]
key = "branch"
type = "select"
label_key = "setting.branch.label"
description_key = "setting.branch.description"
options = [
{ value = "master", label_key = "setting.option.branch.master" },
{ value = "nixos-unstable", label_key = "setting.option.branch.nixos_unstable" },
{ value = "nixos-unstable-small", label_key = "setting.option.branch.nixos_unstable_small" },
{ value = "nixos-26.05", label_key = "setting.option.branch.nixos_26_05" },
{ value = "nixos-25.11", label_key = "setting.option.branch.nixos_25_11" },
{ value = "nixos-25.05", label_key = "setting.option.branch.nixos_25_05" },
{ value = "nixos-24.11", label_key = "setting.option.branch.nixos_24_11" },
{ value = "nixos-24.05", label_key = "setting.option.branch.nixos_24_05" },
{ value = "nixos-23.11", label_key = "setting.option.branch.nixos_23_11" },
{ value = "nixos-23.05", label_key = "setting.option.branch.nixos_23_05" },
{ value = "nixos-26.05-small", label_key = "setting.option.branch.nixos_26_05_small" },
{ value = "nixos-25.11-small", label_key = "setting.option.branch.nixos_25_11_small" },
{ value = "nixos-25.05-small", label_key = "setting.option.branch.nixos_25_05_small" },
{ value = "nixos-24.11-small", label_key = "setting.option.branch.nixos_24_11_small" },
{ value = "nixos-24.05-small", label_key = "setting.option.branch.nixos_24_05_small" },
{ value = "nixos-23.11-small", label_key = "setting.option.branch.nixos_23_11_small" },
{ value = "nixos-23.05-small", label_key = "setting.option.branch.nixos_23_05_small" },
]
default = "nixos-unstable"
[[setting]] [[setting]]
key = "update_check_interval" key = "update_check_interval"
type = "int" type = "int"
@@ -119,6 +145,20 @@ default = 5
min = 1 min = 1
max = 30 max = 30
[[setting]]
key = "panel_card_color"
type = "color"
label_key = "setting.widget.panel_card_background_color.label"
default = "surface_variant"
[[setting]]
key = "panel_card_opacity"
type = "int"
label_key = "setting.widget.panel_card_background_opacity.label"
default = 70
min = 0
max = 100
[[setting]] [[setting]]
key = "show_update_check_notification" key = "show_update_check_notification"
type = "bool" type = "bool"
@@ -133,30 +173,6 @@ label_key = "setting.show_update_available_notification.label"
description_key = "setting.show_update_available_notification.description" description_key = "setting.show_update_available_notification.description"
default = true default = true
[[setting]]
key = "branch"
type = "select"
label_key = "setting.branch.label"
description_key = "setting.branch.description"
options = [
{ value = "master", label_key = "setting.option.branch.master" },
{ value = "nixos-unstable", label_key = "setting.option.branch.nixos_unstable" },
{ value = "nixos-unstable-small", label_key = "setting.option.branch.nixos_unstable_small" },
{ value = "nixos-25.11", label_key = "setting.option.branch.nixos_25_11" },
{ value = "nixos-25.05", label_key = "setting.option.branch.nixos_25_05" },
{ value = "nixos-24.11", label_key = "setting.option.branch.nixos_24_11" },
{ value = "nixos-24.05", label_key = "setting.option.branch.nixos_24_05" },
{ value = "nixos-23.11", label_key = "setting.option.branch.nixos_23_11" },
{ value = "nixos-23.05", label_key = "setting.option.branch.nixos_23_05" },
{ value = "nixos-25.11-small", label_key = "setting.option.branch.nixos_25_11_small" },
{ value = "nixos-25.05-small", label_key = "setting.option.branch.nixos_25_05_small" },
{ value = "nixos-24.11-small", label_key = "setting.option.branch.nixos_24_11_small" },
{ value = "nixos-24.05-small", label_key = "setting.option.branch.nixos_24_05_small" },
{ value = "nixos-23.11-small", label_key = "setting.option.branch.nixos_23_11_small" },
{ value = "nixos-23.05-small", label_key = "setting.option.branch.nixos_23_05_small" },
]
default = "nixos-unstable"
[[setting]] [[setting]]
key = "update_command" key = "update_command"
type = "string" type = "string"
@@ -171,6 +187,20 @@ label_key = "setting.clean_command.label"
description_key = "setting.clean_command.description" description_key = "setting.clean_command.description"
default = "nix-collect-garbage -d" default = "nix-collect-garbage -d"
[[setting]]
key = "hide_update_button"
type = "bool"
label_key = "setting.hide_update_button.label"
description_key = "setting.hide_update_button.description"
default = false
[[setting]]
key = "hide_clean_button"
type = "bool"
label_key = "setting.hide_clean_button.label"
description_key = "setting.hide_clean_button.description"
default = false
[[setting]] [[setting]]
key = "close_on_enter" key = "close_on_enter"
type = "bool" type = "bool"
@@ -184,8 +214,8 @@ entry = "panel.luau"
placement = "attached" placement = "attached"
position = "auto" position = "auto"
open_near_click = true open_near_click = true
width = 420 width = 430
height = 370 height = 350
[[service]] [[service]]
id = "service" id = "service"
+8
View File
@@ -32,6 +32,8 @@
"setting.widget.update_available_color.label": "Update available color", "setting.widget.update_available_color.label": "Update available color",
"setting.widget.unknown_glyph.label": "Unknown status glyph", "setting.widget.unknown_glyph.label": "Unknown status glyph",
"setting.widget.unknown_color.label": "Unknown status color", "setting.widget.unknown_color.label": "Unknown status color",
"setting.widget.panel_card_background_color.label": "Panel card background color",
"setting.widget.panel_card_background_opacity.label": "Panel card background opacity",
"setting.update_check_interval.label": "Update check interval", "setting.update_check_interval.label": "Update check interval",
"setting.update_check_interval.description": "How often to check for updates (in minutes)", "setting.update_check_interval.description": "How often to check for updates (in minutes)",
"setting.update_check_duration_threshold.label": "Update check duration threshold", "setting.update_check_duration_threshold.label": "Update check duration threshold",
@@ -50,17 +52,23 @@
"setting.update_command.description": "Command to run when clicking Update button", "setting.update_command.description": "Command to run when clicking Update button",
"setting.clean_command.label": "Clean command", "setting.clean_command.label": "Clean command",
"setting.clean_command.description": "Command to run when clicking Clean button", "setting.clean_command.description": "Command to run when clicking Clean button",
"setting.hide_update_button.label": "Hide update button",
"setting.hide_update_button.description": "Whether to hide the update button on the panel",
"setting.hide_clean_button.label": "Hide clean button",
"setting.hide_clean_button.description": "Whether to hide the clean button on the panel",
"setting.close_on_enter.label": "Close on press Enter", "setting.close_on_enter.label": "Close on press Enter",
"setting.close_on_enter.description": "Add 'Press enter to exit' on the terminal window", "setting.close_on_enter.description": "Add 'Press enter to exit' on the terminal window",
"setting.option.branch.master": "Master", "setting.option.branch.master": "Master",
"setting.option.branch.nixos_unstable": "NixOS Unstable", "setting.option.branch.nixos_unstable": "NixOS Unstable",
"setting.option.branch.nixos_unstable_small": "NixOS Unstable Small", "setting.option.branch.nixos_unstable_small": "NixOS Unstable Small",
"setting.option.branch.nixos_26_05": "NixOS 26.05",
"setting.option.branch.nixos_25_11": "NixOS 25.11", "setting.option.branch.nixos_25_11": "NixOS 25.11",
"setting.option.branch.nixos_25_05": "NixOS 25.05", "setting.option.branch.nixos_25_05": "NixOS 25.05",
"setting.option.branch.nixos_24_11": "NixOS 24.11", "setting.option.branch.nixos_24_11": "NixOS 24.11",
"setting.option.branch.nixos_24_05": "NixOS 24.05", "setting.option.branch.nixos_24_05": "NixOS 24.05",
"setting.option.branch.nixos_23_11": "NixOS 23.11", "setting.option.branch.nixos_23_11": "NixOS 23.11",
"setting.option.branch.nixos_23_05": "NixOS 23.05", "setting.option.branch.nixos_23_05": "NixOS 23.05",
"setting.option.branch.nixos_26_05_small": "NixOS 26.05 Small",
"setting.option.branch.nixos_25_11_small": "NixOS 25.11 Small", "setting.option.branch.nixos_25_11_small": "NixOS 25.11 Small",
"setting.option.branch.nixos_25_05_small": "NixOS 25.05 Small", "setting.option.branch.nixos_25_05_small": "NixOS 25.05 Small",
"setting.option.branch.nixos_24_11_small": "NixOS 24.11 Small", "setting.option.branch.nixos_24_11_small": "NixOS 24.11 Small",