X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/b371de56f8bf19f982a4f6887f2110444b590f74..7de62e4d9fe0d3a7521fc72a66c905d6f343c27b:/widgets/abase.lua?ds=sidebyside diff --git a/widgets/abase.lua b/widgets/abase.lua index 075d615..87af872 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -6,35 +6,39 @@ --]] -local newtimer = require("lain.helpers").newtimer -local async = require("lain.asyncshell") -local wibox = require("wibox") +local helpers = require("lain.helpers") +local async = require("lain.asyncshell") +local wibox = require("wibox") local setmetatable = setmetatable --- Basic template for custom widgets +-- Basic template for custom widgets -- Asynchronous version -- lain.widgets.abase local function worker(args) local abase = {} local args = args or {} - local timeout = args.timeout or 5 + local timeout = args.timeout or 1 local cmd = args.cmd or "" local settings = args.settings or function() end abase.widget = wibox.widget.textbox('') + helpers.set_map(cmd, '') function abase.update() async.request(cmd, function(f) - output = f:read("*a") - f:close() - widget = abase.widget - settings() + output = f + + if helpers.get_map(cmd) ~= output then + widget = abase.widget + settings() + helpers.set_map(cmd, output) + end end) end - newtimer(cmd, timeout, abase.update) + helpers.newtimer(cmd, timeout, abase.update) return setmetatable(abase, { __index = abase.widget }) end