Merge pull request #25 from avivbintangaringga/main
feat(nix-monitor): update version 1.1.0
This commit is contained in:
@@ -1,55 +1,52 @@
|
||||
function tr(key)
|
||||
return noctalia.tr(key)
|
||||
return noctalia.tr(key)
|
||||
end
|
||||
|
||||
function cfg(key)
|
||||
return noctalia.getConfig(key)
|
||||
return noctalia.getConfig(key)
|
||||
end
|
||||
|
||||
function getState(key)
|
||||
return noctalia.state.get(key)
|
||||
return noctalia.state.get(key)
|
||||
end
|
||||
|
||||
function displayWidget(glyph: string, text: string, color: string?)
|
||||
if color == nil then
|
||||
color = "on_surface"
|
||||
end
|
||||
local _color = color or "on_surface"
|
||||
|
||||
if cfg("colorize_text") then
|
||||
barWidget.setColor(color)
|
||||
end
|
||||
if cfg("colorize_text") then
|
||||
barWidget.setColor(_color)
|
||||
end
|
||||
|
||||
if cfg("colorize_glyph") then
|
||||
barWidget.setGlyphColor(color)
|
||||
end
|
||||
if cfg("colorize_glyph") then
|
||||
barWidget.setGlyphColor(_color)
|
||||
end
|
||||
|
||||
if cfg("show_glyph") then
|
||||
barWidget.setGlyph(glyph)
|
||||
end
|
||||
if cfg("show_glyph") then
|
||||
barWidget.setGlyph(glyph)
|
||||
end
|
||||
|
||||
if cfg("show_text") then
|
||||
barWidget.setText(text)
|
||||
end
|
||||
if cfg("show_text") then
|
||||
barWidget.setText(text)
|
||||
end
|
||||
end
|
||||
|
||||
-- Hooks
|
||||
function update()
|
||||
if getState("isRemoteCheckRunning") then
|
||||
displayWidget(cfg("checking_glyph"), tr("bar.checking"), cfg("checking_color"))
|
||||
else
|
||||
if getState("isUpdateAvailable") then
|
||||
displayWidget(cfg("update_available_glyph"), tr("bar.update_available"), cfg("update_available_color"))
|
||||
else
|
||||
if getState("localHash") == "n/a" or getState("remoteHash") == "n/a" then
|
||||
displayWidget(cfg("unknown_glyph"), tr("bar.unknown"), cfg("unknown_color"))
|
||||
else
|
||||
displayWidget(cfg("up_to_date_glyph"), tr("bar.up_to_date"), cfg("up_to_date_color"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if getState("isRemoteCheckRunning") then
|
||||
displayWidget(cfg("checking_glyph"), tr("bar.checking"), cfg("checking_color"))
|
||||
else
|
||||
if getState("isUpdateAvailable") then
|
||||
displayWidget(cfg("update_available_glyph"), tr("bar.update_available"), cfg("update_available_color"))
|
||||
else
|
||||
if getState("localHash") == "n/a" or getState("remoteHash") == "n/a" then
|
||||
displayWidget(cfg("unknown_glyph"), tr("bar.unknown"), cfg("unknown_color"))
|
||||
else
|
||||
displayWidget(cfg("up_to_date_glyph"), tr("bar.up_to_date"), cfg("up_to_date_color"))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function onClick()
|
||||
noctalia.togglePanel("avivbintangaringga/nix-monitor:panel")
|
||||
noctalia.togglePanel("avivbintangaringga/nix-monitor:panel")
|
||||
end
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
noctalia.setUpdateInterval(5000)
|
||||
noctalia.setUpdateInterval(1000)
|
||||
|
||||
-- Helper functions
|
||||
function tr(key)
|
||||
return noctalia.tr(key)
|
||||
return noctalia.tr(key)
|
||||
end
|
||||
|
||||
function cfg(key)
|
||||
return noctalia.getConfig(key)
|
||||
return noctalia.getConfig(key)
|
||||
end
|
||||
|
||||
function getState(key)
|
||||
return noctalia.state.get(key)
|
||||
return noctalia.state.get(key)
|
||||
end
|
||||
|
||||
function setState(key, val)
|
||||
noctalia.state.set(key, val)
|
||||
noctalia.state.set(key, val)
|
||||
end
|
||||
|
||||
function watchState(key, cb)
|
||||
noctalia.state.watch(key, cb)
|
||||
noctalia.state.watch(key, cb)
|
||||
end
|
||||
|
||||
function killWithPidFile(file)
|
||||
if noctalia.fileExists(file) then
|
||||
local pid = noctalia.string.trim(noctalia.readFile(file))
|
||||
if noctalia.fileExists(file) then
|
||||
local pid = noctalia.string.trim(noctalia.readFile(file))
|
||||
|
||||
if type(pid) == "string" and pid ~= "" then
|
||||
noctalia.runAsync(`pkill -9 -P {pid} && kill -9 {pid}`)
|
||||
end
|
||||
noctalia.removeFile(file)
|
||||
end
|
||||
if type(pid) == "string" and pid ~= "" then
|
||||
noctalia.runAsync(`pkill -9 -P {pid} && kill -9 {pid}`)
|
||||
end
|
||||
noctalia.removeFile(file)
|
||||
end
|
||||
end
|
||||
|
||||
-- Vars
|
||||
@@ -47,14 +47,14 @@ local storePidFile = stateDir .. "/storeSize.pid"
|
||||
local closurePidFile = stateDir .. "/closureSize.pid"
|
||||
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 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())
|
||||
@@ -82,12 +82,12 @@ noctalia.writeFile(remoteHashFile, "")
|
||||
|
||||
-- Local check
|
||||
function checkLocalHash()
|
||||
setState("lastLocalCheckTime", os.time())
|
||||
noctalia.runAsync(localHashCmd, function(res)
|
||||
if res.exitCode == 0 then
|
||||
setState("localHash", noctalia.string.trim(res.stdout))
|
||||
end
|
||||
end)
|
||||
setState("lastLocalCheckTime", os.time())
|
||||
noctalia.runAsync(localHashCmd, function(res)
|
||||
if res.exitCode == 0 then
|
||||
setState("localHash", noctalia.string.trim(res.stdout))
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Remote check
|
||||
@@ -95,116 +95,118 @@ end
|
||||
-- Currently it is writing to a file because when I use the runAsync with
|
||||
-- the callback, it is timed out
|
||||
function checkRemoteHash(delay: number?)
|
||||
local delay = delay or 0
|
||||
local delay = delay or 0
|
||||
|
||||
if getState("isRemoteCheckRunning") then
|
||||
return
|
||||
end
|
||||
if getState("isRemoteCheckRunning") then
|
||||
return
|
||||
end
|
||||
|
||||
setState("isRemoteCheckRunning", true)
|
||||
setState("lastRemoteCheckRunTime", os.time())
|
||||
setState("isRemoteCheckRunning", true)
|
||||
setState("lastRemoteCheckRunTime", os.time())
|
||||
|
||||
if cfg("show_update_check_notification") then
|
||||
noctalia.notify(tr("notification.checking_update"))
|
||||
end
|
||||
if cfg("show_update_check_notification") then
|
||||
noctalia.notify(tr("notification.checking_update"))
|
||||
end
|
||||
|
||||
noctalia.writeFile(remoteHashFile, "")
|
||||
noctalia.runAsync(`sleep {delay} && {remoteHashCmd} > {remoteHashFile} & echo $! > {remotePidFile}`)
|
||||
noctalia.writeFile(remoteHashFile, "")
|
||||
noctalia.runAsync(`sleep {delay} && {remoteHashCmd} > {remoteHashFile} & echo $! > {remotePidFile}`)
|
||||
end
|
||||
|
||||
-- Check if the remoteHash check command is finished by reading the file
|
||||
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
|
||||
setState("isRemoteCheckRunning", false)
|
||||
setState("remoteHash", remoteHash)
|
||||
onRemoteHashCheckCompleted()
|
||||
end
|
||||
if type(remoteHash) == "string" and remoteHash ~= "" then
|
||||
setState("isRemoteCheckRunning", false)
|
||||
setState("remoteHash", remoteHash)
|
||||
onRemoteHashCheckCompleted()
|
||||
end
|
||||
end
|
||||
|
||||
function onRemoteHashCheckCompleted()
|
||||
if cfg("show_update_check_notification") then
|
||||
noctalia.notify(tr("notification.update_check_completed"))
|
||||
end
|
||||
if cfg("show_update_check_notification") then
|
||||
noctalia.notify(tr("notification.update_check_completed"))
|
||||
end
|
||||
|
||||
setState("lastRemoteCheckTime", os.time())
|
||||
setState("lastRemoteCheckTime", os.time())
|
||||
|
||||
local date = noctalia.formatTime("%Y-%m-%d %H:%M:%S")
|
||||
setState("lastRemoteCheckTimeStr", date)
|
||||
local date = noctalia.formatTime("%Y-%m-%d %H:%M:%S")
|
||||
setState("lastRemoteCheckTimeStr", date)
|
||||
|
||||
noctalia.removeFile(remotePidFile)
|
||||
noctalia.removeFile(remotePidFile)
|
||||
end
|
||||
|
||||
function cancelRemoteCheck()
|
||||
setState("isRemoteCheckRunning", false)
|
||||
killWithPidFile(remotePidFile)
|
||||
setState("isRemoteCheckRunning", false)
|
||||
killWithPidFile(remotePidFile)
|
||||
end
|
||||
|
||||
-- Generation check
|
||||
function checkGenerations()
|
||||
setState("lastGenerationsCheckTime", os.time())
|
||||
setState("lastGenerationsCheckTime", os.time())
|
||||
|
||||
noctalia.runAsync(nixosGenerationsCmd, function(result)
|
||||
setState("nixosGenerations", result.stdout)
|
||||
end)
|
||||
noctalia.runAsync(nixosGenerationsCmd, function(result)
|
||||
setState("nixosGenerations", noctalia.string.trim(result.stdout))
|
||||
end)
|
||||
|
||||
noctalia.runAsync(nixosCurrentGenCmd, function(result)
|
||||
setState("nixosCurrentGen", result.stdout)
|
||||
end)
|
||||
noctalia.runAsync(nixosCurrentGenCmd, function(result)
|
||||
setState("nixosCurrentGen", noctalia.string.trim(result.stdout))
|
||||
end)
|
||||
|
||||
if getState("hasHomeManager") then
|
||||
noctalia.runAsync(hmGenerationsCmd, function(result)
|
||||
setState("hmGenerations", result.stdout)
|
||||
end)
|
||||
if getState("hasHomeManager") then
|
||||
noctalia.runAsync(hmGenerationsCmd, function(result)
|
||||
setState("hmGenerations", noctalia.string.trim(result.stdout))
|
||||
end)
|
||||
|
||||
noctalia.runAsync(hmCurrentGenCmd, function(result)
|
||||
setState("hmCurrentGen", result.stdout)
|
||||
end)
|
||||
end
|
||||
noctalia.runAsync(hmCurrentGenCmd, function(result)
|
||||
setState("hmCurrentGen", noctalia.string.trim(result.stdout))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- System stats check
|
||||
function checkSystemStats()
|
||||
if getState("isSystemStatsCheckRunning") then
|
||||
return
|
||||
end
|
||||
if getState("isSystemStatsCheckRunning") then
|
||||
return
|
||||
end
|
||||
|
||||
setState("isSystemStatsCheckRunning", true)
|
||||
setState("lastSystemStatsCheckRunTime", os.time())
|
||||
setState("isSystemStatsCheckRunning", true)
|
||||
setState("lastSystemStatsCheckRunTime", os.time())
|
||||
|
||||
-- Sleep 0 to trigger noctalia calling /bin/sh
|
||||
noctalia.runAsync(`sleep 0 && {storeSizeCmd} > {storeSizeFile} & echo $! > {storePidFile}`)
|
||||
noctalia.runAsync(`sleep 0 && {closureSizeCmd} > {closureSizeFile} & echo $! > {closurePidFile}`)
|
||||
-- Sleep 0 to trigger noctalia calling /bin/sh
|
||||
noctalia.runAsync(`sleep 0 && {storeSizeCmd} > {storeSizeFile} & echo $! > {storePidFile}`)
|
||||
noctalia.runAsync(`sleep 0 && {closureSizeCmd} > {closureSizeFile} & echo $! > {closurePidFile}`)
|
||||
end
|
||||
|
||||
function checkSystemStatsFile()
|
||||
local storeSize = noctalia.string.trim(noctalia.readFile(storeSizeFile))
|
||||
local closureSize = noctalia.string.trim(noctalia.readFile(closureSizeFile))
|
||||
local storeSize = noctalia.string.trim(noctalia.readFile(storeSizeFile))
|
||||
local closureSize = noctalia.string.trim(noctalia.readFile(closureSizeFile))
|
||||
|
||||
if typeof(storeSize) == "string" and storeSize ~= "" then
|
||||
setState("storeSize", storeSize)
|
||||
end
|
||||
if typeof(storeSize) == "string" and storeSize ~= "" then
|
||||
setState("storeSize", storeSize)
|
||||
end
|
||||
|
||||
if typeof(closureSize) == "string" and closureSize ~= "" then
|
||||
setState("closureSize", closureSize)
|
||||
end
|
||||
if typeof(closureSize) == "string" and closureSize ~= "" then
|
||||
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)
|
||||
setState("lastSystemStatsCheckTime", os.time())
|
||||
noctalia.removeFile(storePidFile)
|
||||
noctalia.removeFile(closurePidFile)
|
||||
end
|
||||
if success then
|
||||
setState("isSystemStatsCheckRunning", false)
|
||||
setState("lastSystemStatsCheckTime", os.time())
|
||||
noctalia.removeFile(storePidFile)
|
||||
noctalia.removeFile(closurePidFile)
|
||||
end
|
||||
end
|
||||
|
||||
function cancelSystemCheck()
|
||||
setState("isSystemStatsCheckRunning", false)
|
||||
killWithPidFile(storePidFile)
|
||||
killWithPidFile(closurePidFile)
|
||||
setState("isSystemStatsCheckRunning", false)
|
||||
killWithPidFile(storePidFile)
|
||||
killWithPidFile(closurePidFile)
|
||||
end
|
||||
|
||||
-- Init
|
||||
@@ -214,18 +216,18 @@ checkSystemStats()
|
||||
|
||||
-- Command watcher
|
||||
watchState("command", function(command)
|
||||
if command == "check" then
|
||||
checkLocalHash()
|
||||
cancelRemoteCheck()
|
||||
checkRemoteHash()
|
||||
checkGenerations()
|
||||
checkSystemStats()
|
||||
end
|
||||
if command == "check" then
|
||||
checkLocalHash()
|
||||
cancelRemoteCheck()
|
||||
checkRemoteHash()
|
||||
checkGenerations()
|
||||
checkSystemStats()
|
||||
end
|
||||
|
||||
if command == "cancel" then
|
||||
cancelRemoteCheck()
|
||||
cancelSystemCheck()
|
||||
end
|
||||
if command == "cancel" then
|
||||
cancelRemoteCheck()
|
||||
cancelSystemCheck()
|
||||
end
|
||||
end)
|
||||
|
||||
--
|
||||
@@ -233,60 +235,62 @@ end)
|
||||
--
|
||||
|
||||
function update()
|
||||
-- Check local hash every 10 seconds
|
||||
if (os.time() - getState("lastLocalCheckTime") >= 10) then
|
||||
checkLocalHash()
|
||||
end
|
||||
-- Check local hash every 10 seconds
|
||||
if os.time() - getState("lastLocalCheckTime") >= 10 then
|
||||
checkLocalHash()
|
||||
end
|
||||
|
||||
-- Remote check
|
||||
if (os.time() - getState("lastRemoteCheckTime")) >= 60 * updateCheckInterval then
|
||||
checkRemoteHash()
|
||||
end
|
||||
-- Remote check
|
||||
if (os.time() - getState("lastRemoteCheckTime")) >= 60 * updateCheckInterval then
|
||||
checkRemoteHash()
|
||||
end
|
||||
|
||||
if getState("isRemoteCheckRunning") then
|
||||
checkRemoteStatus()
|
||||
if getState("isRemoteCheckRunning") then
|
||||
checkRemoteStatus()
|
||||
|
||||
-- Remote check timeout
|
||||
if (os.time() - getState("lastRemoteCheckRunTime")) >= 60 * updateCheckDurationThreshold then
|
||||
cancelRemoteCheck()
|
||||
end
|
||||
end
|
||||
-- Remote check timeout
|
||||
if (os.time() - getState("lastRemoteCheckRunTime")) >= 60 * updateCheckDurationThreshold then
|
||||
cancelRemoteCheck()
|
||||
end
|
||||
end
|
||||
|
||||
if getState("localHash") ~= getState("remoteHash") and
|
||||
getState("localHash") ~= "n/a" and getState("remoteHash") ~= "n/a"
|
||||
then
|
||||
setState("isUpdateAvailable", true)
|
||||
if
|
||||
getState("localHash") ~= getState("remoteHash")
|
||||
and getState("localHash") ~= "n/a"
|
||||
and getState("remoteHash") ~= "n/a"
|
||||
then
|
||||
setState("isUpdateAvailable", true)
|
||||
|
||||
if cfg("show_update_available_notification") and showUpdateAvailableNotification then
|
||||
noctalia.notify(tr("notification.update_is_available"))
|
||||
showUpdateAvailableNotification = false
|
||||
end
|
||||
else
|
||||
setState("isUpdateAvailable", false)
|
||||
showUpdateAvailableNotification = true
|
||||
end
|
||||
if cfg("show_update_available_notification") and showUpdateAvailableNotification then
|
||||
noctalia.notify(tr("notification.update_is_available"))
|
||||
showUpdateAvailableNotification = false
|
||||
end
|
||||
else
|
||||
setState("isUpdateAvailable", false)
|
||||
showUpdateAvailableNotification = true
|
||||
end
|
||||
|
||||
-- Generations check
|
||||
if (os.time() - getState("lastGenerationsCheckTime")) >= 20 then
|
||||
checkGenerations()
|
||||
end
|
||||
-- Generations check
|
||||
if (os.time() - getState("lastGenerationsCheckTime")) >= 10 then
|
||||
checkGenerations()
|
||||
end
|
||||
|
||||
-- System stats check
|
||||
if (os.time() - getState("lastSystemStatsCheckTime")) >= 60 * systemStatsCheckInterval then
|
||||
checkSystemStats()
|
||||
end
|
||||
-- System stats check
|
||||
if (os.time() - getState("lastSystemStatsCheckTime")) >= 60 * systemStatsCheckInterval then
|
||||
checkSystemStats()
|
||||
end
|
||||
|
||||
if getState("isSystemStatsCheckRunning") then
|
||||
checkSystemStatsFile()
|
||||
if getState("isSystemStatsCheckRunning") then
|
||||
checkSystemStatsFile()
|
||||
|
||||
-- System stats check timeout
|
||||
if (os.time() - getState("lastSystemStatsCheckRunTime")) >= 60 * systemStatsCheckDurationThreshold then
|
||||
cancelSystemCheck()
|
||||
end
|
||||
end
|
||||
-- System stats check timeout
|
||||
if (os.time() - getState("lastSystemStatsCheckRunTime")) >= 60 * systemStatsCheckDurationThreshold then
|
||||
cancelSystemCheck()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function onExit(signal)
|
||||
cancelRemoteCheck()
|
||||
cancelSystemCheck()
|
||||
cancelRemoteCheck()
|
||||
cancelSystemCheck()
|
||||
end
|
||||
|
||||
+212
-190
@@ -1,201 +1,221 @@
|
||||
-- Helper functions
|
||||
|
||||
function tr(key)
|
||||
return noctalia.tr(key)
|
||||
return noctalia.tr(key)
|
||||
end
|
||||
|
||||
function cfg(key)
|
||||
return noctalia.getConfig(key)
|
||||
return noctalia.getConfig(key)
|
||||
end
|
||||
|
||||
function getState(key)
|
||||
return noctalia.state.get(key)
|
||||
return noctalia.state.get(key)
|
||||
end
|
||||
|
||||
function setState(key, val)
|
||||
noctalia.state.set(key, val)
|
||||
noctalia.state.set(key, val)
|
||||
end
|
||||
|
||||
function watchState(key, cb)
|
||||
noctalia.state.watch(key, cb)
|
||||
noctalia.state.watch(key, cb)
|
||||
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)
|
||||
return ui.column({
|
||||
fill = "surface/0.7",
|
||||
flexGrow = 1,
|
||||
height = 100,
|
||||
radius = 8,
|
||||
align = "center",
|
||||
padding = 12,
|
||||
justify = "space_between"
|
||||
}, {
|
||||
ui.glyph({
|
||||
name = glyph,
|
||||
size = 30
|
||||
}),
|
||||
ui.label({
|
||||
text = text,
|
||||
fontWeight = "bold"
|
||||
}),
|
||||
ui.label({
|
||||
text = subtext,
|
||||
fontSize = 12,
|
||||
fontWeight = "medium"
|
||||
}),
|
||||
})
|
||||
return ui.column({
|
||||
fill = getBackgroundColor(),
|
||||
flexGrow = 1,
|
||||
height = 100,
|
||||
radius = 8,
|
||||
align = "center",
|
||||
padding = 12,
|
||||
justify = "space_between",
|
||||
}, {
|
||||
ui.glyph({
|
||||
name = glyph,
|
||||
size = 30,
|
||||
}),
|
||||
ui.label({
|
||||
text = text,
|
||||
fontWeight = "bold",
|
||||
}),
|
||||
ui.label({
|
||||
text = subtext,
|
||||
fontSize = 12,
|
||||
fontWeight = "medium",
|
||||
}),
|
||||
})
|
||||
end
|
||||
|
||||
local function statLabel(text, glyph: string?)
|
||||
local items = {}
|
||||
if glyph ~= nil then
|
||||
table.insert(items, ui.glyph({
|
||||
name = glyph,
|
||||
size = 20
|
||||
}))
|
||||
end
|
||||
local items = {}
|
||||
if glyph ~= nil then
|
||||
table.insert(
|
||||
items,
|
||||
ui.glyph({
|
||||
name = glyph,
|
||||
size = 16,
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
table.insert(items, ui.label({
|
||||
text = text,
|
||||
fontSize = 12,
|
||||
fontWeight = "semibold"
|
||||
}))
|
||||
table.insert(
|
||||
items,
|
||||
ui.label({
|
||||
text = text,
|
||||
fontSize = 12,
|
||||
fontWeight = "semibold",
|
||||
})
|
||||
)
|
||||
|
||||
return ui.row({
|
||||
gap = 8,
|
||||
align = "center"
|
||||
}, items)
|
||||
return ui.row({
|
||||
gap = 8,
|
||||
align = "center",
|
||||
}, items)
|
||||
end
|
||||
|
||||
local function render()
|
||||
local firstBtn
|
||||
local buttons = {}
|
||||
|
||||
if getState("isRemoteCheckRunning") then
|
||||
firstBtn = ui.button({
|
||||
text = tr("panel.cancel"),
|
||||
glyph = "cancel",
|
||||
flexGrow = 1,
|
||||
variant = "destructive",
|
||||
onClick = "onCancelClicked",
|
||||
})
|
||||
else
|
||||
if getState("isUpdateAvailable") then
|
||||
firstBtn = ui.button({
|
||||
text = tr("panel.update"),
|
||||
glyph = "progress-down",
|
||||
flexGrow = 1,
|
||||
variant = "primary",
|
||||
onClick = "onUpdateClicked",
|
||||
})
|
||||
else
|
||||
firstBtn = ui.button({
|
||||
text = tr("panel.check"),
|
||||
glyph = "search",
|
||||
flexGrow = 1,
|
||||
variant = "outline",
|
||||
onClick = "onCheckClicked",
|
||||
})
|
||||
end
|
||||
end
|
||||
if getState("isRemoteCheckRunning") then
|
||||
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({
|
||||
text = tr("panel.update"),
|
||||
glyph = "progress-down",
|
||||
flexGrow = 1,
|
||||
variant = "primary",
|
||||
onClick = "onUpdateClicked",
|
||||
})
|
||||
)
|
||||
else
|
||||
table.insert(
|
||||
buttons,
|
||||
ui.button({
|
||||
text = tr("panel.check"),
|
||||
glyph = "search",
|
||||
flexGrow = 1,
|
||||
variant = "outline",
|
||||
onClick = "onCheckClicked",
|
||||
})
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
local lastCheckTimeStr = getState("lastRemoteCheckTimeStr")
|
||||
local generationItems = {
|
||||
statLabel(`SYS: {getState("nixosGenerations")}`, "device-desktop"),
|
||||
statLabel(`{tr("panel.current")}: {getState("nixosCurrentGen")}`, "device-desktop-check")
|
||||
}
|
||||
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
|
||||
|
||||
if getState("hasHomeManager") then
|
||||
table.insert(generationItems,
|
||||
statLabel(`HM: {getState("hmGenerations")}`, "home")
|
||||
)
|
||||
local lastCheckTimeStr = getState("lastRemoteCheckTimeStr")
|
||||
local generationItems = {
|
||||
statLabel(`SYS: {getState("nixosGenerations")}`, "device-desktop"),
|
||||
statLabel(`{tr("panel.current")}: {getState("nixosCurrentGen")}`, "device-desktop-check"),
|
||||
}
|
||||
|
||||
table.insert(generationItems,
|
||||
statLabel(`{tr("panel.current")}: {getState("hmCurrentGen")}`, "home-check")
|
||||
)
|
||||
end
|
||||
if getState("hasHomeManager") and getState("hmGenerations") ~= "" and getState("hmCurrentGen") ~= "" then
|
||||
table.insert(generationItems, statLabel(`HM: {getState("hmGenerations")}`, "home"))
|
||||
|
||||
panel.render(
|
||||
ui.column({
|
||||
gap = 8,
|
||||
}, {
|
||||
ui.row({
|
||||
justify = "space_between",
|
||||
align = "center"
|
||||
}, {
|
||||
ui.label({
|
||||
text = tr("panel.title"),
|
||||
fontSize = 20,
|
||||
}),
|
||||
table.insert(generationItems, statLabel(`{tr("panel.current")}: {getState("hmCurrentGen")}`, "home-check"))
|
||||
end
|
||||
|
||||
ui.label({
|
||||
text = cfg("branch"),
|
||||
fontSize = 14,
|
||||
}),
|
||||
}),
|
||||
ui.separator({
|
||||
thickness = 2,
|
||||
orientation = "horizontal",
|
||||
spacing = 4
|
||||
}),
|
||||
ui.row({
|
||||
gap = 8,
|
||||
align = "center",
|
||||
justify = "space_between"
|
||||
}, {
|
||||
labelBox(tr("panel.local"), getState("localHash"), "devices-pc"),
|
||||
labelBox(tr("panel.remote"), getState("remoteHash"), "world"),
|
||||
}),
|
||||
ui.separator({
|
||||
thickness = 2,
|
||||
orientation = "horizontal",
|
||||
spacing = 4
|
||||
}),
|
||||
ui.row({
|
||||
fill = "surface/0.7",
|
||||
align = "center",
|
||||
justify = "space_between",
|
||||
flexGrow = 1,
|
||||
paddingV = 4,
|
||||
paddingH = 8,
|
||||
radius = 8,
|
||||
}, generationItems),
|
||||
ui.row({
|
||||
fill = "surface/0.7",
|
||||
align = "center",
|
||||
justify = "center",
|
||||
flexGrow = 1,
|
||||
paddingV = 4,
|
||||
paddingH = 8,
|
||||
radius = 8,
|
||||
}, {
|
||||
statLabel(`{tr("panel.store_size")}: {getState("storeSize")}`, "database"),
|
||||
ui.spacer({width = 16}),
|
||||
statLabel(`{tr("panel.closure_size")}: {getState("closureSize")}`, "server"),
|
||||
}),
|
||||
ui.separator({
|
||||
thickness = 2,
|
||||
orientation = "horizontal",
|
||||
spacing = 4
|
||||
}),
|
||||
ui.label({
|
||||
text = `{tr("panel.last_checked")}: {lastCheckTimeStr}`
|
||||
}),
|
||||
ui.row({
|
||||
gap = 8,
|
||||
align = "center",
|
||||
justify = "space_between"
|
||||
}, {
|
||||
firstBtn,
|
||||
ui.button({
|
||||
text = tr("panel.clean"),
|
||||
glyph = "trash",
|
||||
flexGrow = 1,
|
||||
variant = "destructive",
|
||||
onClick = "onCleanClicked",
|
||||
}),
|
||||
})
|
||||
})
|
||||
)
|
||||
panel.render(ui.column({
|
||||
gap = 8,
|
||||
}, {
|
||||
ui.row({
|
||||
justify = "space_between",
|
||||
align = "center",
|
||||
}, {
|
||||
ui.label({
|
||||
text = tr("panel.title"),
|
||||
fontSize = 16,
|
||||
}),
|
||||
|
||||
ui.label({
|
||||
text = cfg("branch"),
|
||||
fontSize = 12,
|
||||
}),
|
||||
}),
|
||||
ui.separator({
|
||||
thickness = 2,
|
||||
orientation = "horizontal",
|
||||
spacing = 4,
|
||||
}),
|
||||
ui.row({
|
||||
gap = 8,
|
||||
align = "center",
|
||||
justify = "space_between",
|
||||
}, {
|
||||
labelBox(tr("panel.local"), getState("localHash"), "devices-pc"),
|
||||
labelBox(tr("panel.remote"), getState("remoteHash"), "world"),
|
||||
}),
|
||||
ui.separator({
|
||||
thickness = 2,
|
||||
orientation = "horizontal",
|
||||
spacing = 4,
|
||||
}),
|
||||
ui.row({
|
||||
fill = getBackgroundColor(),
|
||||
align = "center",
|
||||
justify = "space_between",
|
||||
flexGrow = 1,
|
||||
paddingV = 4,
|
||||
paddingH = 8,
|
||||
radius = 8,
|
||||
}, generationItems),
|
||||
ui.row({
|
||||
fill = getBackgroundColor(),
|
||||
align = "center",
|
||||
justify = "center",
|
||||
flexGrow = 1,
|
||||
paddingV = 4,
|
||||
paddingH = 8,
|
||||
radius = 8,
|
||||
}, {
|
||||
statLabel(`{tr("panel.store_size")}: {getState("storeSize")}`, "database"),
|
||||
ui.spacer({ width = 16 }),
|
||||
statLabel(`{tr("panel.closure_size")}: {getState("closureSize")}`, "server"),
|
||||
}),
|
||||
ui.separator({
|
||||
thickness = 2,
|
||||
orientation = "horizontal",
|
||||
spacing = 4,
|
||||
}),
|
||||
ui.label({
|
||||
text = `{tr("panel.last_checked")}: {lastCheckTimeStr}`,
|
||||
fontSize = 12,
|
||||
}),
|
||||
ui.row({
|
||||
gap = 8,
|
||||
align = "center",
|
||||
justify = "space_between",
|
||||
}, buttons),
|
||||
}))
|
||||
end
|
||||
|
||||
-- State watcher
|
||||
@@ -203,51 +223,53 @@ watchState("isRemoteCheckRunning", render)
|
||||
watchState("lastRemoteCheckTimeStr", render)
|
||||
watchState("localHash", render)
|
||||
watchState("remoteHash", render)
|
||||
watchState("storeSize", render)
|
||||
watchState("closureSize", render)
|
||||
|
||||
-- Hooks
|
||||
function onOpen(_ctx)
|
||||
render()
|
||||
render()
|
||||
end
|
||||
|
||||
function update()
|
||||
render()
|
||||
render()
|
||||
end
|
||||
|
||||
-- Click handler
|
||||
function onCheckClicked()
|
||||
setState("command", "check")
|
||||
setState("command", "check")
|
||||
end
|
||||
|
||||
function onCancelClicked()
|
||||
setState("command", "cancel")
|
||||
setState("command", "cancel")
|
||||
end
|
||||
|
||||
function onUpdateClicked()
|
||||
command = cfg("update_command")
|
||||
if command == "" then
|
||||
noctalia.notifyError(tr("notification.update_command_is_empty"))
|
||||
return
|
||||
end
|
||||
local command = cfg("update_command")
|
||||
if command == "" then
|
||||
noctalia.notifyError(tr("notification.update_command_is_empty"))
|
||||
return
|
||||
end
|
||||
|
||||
if cfg("close_on_enter") then
|
||||
command = `{command} && echo && read -p "{tr("terminal.press_enter_to_exit")}"`
|
||||
end
|
||||
if cfg("close_on_enter") then
|
||||
command = `{command} && echo && read -p "{tr("terminal.press_enter_to_exit")}"`
|
||||
end
|
||||
|
||||
panel.close()
|
||||
noctalia.runInTerminal(command)
|
||||
panel.close()
|
||||
noctalia.runInTerminal(command)
|
||||
end
|
||||
|
||||
function onCleanClicked()
|
||||
command = cfg("clean_command")
|
||||
if command == "" then
|
||||
noctalia.notifyError(tr("notification.clean_command_is_empty"))
|
||||
return
|
||||
end
|
||||
local command = cfg("clean_command")
|
||||
if command == "" then
|
||||
noctalia.notifyError(tr("notification.clean_command_is_empty"))
|
||||
return
|
||||
end
|
||||
|
||||
if cfg("close_on_enter") then
|
||||
command = `{command} && echo && read -p "{tr("terminal.press_enter_to_exit")}"`
|
||||
end
|
||||
if cfg("close_on_enter") then
|
||||
command = `{command} && echo && read -p "{tr("terminal.press_enter_to_exit")}"`
|
||||
end
|
||||
|
||||
panel.close()
|
||||
noctalia.runInTerminal(command)
|
||||
panel.close()
|
||||
noctalia.runInTerminal(command)
|
||||
end
|
||||
|
||||
+57
-27
@@ -1,6 +1,6 @@
|
||||
id = "avivbintangaringga/nix-monitor"
|
||||
name = "Nix Monitor"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
min_noctalia = "5.0.0"
|
||||
icon = "package"
|
||||
author = "avivbintangaringga"
|
||||
@@ -85,6 +85,32 @@ type = "color"
|
||||
label_key = "setting.widget.unknown_color.label"
|
||||
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]]
|
||||
key = "update_check_interval"
|
||||
type = "int"
|
||||
@@ -119,6 +145,20 @@ default = 5
|
||||
min = 1
|
||||
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]]
|
||||
key = "show_update_check_notification"
|
||||
type = "bool"
|
||||
@@ -133,30 +173,6 @@ label_key = "setting.show_update_available_notification.label"
|
||||
description_key = "setting.show_update_available_notification.description"
|
||||
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]]
|
||||
key = "update_command"
|
||||
type = "string"
|
||||
@@ -171,6 +187,20 @@ label_key = "setting.clean_command.label"
|
||||
description_key = "setting.clean_command.description"
|
||||
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]]
|
||||
key = "close_on_enter"
|
||||
type = "bool"
|
||||
@@ -184,8 +214,8 @@ entry = "panel.luau"
|
||||
placement = "attached"
|
||||
position = "auto"
|
||||
open_near_click = true
|
||||
width = 420
|
||||
height = 370
|
||||
width = 430
|
||||
height = 350
|
||||
|
||||
[[service]]
|
||||
id = "service"
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
"setting.widget.update_available_color.label": "Update available color",
|
||||
"setting.widget.unknown_glyph.label": "Unknown status glyph",
|
||||
"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.description": "How often to check for updates (in minutes)",
|
||||
"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.clean_command.label": "Clean command",
|
||||
"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.description": "Add 'Press enter to exit' on the terminal window",
|
||||
"setting.option.branch.master": "Master",
|
||||
"setting.option.branch.nixos_unstable": "NixOS Unstable",
|
||||
"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_05": "NixOS 25.05",
|
||||
"setting.option.branch.nixos_24_11": "NixOS 24.11",
|
||||
"setting.option.branch.nixos_24_05": "NixOS 24.05",
|
||||
"setting.option.branch.nixos_23_11": "NixOS 23.11",
|
||||
"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_05_small": "NixOS 25.05 Small",
|
||||
"setting.option.branch.nixos_24_11_small": "NixOS 24.11 Small",
|
||||
|
||||
Reference in New Issue
Block a user