mpd and yawn widget are now asynchronous

This commit is contained in:
luke bonham 2014-08-07 13:37:24 +02:00 committed by copycat-killer
parent c14436760d
commit e00ee3436e
3 changed files with 133 additions and 128 deletions

View file

@ -13,6 +13,8 @@
-- ...synchronously
-- wwidget.text = asyncshell.demand('wscript -Kiev', 5):read("*l") or "Error"
-- This makes things faster, but puts weight on sysload and is more cpu demanding.
local spawn = require('awful.util').spawn
asyncshell = {}

View file

@ -8,6 +8,7 @@
--]]
local helpers = require("lain.helpers")
local async = require("lain.asyncshell")
local escape_f = require("awful.util").escape
local naughty = require("naughty")
@ -50,6 +51,7 @@ local function worker(args)
helpers.set_map("current mpd track", nil)
function mpd.update()
async.request(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh, function (f)
mpd_now = {
state = "N/A",
file = "N/A",
@ -59,8 +61,6 @@ local function worker(args)
date = "N/A"
}
local f = io.popen(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh)
for line in f:lines() do
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
if k == "state" then mpd_now.state = v
@ -73,8 +73,6 @@ local function worker(args)
end
end
f:close()
mpd_notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
mpd_now.album, mpd_now.date, mpd_now.title)
widget = mpd.widget
@ -100,6 +98,7 @@ local function worker(args)
then
helpers.set_map("current mpd track", nil)
end
end)
end
helpers.newtimer("mpd", timeout, mpd.update)

View file

@ -7,6 +7,7 @@
--]]
local newtimer = require("lain.helpers").newtimer
local async = require("lain.asyncshell")
local naughty = require("naughty")
local wibox = require("wibox")
@ -47,7 +48,9 @@ yawn_notification_preset = {}
local function fetch_weather()
local url = api_url .. units_set .. city_id
local f = io.popen("curl --connect-timeout 1 -fsm 3 '" .. url .. "'" )
local cmd = "curl --connect-timeout 1 -fsm 3 '" .. url .. "'"
async.request(cmd, function(f)
local text = f:read("*a")
f:close()
@ -140,6 +143,7 @@ local function fetch_weather()
units = units:gsub(" ", "")
settings()
end)
end
function yawn.hide()