mpd and yawn widget are now asynchronous
This commit is contained in:
parent
c14436760d
commit
e00ee3436e
3 changed files with 133 additions and 128 deletions
|
@ -13,6 +13,8 @@
|
||||||
-- ...synchronously
|
-- ...synchronously
|
||||||
-- wwidget.text = asyncshell.demand('wscript -Kiev', 5):read("*l") or "Error"
|
-- 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
|
local spawn = require('awful.util').spawn
|
||||||
|
|
||||||
asyncshell = {}
|
asyncshell = {}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local helpers = require("lain.helpers")
|
local helpers = require("lain.helpers")
|
||||||
|
local async = require("lain.asyncshell")
|
||||||
|
|
||||||
local escape_f = require("awful.util").escape
|
local escape_f = require("awful.util").escape
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
|
@ -50,6 +51,7 @@ local function worker(args)
|
||||||
helpers.set_map("current mpd track", nil)
|
helpers.set_map("current mpd track", nil)
|
||||||
|
|
||||||
function mpd.update()
|
function mpd.update()
|
||||||
|
async.request(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh, function (f)
|
||||||
mpd_now = {
|
mpd_now = {
|
||||||
state = "N/A",
|
state = "N/A",
|
||||||
file = "N/A",
|
file = "N/A",
|
||||||
|
@ -59,8 +61,6 @@ local function worker(args)
|
||||||
date = "N/A"
|
date = "N/A"
|
||||||
}
|
}
|
||||||
|
|
||||||
local f = io.popen(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh)
|
|
||||||
|
|
||||||
for line in f:lines() do
|
for line in f:lines() do
|
||||||
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
||||||
if k == "state" then mpd_now.state = v
|
if k == "state" then mpd_now.state = v
|
||||||
|
@ -73,8 +73,6 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
f:close()
|
|
||||||
|
|
||||||
mpd_notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
|
mpd_notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
|
||||||
mpd_now.album, mpd_now.date, mpd_now.title)
|
mpd_now.album, mpd_now.date, mpd_now.title)
|
||||||
widget = mpd.widget
|
widget = mpd.widget
|
||||||
|
@ -100,6 +98,7 @@ local function worker(args)
|
||||||
then
|
then
|
||||||
helpers.set_map("current mpd track", nil)
|
helpers.set_map("current mpd track", nil)
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer("mpd", timeout, mpd.update)
|
helpers.newtimer("mpd", timeout, mpd.update)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local newtimer = require("lain.helpers").newtimer
|
||||||
|
local async = require("lain.asyncshell")
|
||||||
|
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
@ -47,7 +48,9 @@ yawn_notification_preset = {}
|
||||||
|
|
||||||
local function fetch_weather()
|
local function fetch_weather()
|
||||||
local url = api_url .. units_set .. city_id
|
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")
|
local text = f:read("*a")
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
|
@ -140,6 +143,7 @@ local function fetch_weather()
|
||||||
units = units:gsub(" ", "")
|
units = units:gsub(" ", "")
|
||||||
|
|
||||||
settings()
|
settings()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function yawn.hide()
|
function yawn.hide()
|
||||||
|
|
Loading…
Add table
Reference in a new issue