diff --git a/Changes.md b/Changes.md index 590447f..765058c 100644 --- a/Changes.md +++ b/Changes.md @@ -19,7 +19,7 @@ Fixed: - Deprecate the use of `io.popen` in following widgets: * wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux - * bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd + * bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd * volume, gmail, mdir, mpd, fs - [mpd] Lua 5.3 compatibility (for real this time); also correct a typo - [pkg,weather,contrib/btc] Allow function call without Awesome diff --git a/helpers.lua b/helpers.lua index ed11043..3ce5323 100644 --- a/helpers.lua +++ b/helpers.lua @@ -21,7 +21,9 @@ local string = { lower = string.lower, format = string.format, match = string.match, + find = string.find, } +local table = { concat = table.concat } local pcall = pcall local assert = assert local spawn = require("vicious.spawn") @@ -263,14 +265,22 @@ end -- }}} -- {{{ Return result from sysctl variable as table (async) -function helpers.sysctl_async(path, parse) +function helpers.sysctl_async(path_table, parse) local ret = {} - local path = table.concat(path, " ") + local path = {} - spawn.with_line_callback("sysctl " .. helpers.shellquote(path), { + for i=1,#path_table do + path[i] = helpers.shellquote(path_table[i]) + end + + path = table.concat(path, " ") + + spawn.with_line_callback("sysctl " .. path, { stdout = function(line) - local key, value = string.match(line, "(.+): (.+)") - ret[key] = value + if not string.find(line, "sysctl: unknown oid") then + local key, value = string.match(line, "(.+): (.+)") + ret[key] = value + end end, output_done = function() parse(ret) end }) diff --git a/widgets/thermal_freebsd.lua b/widgets/thermal_freebsd.lua index 5a7dbe7..623df69 100644 --- a/widgets/thermal_freebsd.lua +++ b/widgets/thermal_freebsd.lua @@ -13,10 +13,18 @@ function thermal_freebsd.async(format, warg, callback) if not warg then return callback{} end if type(warg) ~= "table" then warg = { warg } end - local thermals = {} - helpers.sysctl_async(warg, function(ret) - for i=1, #warg do + local thermals = {} + + for k, v in pairs(ret) do + print(k, v) + end + + for i=1,#warg do + print(warg[i]) + print(ret[warg[i]]) + print(ret["hw.acpi.thermal.tz0.temperature"]) + print(ret['hw.acpi.thermal.tz0.temperature']) if ret[warg[i]] ~= nil then thermals[i] = string.match(ret[warg[i]], "[%d]+") else diff --git a/widgets/uptime_freebsd.lua b/widgets/uptime_freebsd.lua index 9e075e5..09ee75e 100644 --- a/widgets/uptime_freebsd.lua +++ b/widgets/uptime_freebsd.lua @@ -14,17 +14,21 @@ local uptime_freebsd = {} -- {{{ Uptime widget type -local function worker(format) - local l1, l5, l15 = string.match(helpers.sysctl("vm.loadavg"), "{ ([%d]+%.[%d]+) ([%d]+%.[%d]+) ([%d]+%.[%d]+) }") - local up_t = os.time() - tonumber(string.match(helpers.sysctl("kern.boottime"), "sec = ([%d]+)")) +function uptime_freebsd.async(format, warg, callback) + helpers.sysctl_async({ "vm.loadavg", + "kern.boottime" }, + function(ret) + local l1, l5, l15 = string.match(ret["vm.loadavg"], "{ ([%d]+%.[%d]+) ([%d]+%.[%d]+) ([%d]+%.[%d]+) }") + local up_t = os.time() - tonumber(string.match(ret["kern.boottime"], "sec = ([%d]+)")) - -- Get system uptime - local up_d = math.floor(up_t / (3600 * 24)) - local up_h = math.floor((up_t % (3600 * 24)) / 3600) - local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60) + -- Get system uptime + local up_d = math.floor(up_t / (3600 * 24)) + local up_h = math.floor((up_t % (3600 * 24)) / 3600) + local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60) - return {up_d, up_h, up_m, l1, l5, l15} + return callback({ up_d, up_h, up_m, l1, l5, l15 }) + end) end -- }}} -return setmetatable(uptime_freebsd, { __call = function(_, ...) return worker(...) end }) +return helpers.setasyncall(uptime_freebsd)