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