mpd and yawn widget are now asynchronous
This commit is contained in:
parent
823659d83d
commit
6714db710a
3 changed files with 133 additions and 128 deletions
|
@ -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 = {}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue