widgets: reuse existing datasets where appropriate
Gmail, mbox, raid, weather and wifi could return the old value in case there isn't new data, no need for N/A to be so common on our wibox.
This commit is contained in:
parent
a9347ec0d0
commit
448275a386
|
@ -21,7 +21,7 @@ local string = {
|
|||
module("vicious.widgets.cpu")
|
||||
|
||||
|
||||
-- Initialise function tables
|
||||
-- Initialize function tables
|
||||
local cpu_usage = {}
|
||||
local cpu_total = {}
|
||||
local cpu_active = {}
|
||||
|
|
|
@ -16,7 +16,7 @@ local helpers = require("vicious.helpers")
|
|||
module("vicious.widgets.dio")
|
||||
|
||||
|
||||
-- Initialise function tables
|
||||
-- Initialize function tables
|
||||
local disk_usage = {}
|
||||
local disk_total = {}
|
||||
-- Variable definitions
|
||||
|
|
|
@ -38,16 +38,15 @@ local rss = {
|
|||
|
||||
-- Default is all unread
|
||||
local feed = rss.unread
|
||||
local mail = {
|
||||
["{count}"] = 0,
|
||||
["{subject}"] = "N/A"
|
||||
}
|
||||
-- }}}
|
||||
|
||||
|
||||
-- {{{ Gmail widget type
|
||||
local function worker(format, warg)
|
||||
local mail = {
|
||||
["{count}"] = 0,
|
||||
["{subject}"] = "N/A"
|
||||
}
|
||||
|
||||
-- Get info from the Gmail atom feed
|
||||
local f = io.popen("curl --connect-timeout 1 -m 3 -fsn " .. feed[1])
|
||||
|
||||
|
|
|
@ -16,13 +16,13 @@ local helpers = require("vicious.helpers")
|
|||
module("vicious.widgets.mbox")
|
||||
|
||||
|
||||
-- Initialize variables
|
||||
local subject = "N/A"
|
||||
|
||||
-- {{{ Mailbox widget type
|
||||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Default value
|
||||
local subject = "N/A"
|
||||
|
||||
-- mbox could be huge, get a 30kb chunk from EOF
|
||||
if type(warg) ~= "table" then mbox = warg end
|
||||
-- * attachment could be much bigger than 30kb
|
||||
|
|
|
@ -18,7 +18,7 @@ module("vicious.widgets.mboxc")
|
|||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Initialise counters
|
||||
-- Initialize counters
|
||||
local count = { old = 0, total = 0, new = 0 }
|
||||
|
||||
-- Get data from mbox files
|
||||
|
|
|
@ -18,7 +18,7 @@ module("vicious.widgets.mdir")
|
|||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Initialise counters
|
||||
-- Initialize counters
|
||||
local count = { new = 0, cur = 0 }
|
||||
|
||||
for i=1, #warg do
|
||||
|
|
|
@ -18,7 +18,7 @@ local helpers = require("vicious.helpers")
|
|||
module("vicious.widgets.net")
|
||||
|
||||
|
||||
-- Initialise function tables
|
||||
-- Initialize function tables
|
||||
local nets = {}
|
||||
-- Variable definitions
|
||||
local unit = { ["b"] = 1, ["kb"] = 1024,
|
||||
|
|
|
@ -28,7 +28,7 @@ local function worker(format, warg)
|
|||
local soon = today + 24 * 3600 * 3 -- 3 days ahead is close
|
||||
local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum
|
||||
|
||||
-- Initialise counters
|
||||
-- Initialize counters
|
||||
local count = { past = 0, today = 0, soon = 0, future = 0 }
|
||||
|
||||
-- Get data from agenda files
|
||||
|
|
|
@ -18,7 +18,7 @@ module("vicious.widgets.pkg")
|
|||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Initialise counters
|
||||
-- Initialize counters
|
||||
local updates = 0
|
||||
local manager = {
|
||||
["Arch"] = { cmd = "pacman -Qu" },
|
||||
|
|
|
@ -19,20 +19,23 @@ local string = {
|
|||
module("vicious.widgets.raid")
|
||||
|
||||
|
||||
-- Initialize function tables
|
||||
local mddev = {}
|
||||
|
||||
-- {{{ RAID widget type
|
||||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
|
||||
local found = false
|
||||
local mddev = {}
|
||||
if not mddev[warg] then
|
||||
mddev[warg] = {
|
||||
["found"] = false,
|
||||
["active"] = 0,
|
||||
["assigned"] = 0
|
||||
}
|
||||
end
|
||||
|
||||
-- Linux manual page: md(4)
|
||||
for line in io.lines("/proc/mdstat") do
|
||||
if found then
|
||||
if mddev[warg]["found"] then
|
||||
local updev = string.match(line, "%[[_U]+%]")
|
||||
|
||||
for i in string.gmatch(updev, "U") do
|
||||
|
@ -41,7 +44,7 @@ local function worker(format, warg)
|
|||
|
||||
break
|
||||
elseif string.sub(line, 1, string.len(warg)) == warg then
|
||||
found = true
|
||||
mddev[warg]["found"] = true
|
||||
|
||||
for i in string.gmatch(line, "%[%d%]") do
|
||||
mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1
|
||||
|
|
|
@ -17,12 +17,8 @@ local helpers = require("vicious.helpers")
|
|||
module("vicious.widgets.weather")
|
||||
|
||||
|
||||
-- {{{ Weather widget type
|
||||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Default values
|
||||
local weather = {
|
||||
-- Initialize function tables
|
||||
local weather = {
|
||||
["{city}"] = "N/A",
|
||||
["{wind}"] = "N/A",
|
||||
["{windmph}"] = "N/A",
|
||||
|
@ -33,7 +29,11 @@ local function worker(format, warg)
|
|||
["{tempc}"] = "N/A",
|
||||
["{humid}"] = "N/A",
|
||||
["{press}"] = "N/A"
|
||||
}
|
||||
}
|
||||
|
||||
-- {{{ Weather widget type
|
||||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Get weather forceast by the station ICAO code, from:
|
||||
-- * US National Oceanic and Atmospheric Administration
|
||||
|
|
|
@ -21,19 +21,19 @@ local string = {
|
|||
module("vicious.widgets.wifi")
|
||||
|
||||
|
||||
-- {{{ Wireless widget type
|
||||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Default values
|
||||
local winfo = {
|
||||
-- Initialize function tables
|
||||
local winfo = {
|
||||
["{ssid}"] = "N/A",
|
||||
["{mode}"] = "N/A",
|
||||
["{chan}"] = 0,
|
||||
["{rate}"] = 0,
|
||||
["{link}"] = 0,
|
||||
["{sign}"] = 0
|
||||
}
|
||||
}
|
||||
|
||||
-- {{{ Wireless widget type
|
||||
local function worker(format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Get data from iwconfig where available
|
||||
local iwconfig = "/sbin/iwconfig"
|
||||
|
|
Loading…
Reference in New Issue