helpers.newtimer: added stoppable option
This commit is contained in:
parent
272844030a
commit
a00417d801
12 changed files with 46 additions and 43 deletions
10
helpers.lua
10
helpers.lua
|
@ -92,8 +92,9 @@ end
|
||||||
|
|
||||||
helpers.timer_table = {}
|
helpers.timer_table = {}
|
||||||
|
|
||||||
function helpers.newtimer(_name, timeout, fun, nostart)
|
function helpers.newtimer(name, timeout, fun, nostart, stoppable)
|
||||||
local name = timeout
|
if not name or #name == 0 then return end
|
||||||
|
name = (stoppable and name) or timeout
|
||||||
if not helpers.timer_table[name] then
|
if not helpers.timer_table[name] then
|
||||||
helpers.timer_table[name] = timer({ timeout = timeout })
|
helpers.timer_table[name] = timer({ timeout = timeout })
|
||||||
helpers.timer_table[name]:start()
|
helpers.timer_table[name]:start()
|
||||||
|
@ -102,6 +103,7 @@ function helpers.newtimer(_name, timeout, fun, nostart)
|
||||||
if not nostart then
|
if not nostart then
|
||||||
helpers.timer_table[name]:emit_signal("timeout")
|
helpers.timer_table[name]:emit_signal("timeout")
|
||||||
end
|
end
|
||||||
|
return stoppable and helpers.timer_table[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
@ -175,9 +177,9 @@ function helpers.spairs(t)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create a lain textbox widget
|
-- create a textbox with no spacing issues
|
||||||
function helpers.make_widget_textbox()
|
function helpers.make_widget_textbox()
|
||||||
local w = wibox.widget.textbox('')
|
local w = wibox.widget.textbox()
|
||||||
local t = wibox.widget.base.make_widget(w)
|
local t = wibox.widget.base.make_widget(w)
|
||||||
t.widget = w
|
t.widget = w
|
||||||
return t
|
return t
|
||||||
|
|
|
@ -14,14 +14,14 @@ local setmetatable = setmetatable
|
||||||
-- lain.widgets.abase
|
-- lain.widgets.abase
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local abase = {}
|
local abase = helpers.make_widget_textbox()
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 5
|
local timeout = args.timeout or 5
|
||||||
|
local nostart = args.nostart or false
|
||||||
|
local stoppable = args.stoppable or false
|
||||||
local cmd = args.cmd or ""
|
local cmd = args.cmd or ""
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
abase.widget = wibox.widget.textbox()
|
|
||||||
|
|
||||||
function abase.update()
|
function abase.update()
|
||||||
helpers.async(cmd, function(f)
|
helpers.async(cmd, function(f)
|
||||||
output = f
|
output = f
|
||||||
|
@ -33,7 +33,7 @@ local function worker(args)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer(cmd, timeout, abase.update)
|
abase.timer = helpers.newtimer(cmd, timeout, abase.update, nostart, stoppable)
|
||||||
|
|
||||||
return setmetatable(abase, { __index = abase.widget })
|
return setmetatable(abase, { __index = abase.widget })
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
local read_pipe = require("lain.helpers").read_pipe
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
|
@ -15,16 +14,18 @@ local setmetatable = setmetatable
|
||||||
-- lain.widgets.base
|
-- lain.widgets.base
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local base = {}
|
local base = helpers.make_widget_textbox()
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 5
|
local timeout = args.timeout or 5
|
||||||
|
local nostart = args.nostart or false
|
||||||
|
local stoppable = args.stoppable or false
|
||||||
local cmd = args.cmd or ""
|
local cmd = args.cmd or ""
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
base.widget = wibox.widget.textbox()
|
base.widget = wibox.widget.textbox()
|
||||||
|
|
||||||
function base.update()
|
function base.update()
|
||||||
output = read_pipe(cmd)
|
output = helpers.read_pipe(cmd)
|
||||||
if output ~= base.prev then
|
if output ~= base.prev then
|
||||||
widget = base.widget
|
widget = base.widget
|
||||||
settings()
|
settings()
|
||||||
|
@ -32,7 +33,7 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer(cmd, timeout, base.update)
|
base.timer = helpers.newtimer(cmd, timeout, base.update, nostart, stoppable)
|
||||||
|
|
||||||
return setmetatable(base, { __index = base.widget })
|
return setmetatable(base, { __index = base.widget })
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,23 +67,24 @@ local function worker(args)
|
||||||
if gpm_now.playing then
|
if gpm_now.playing then
|
||||||
if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then
|
if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then
|
||||||
helpers.set_map("gpmdp_current", gpm_now.title)
|
helpers.set_map("gpmdp_current", gpm_now.title)
|
||||||
os.execute(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url))
|
|
||||||
|
|
||||||
if followtag then gpmdp_notification_preset.screen = focused() end
|
if followtag then gpmdp_notification_preset.screen = focused() end
|
||||||
|
|
||||||
|
helpers.async(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url),
|
||||||
|
function(f)
|
||||||
gpmdp.id = naughty.notify({
|
gpmdp.id = naughty.notify({
|
||||||
preset = gpmdp_notification_preset,
|
preset = gpmdp_notification_preset,
|
||||||
icon = "/tmp/gpmcover.png",
|
icon = "/tmp/gpmcover.png",
|
||||||
replaces_id = gpmdp.id,
|
replaces_id = gpmdp.id
|
||||||
}).id
|
}).id
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
elseif not gpm_now.running
|
elseif not gpm_now.running then
|
||||||
then
|
|
||||||
helpers.set_map("gpmdp_current", nil)
|
helpers.set_map("gpmdp_current", nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer("gpmdp", timeout, gpmdp.update)
|
gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true)
|
||||||
|
|
||||||
return setmetatable(gpmdp, { __index = gpmdp.widget })
|
return setmetatable(gpmdp, { __index = gpmdp.widget })
|
||||||
end
|
end
|
||||||
|
|
|
@ -91,7 +91,7 @@ local function worker(args)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer("moc", timeout, moc.update)
|
moc.timer = helpers.newtimer("moc", timeout, moc.update, true, true)
|
||||||
|
|
||||||
return setmetatable(moc, { __index = moc.widget })
|
return setmetatable(moc, { __index = moc.widget })
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,13 +81,11 @@ function smapi:battery(name)
|
||||||
local time_val = bat_now.status == 'discharging' and 'remaining_running_time' or 'remaining_charging_time'
|
local time_val = bat_now.status == 'discharging' and 'remaining_running_time' or 'remaining_charging_time'
|
||||||
local mins_left = self:get(time_val)
|
local mins_left = self:get(time_val)
|
||||||
|
|
||||||
if mins_left:find("^%d+") == nil
|
if not mins_left:find("^%d+") then return "N/A" end
|
||||||
then
|
|
||||||
return "N/A"
|
|
||||||
end
|
|
||||||
|
|
||||||
local hrs = math.floor(mins_left / 60)
|
local hrs = math.floor(mins_left / 60)
|
||||||
local min = mins_left % 60
|
local min = mins_left % 60
|
||||||
|
|
||||||
return string.format("%02d:%02d", hrs, min)
|
return string.format("%02d:%02d", hrs, min)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ local function worker(args )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer(mail, timeout, update)
|
imap.timer = helpers.newtimer(mail, timeout, update, true, true)
|
||||||
|
|
||||||
return setmetatable(imap, { __index = imap.widget })
|
return setmetatable(imap, { __index = imap.widget })
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,7 +30,7 @@ local function worker(args)
|
||||||
|
|
||||||
maildir.widget = wibox.widget.textbox()
|
maildir.widget = wibox.widget.textbox()
|
||||||
|
|
||||||
function update()
|
function maildir.update()
|
||||||
if ext_mail_cmd then awful.spawn(ext_mail_cmd) end
|
if ext_mail_cmd then awful.spawn(ext_mail_cmd) end
|
||||||
|
|
||||||
-- Find pathes to mailboxes.
|
-- Find pathes to mailboxes.
|
||||||
|
@ -76,7 +76,7 @@ local function worker(args)
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer(mailpath, timeout, update, true)
|
maildir.timer = helpers.newtimer(mailpath, timeout, maildir.update, true, true)
|
||||||
|
|
||||||
return setmetatable(maildir, { __index = maildir.widget })
|
return setmetatable(maildir, { __index = maildir.widget })
|
||||||
end
|
end
|
||||||
|
|
|
@ -126,7 +126,7 @@ local function worker(args)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer("mpd", timeout, mpd.update)
|
mpd.timer = helpers.newtimer("mpd", timeout, mpd.update, true, true)
|
||||||
|
|
||||||
return mpd
|
return mpd
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,7 @@ local naughty = require("naughty")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
local string = { format = string.format,
|
local string = { format = string.format,
|
||||||
match = string.match }
|
match = string.match }
|
||||||
|
local tostring = tostring
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Network infos
|
-- Network infos
|
||||||
|
@ -116,7 +117,7 @@ local function worker(args)
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer(net.iface, timeout, update)
|
helpers.newtimer("net-" .. tostring(net.iface), timeout, update)
|
||||||
|
|
||||||
return net
|
return net
|
||||||
end
|
end
|
||||||
|
|
|
@ -160,8 +160,8 @@ local function worker(args)
|
||||||
|
|
||||||
weather.attach(weather.widget)
|
weather.attach(weather.widget)
|
||||||
|
|
||||||
newtimer("weather-" .. city_id, timeout, weather.update)
|
weather.timer = newtimer("weather-" .. city_id, timeout, weather.update, false, true)
|
||||||
newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update)
|
weather.timer_forecast = newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update, false, true)
|
||||||
|
|
||||||
return setmetatable(weather, { __index = weather.widget })
|
return setmetatable(weather, { __index = weather.widget })
|
||||||
end
|
end
|
||||||
|
|
2
wiki
2
wiki
|
@ -1 +1 @@
|
||||||
Subproject commit 991e3bb813a650a6d6bcd27a9563a746fe489716
|
Subproject commit df5dd684ec35c1fc8e044fb5fd0bdb76f7f568fa
|
Loading…
Add table
Reference in a new issue