From acdae44300d237314accd5e724e4ab7d15d69c8e Mon Sep 17 00:00:00 2001 From: avivbintangaringga Date: Wed, 15 Jul 2026 23:38:09 +0700 Subject: [PATCH] fix(nix-monitor): add system check duration threshold --- nix-monitor/nix_monitor_service.luau | 19 ++++++++++++++----- nix-monitor/plugin.toml | 21 +++++++++++++++------ nix-monitor/translations/en.json | 10 ++++++---- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/nix-monitor/nix_monitor_service.luau b/nix-monitor/nix_monitor_service.luau index 08520f4..334249d 100644 --- a/nix-monitor/nix_monitor_service.luau +++ b/nix-monitor/nix_monitor_service.luau @@ -34,9 +34,10 @@ end -- Vars local branch = cfg("branch") -local updateCheckInterval = cfg("check_interval") -local checkDurationThreshold = cfg("check_duration_threshold") +local updateCheckInterval = cfg("update_check_interval") +local updateCheckDurationThreshold = cfg("update_check_duration_threshold") local systemStatsCheckInterval = cfg("system_stats_check_interval") +local systemStatsCheckDurationThreshold = cfg("system_stats_check_duration_threshold") local stateDir = "/tmp/nix-monitor" local remoteHashFile = stateDir .. "/remoteHash" local storeSizeFile = stateDir .. "/storeSize" @@ -66,7 +67,8 @@ setState("isRemoteCheckRunning", false) setState("isUpdateAvailable", false) setState("lastGenerationsCheckTime", 0) setState("isSystemStatsCheckRunning", false) -setState("lastSystemStatsCheckTime", 0) +setState("lastSystemStatsCheckTime", os.time()) +setState("lastSystemStatsCheckRunTime", os.time()) setState("hasHomeManager", noctalia.commandExists("home-manager")) setState("nixosGenerations", "•••") setState("nixosCurrentGen", "•••") @@ -169,7 +171,7 @@ function checkSystemStats() end setState("isSystemStatsCheckRunning", true) - setState("lastSystemStatsCheckTime", os.time()) + setState("lastSystemStatsCheckRunTime", os.time()) -- Sleep 0 to trigger noctalia calling /bin/sh noctalia.runAsync(`sleep 0 && {storeSizeCmd} > {storeSizeFile} & echo $! > {storePidFile}`) @@ -193,6 +195,7 @@ function checkSystemStatsFile() if success then setState("isSystemStatsCheckRunning", false) + setState("lastSystemStatsCheckTime", os.time()) noctalia.removeFile(storePidFile) noctalia.removeFile(closurePidFile) end @@ -207,6 +210,7 @@ end -- Init checkLocalHash() checkRemoteHash(10) +checkSystemStats() -- Command watcher watchState("command", function(command) @@ -243,7 +247,7 @@ function update() checkRemoteStatus() -- Remote check timeout - if (os.time() - getState("lastRemoteCheckRunTime")) >= 60 * checkDurationThreshold then + if (os.time() - getState("lastRemoteCheckRunTime")) >= 60 * updateCheckDurationThreshold then cancelRemoteCheck() end end @@ -274,6 +278,11 @@ function update() if getState("isSystemStatsCheckRunning") then checkSystemStatsFile() + + -- System stats check timeout + if (os.time() - getState("lastSystemStatsCheckRunTime")) >= 60 * systemStatsCheckDurationThreshold then + cancelSystemCheck() + end end end diff --git a/nix-monitor/plugin.toml b/nix-monitor/plugin.toml index 9732578..4d089f1 100644 --- a/nix-monitor/plugin.toml +++ b/nix-monitor/plugin.toml @@ -86,18 +86,18 @@ label_key = "setting.widget.unknown_color.label" default = "on_surface" [[setting]] -key = "check_interval" +key = "update_check_interval" type = "int" -label_key = "setting.check_interval.label" -description_key = "setting.check_interval.description" +label_key = "setting.update_check_interval.label" +description_key = "setting.update_check_interval.description" default = 60 min = 10 [[setting]] -key = "check_duration_threshold" +key = "update_check_duration_threshold" type = "int" -label_key = "setting.check_duration_threshold.label" -description_key = "setting.check_duration_threshold.description" +label_key = "setting.update_check_duration_threshold.label" +description_key = "setting.update_check_duration_threshold.description" default = 5 min = 1 max = 30 @@ -110,6 +110,15 @@ description_key = "setting.system_stats_check_interval.description" default = 10 min = 5 +[[setting]] +key = "system_stats_check_duration_threshold" +type = "int" +label_key = "setting.system_stats_check_duration_threshold.label" +description_key = "setting.system_stats_check_duration_threshold.description" +default = 5 +min = 1 +max = 30 + [[setting]] key = "show_update_check_notification" type = "bool" diff --git a/nix-monitor/translations/en.json b/nix-monitor/translations/en.json index fb8eec8..9e2f6a7 100644 --- a/nix-monitor/translations/en.json +++ b/nix-monitor/translations/en.json @@ -32,12 +32,14 @@ "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.check_interval.label": "Update check interval", - "setting.check_interval.description": "How often to check for updates (in minutes)", - "setting.check_duration_threshold.label": "Update check duration threshold", - "setting.check_duration_threshold.description": "Cancel check if it took too long (in minutes)", + "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", + "setting.update_check_duration_threshold.description": "Cancel update check if it took too long (in minutes)", "setting.system_stats_check_interval.label": "System stats check interval", "setting.system_stats_check_interval.description": "How often to check for system stats (in minutes)", + "setting.system_stats_check_duration_threshold.label": "System stats check duration threshold", + "setting.system_stats_check_duration_threshold.description": "Cancel system stats check if it took too long (in minutes)", "setting.show_update_check_notification.label": "Show update check notification", "setting.show_update_check_notification.description": "Whether to show a notification whenever update check is in progress and completed", "setting.show_update_available_notification.label": "Show update available notification",