2014-08-08 14:10:25 +02:00
|
|
|
|
|
|
|
--[[
|
|
|
|
|
|
|
|
Licensed under GNU General Public License v2
|
|
|
|
* (c) 2014, Luke Bonham
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
2017-01-20 20:58:22 +01:00
|
|
|
local helpers = require("lain.helpers")
|
2015-10-20 15:17:44 +02:00
|
|
|
local wibox = require("wibox")
|
2014-08-08 14:10:25 +02:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
2017-01-07 15:12:41 +01:00
|
|
|
-- Basic template for custom widgets (asynchronous version)
|
2014-08-08 14:10:25 +02:00
|
|
|
-- lain.widgets.abase
|
|
|
|
|
|
|
|
local function worker(args)
|
2017-01-24 16:15:40 +01:00
|
|
|
local abase = helpers.make_widget_textbox()
|
|
|
|
local args = args or {}
|
|
|
|
local timeout = args.timeout or 5
|
|
|
|
local nostart = args.nostart or false
|
|
|
|
local stoppable = args.stoppable or false
|
|
|
|
local cmd = args.cmd or ""
|
|
|
|
local settings = args.settings or function() end
|
2014-08-08 14:10:25 +02:00
|
|
|
|
|
|
|
function abase.update()
|
2017-01-20 20:58:22 +01:00
|
|
|
helpers.async(cmd, function(f)
|
2015-08-05 12:28:54 +02:00
|
|
|
output = f
|
2016-03-03 12:40:49 +01:00
|
|
|
if output ~= abase.prev then
|
|
|
|
widget = abase.widget
|
|
|
|
settings()
|
|
|
|
abase.prev = output
|
|
|
|
end
|
2014-08-08 14:10:25 +02:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2017-01-24 16:15:40 +01:00
|
|
|
abase.timer = helpers.newtimer(cmd, timeout, abase.update, nostart, stoppable)
|
2014-08-08 14:10:25 +02:00
|
|
|
|
|
|
|
return setmetatable(abase, { __index = abase.widget })
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|