[mpd] Deprecate io.popen
This commit is contained in:
parent
b0b6d46937
commit
db446c35d9
|
@ -20,7 +20,7 @@ Fixed:
|
|||
- Deprecate the use of `io.popen` in following widgets:
|
||||
* wifi_linux, wifiiw_linux
|
||||
* bat_freebsd, mem_freebsd, net_freebsd
|
||||
* volume, gmail, mdir
|
||||
* volume, gmail, mdir, mpd
|
||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local io = { popen = io.popen }
|
||||
local setmetatable = setmetatable
|
||||
local string = { gmatch = string.gmatch }
|
||||
local helpers = require("vicious.helpers")
|
||||
local math = { floor = math.floor }
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
local spawn = require"vicious.spawn"
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -55,7 +54,7 @@ end
|
|||
-- }}}
|
||||
|
||||
-- {{{ MPD widget type
|
||||
local function worker(format, warg)
|
||||
function mpd_all.async(format, warg, callback)
|
||||
-- Fallback values
|
||||
local mpd_state = {
|
||||
["{volume}"] = 0,
|
||||
|
@ -81,9 +80,9 @@ local function worker(format, warg)
|
|||
warg and (warg.port or warg[3]) or "6600")
|
||||
|
||||
-- Get data from MPD server
|
||||
local f = io.popen(query .. "|" .. connect)
|
||||
for line in f:lines() do
|
||||
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
||||
spawn.with_line_callback_with_shell(query .. "|" .. connect, {
|
||||
stdout = function (line)
|
||||
for k, v in line:gmatch"([%w]+):[%s](.*)$" do
|
||||
local key = "{" .. k .. "}"
|
||||
if k == "volume" or k == "bitrate" or
|
||||
k == "elapsed" or k == "duration" then
|
||||
|
@ -98,19 +97,17 @@ local function worker(format, warg)
|
|||
mpd_state[key] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
|
||||
end,
|
||||
output_done = function ()
|
||||
-- Formatted elapsed and duration
|
||||
mpd_state["{Elapsed}"], mpd_state["{Duration}"] = format_progress(
|
||||
mpd_state["{elapsed}"], mpd_state["{duration}"])
|
||||
|
||||
-- Formatted playing progress percentage
|
||||
mpd_state["{Progress}"] = format_progress_percentage(
|
||||
mpd_state["{elapsed}"], mpd_state["{duration}"])
|
||||
|
||||
return mpd_state
|
||||
callback(mpd_state)
|
||||
end })
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return setmetatable(mpd_all, { __call = function(_, ...) return worker(...) end })
|
||||
return helpers.setasyncall(mpd_all)
|
||||
|
|
Loading…
Reference in New Issue